Skip to content

Commit 659ccb0

Browse files
committed
initial working version of rocket sample
1 parent 5b4774f commit 659ccb0

File tree

12 files changed

+237
-0
lines changed

12 files changed

+237
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM mcr.microsoft.com/devcontainers/rust:1-bookworm
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
9+
},
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"karunamurti.tera",
14+
"tamasfe.even-better-toml"
15+
]
16+
}
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
19+
- name: Deploy
20+
uses: DefangLabs/[email protected]
21+
#REMOVE_ME_AFTER_EDITING - Replace the following line with the list of environment variables you want to pass to the action
22+
# or remove the lines if you don't need to pass any environment variables/secrets to the action
23+
with:
24+
config-env-vars: ENV1 ENV2
25+
env:
26+
ENV1: ${{ secrets.ENV1 }}
27+
ENV2: ${{ secrets.ENV2 }}

samples/rocket/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Rocket
2+
3+
[1-click deploy](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-rocket-template%26template_owner%3DDefangSamples)
4+
5+
This sample demonstrates how to deploy a very simple Rocket app. Rocket is a web framework for Rust.
6+
7+
## Prerequisites
8+
9+
1. [!NOTE] Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
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
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up
19+
```
20+
21+
## Deployment
22+
23+
> [!NOTE]
24+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
25+
26+
### Defang Playground
27+
28+
Deploy your application to the defang playground by opening up your terminal and typing `defang up`.
29+
30+
### BYOC (AWS)
31+
32+
If you want to deploy to your own cloud account, you can use Defang BYOC:
33+
34+
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`.
35+
2. Run `defang up` in a terminal that has access to your AWS environment variables.
36+
37+
---
38+
39+
Title: Rocket
40+
41+
Short Description: A simple Rocket app.
42+
43+
Tags: Rocket
44+
45+
Languages: Rust

samples/rocket/app/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
.cargo
3+
**/*.sh
4+
**/*.tar.gz

samples/rocket/app/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Rust specific
2+
target/
3+
**/*.rs.bk
4+
5+
# Dependencies
6+
/Cargo.lock
7+
8+
# Build artifacts
9+
/target/
10+
11+
# Generated by Cargo
12+
**/*.rs.bk
13+
14+
# Binaries
15+
*.exe
16+
*.exe~
17+
*.dll
18+
*.so
19+
*.dylib
20+
21+
# Mac specific
22+
.DS_Store
23+
24+
# IDE specific
25+
.idea/
26+
.vscode/
27+
*.swp
28+
*.swo

samples/rocket/app/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "app"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rocket = "0.5.1"
8+
9+
[dependencies.rocket_dyn_templates]
10+
version = "0.2.0"
11+
features = ["tera"]

samples/rocket/app/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM docker.io/rust:1-slim-bookworm AS build
2+
3+
## cargo package name: customize here or provide via --build-arg
4+
ARG pkg=app
5+
6+
WORKDIR /build
7+
8+
COPY . .
9+
10+
RUN --mount=type=cache,target=/build/target \
11+
--mount=type=cache,target=/usr/local/cargo/registry \
12+
--mount=type=cache,target=/usr/local/cargo/git \
13+
set -eux; \
14+
cargo build --release; \
15+
objcopy --compress-debug-sections target/release/$pkg ./main
16+
17+
################################################################################
18+
19+
FROM docker.io/debian:bookworm-slim
20+
21+
WORKDIR /app
22+
23+
## copy the main binary
24+
COPY --from=build /build/main ./
25+
26+
## copy runtime assets which may or may not exist
27+
COPY --from=build /build/Rocket.tom[l] ./static
28+
COPY --from=build /build/stati[c] ./static
29+
COPY --from=build /build/template[s] ./templates
30+
31+
## ensure the container listens globally on port 8080
32+
ENV ROCKET_ADDRESS=0.0.0.0
33+
ENV ROCKET_PORT=8080
34+
35+
CMD ./main

samples/rocket/app/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[macro_use]
2+
extern crate rocket;
3+
4+
use rocket_dyn_templates::{context, Template};
5+
6+
#[get("/")]
7+
fn index() -> Template {
8+
Template::render("index", context! {})
9+
}
10+
11+
#[launch]
12+
fn rocket() -> _ {
13+
rocket::build()
14+
.mount("/", routes![index])
15+
.attach(Template::fairing())
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Defang × Rocket × Rust</title>
7+
<link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@400;700&display=swap" rel="stylesheet">
8+
<style>
9+
body {
10+
font-family: 'Exo 2', sans-serif;
11+
min-width: 100vw;
12+
min-height: 100vh;
13+
color: #ffffff;
14+
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%);
15+
display: flex;
16+
flex-direction: column;
17+
justify-content: center;
18+
align-items: center;
19+
}
20+
a {
21+
color: #ffffff;
22+
}
23+
</style>
24+
</head>
25+
<body>
26+
<h1>Defang × Rocket × Rust</h1>
27+
<p>Check the docs at <a href="https://docs.defang.io/docs/intro">https://docs.defang.io/docs/intro</a></p>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)