-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from DefangLabs/rocket
Rocket sample
- Loading branch information
Showing
12 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM mcr.microsoft.com/devcontainers/rust:1-bookworm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": ".." | ||
}, | ||
"features": { | ||
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {}, | ||
"ghcr.io/devcontainers/features/docker-in-docker:2": {} | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"karunamurti.tera", | ||
"tamasfe.even-better-toml" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Deploy | ||
uses: DefangLabs/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Rocket | ||
|
||
[1-click deploy](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-rocket-template%26template_owner%3DDefangSamples) | ||
|
||
This sample demonstrates how to deploy a very simple Rocket app. Rocket is a web framework for Rust. | ||
|
||
## Prerequisites | ||
|
||
1. [!NOTE] Download [Defang CLI](https://github.com/DefangLabs/defang) | ||
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticate against your AWS account | ||
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) | ||
|
||
## Development | ||
|
||
To run the application locally, you can use the following command: | ||
|
||
```bash | ||
docker compose up | ||
``` | ||
|
||
## Deployment | ||
|
||
> [!NOTE] | ||
> Download [Defang CLI](https://github.com/DefangLabs/defang) | ||
### Defang Playground | ||
|
||
Deploy your application to the defang playground by opening up your terminal and typing `defang up`. | ||
|
||
### BYOC (AWS) | ||
|
||
If you want to deploy to your own cloud account, you can use Defang BYOC: | ||
|
||
1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`. | ||
2. Run `defang up` in a terminal that has access to your AWS environment variables. | ||
|
||
--- | ||
|
||
Title: Rocket | ||
|
||
Short Description: A simple Rocket app. | ||
|
||
Tags: Rocket | ||
|
||
Languages: Rust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target | ||
.cargo | ||
**/*.sh | ||
**/*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Rust specific | ||
target/ | ||
**/*.rs.bk | ||
|
||
# Dependencies | ||
/Cargo.lock | ||
|
||
# Build artifacts | ||
/target/ | ||
|
||
# Generated by Cargo | ||
**/*.rs.bk | ||
|
||
# Binaries | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Mac specific | ||
.DS_Store | ||
|
||
# IDE specific | ||
.idea/ | ||
.vscode/ | ||
*.swp | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "app" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rocket = "0.5.1" | ||
|
||
[dependencies.rocket_dyn_templates] | ||
version = "0.2.0" | ||
features = ["tera"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM docker.io/rust:1-slim-bookworm AS build | ||
|
||
## cargo package name: customize here or provide via --build-arg | ||
ARG pkg=app | ||
|
||
WORKDIR /build | ||
|
||
COPY . . | ||
|
||
RUN --mount=type=cache,target=/build/target \ | ||
--mount=type=cache,target=/usr/local/cargo/registry \ | ||
--mount=type=cache,target=/usr/local/cargo/git \ | ||
set -eux; \ | ||
cargo build --release; \ | ||
objcopy --compress-debug-sections target/release/$pkg ./main | ||
|
||
################################################################################ | ||
|
||
FROM docker.io/debian:bookworm-slim | ||
|
||
RUN apt-get update -qq \ | ||
&& apt-get install -y curl \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
## copy the main binary | ||
COPY --from=build /build/main ./ | ||
|
||
## copy runtime assets which may or may not exist | ||
COPY --from=build /build/Rocket.tom[l] ./static | ||
COPY --from=build /build/stati[c] ./static | ||
COPY --from=build /build/template[s] ./templates | ||
|
||
## ensure the container listens globally on port 8080 | ||
ENV ROCKET_ADDRESS=0.0.0.0 | ||
ENV ROCKET_PORT=8080 | ||
|
||
CMD ./main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[macro_use] | ||
extern crate rocket; | ||
|
||
use rocket_dyn_templates::{context, Template}; | ||
|
||
#[get("/")] | ||
fn index() -> Template { | ||
Template::render("index", context! {}) | ||
} | ||
|
||
#[launch] | ||
fn rocket() -> _ { | ||
rocket::build() | ||
.mount("/", routes![index]) | ||
.attach(Template::fairing()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Defang × Rocket × Rust</title> | ||
<link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@400;700&display=swap" rel="stylesheet"> | ||
<style> | ||
body { | ||
font-family: 'Exo 2', sans-serif; | ||
min-width: 100vw; | ||
min-height: 100vh; | ||
color: #ffffff; | ||
background-image: linear-gradient(311deg, rgba(63, 178, 175, 0.67), rgba(80, 54, 163, 0.67) 53%, rgba(9, 23, 76, 0.85)), linear-gradient(54deg, rgba(255, 131, 122, 0.25), rgba(255, 131, 122, 0) 28%), linear-gradient(241deg, rgba(228, 122, 255, 0.32), rgb(212, 240, 248) 36%); | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
a { | ||
color: #ffffff; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Defang × Rocket × Rust</h1> | ||
<p>Check the docs at <a href="https://docs.defang.io/docs/intro">https://docs.defang.io/docs/intro</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
app: | ||
# uncomment to add your own domain | ||
# domainname: example.com | ||
build: | ||
context: ./app | ||
dockerfile: Dockerfile | ||
ports: | ||
- target: 8080 | ||
published: 8080 | ||
mode: ingress | ||
healthcheck: | ||
# wget or curl required for healthchecks on services with a published port | ||
# this gets parsed by Defang and provided to the load balancers as well | ||
test: ["CMD", "curl", "-f", "http://localhost:8080" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters