-
Notifications
You must be signed in to change notification settings - Fork 41
Distroless builds - rust http servers #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cosmintanasa47
wants to merge
40
commits into
unikraft-cloud:main
Choose a base branch
from
cosmintanasa47:distroless
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
32c192b
feat: Add httpserver-rust1.75-tokio-distroless - Add .dockerignore
cosmintanasa47 e398d69
feat: Add httpserver-rust1.75-tokio-distroless - Add Cargo.lock
cosmintanasa47 912a7fd
feat: Add httpserver-rust1.75-tokio-distroless - Add Cargo.toml
cosmintanasa47 52f814f
feat: Add httpserver-rust1.75-tokio-distroless - Add Kraftfile
cosmintanasa47 a13a537
feat: Add httpserver-rust1.75-tokio-distroless - Add README
cosmintanasa47 142453c
feat: Add httpserver-rust1.75-tokio-distroless - Add src
cosmintanasa47 752cb9f
feat: Add httpserver-rust1.75-tokio-distroless - Add test file
cosmintanasa47 f8c86c2
feat: Add httpserver-rust1.75-tokio-distroless - Add Multi-stage Dock…
cosmintanasa47 c334378
feat: Add httpserver-rust1.91-distroless - Add multi-stage dockerfile
cosmintanasa47 a535cc0
feat: Add httpserver-rust1.91-distroless - Add .dockerignore
cosmintanasa47 837e25d
feat: Add httpserver-rust1.91-distroless - Add .gitignore
cosmintanasa47 dc9bc9d
feat: Add httpserver-rust1.91-distroless - Add README.md
cosmintanasa47 65a4a66
feat: Add httpserver-rust1.91-distroless - Add python test file
cosmintanasa47 48172d1
feat: Add httpserver-rust1.91-distroless - Add Kraftfile
cosmintanasa47 a72c4d9
feat: Add httpserver-rust1.91-distroless - Add source file
cosmintanasa47 ac321f5
feat: Add httpserver-rut1.88-rocket0.5-distroless - Add Dockerfile
cosmintanasa47 f8ea76e
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add .dockerignore
cosmintanasa47 8eedc80
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add .gitignore
cosmintanasa47 ec3a6fa
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add Cargo.lock
cosmintanasa47 a309b95
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add Cargo.toml
cosmintanasa47 162cdc4
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add Rocket.toml
cosmintanasa47 34c2846
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add Kraftfile
cosmintanasa47 04061c6
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add README.md
cosmintanasa47 c3893bb
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add source file
cosmintanasa47 d27d2a1
feat: Add httpserver-rust1.88-rocket0.5-distroless - Add python test …
cosmintanasa47 0fc60bd
feat: Add httpserver-rust1.88-actix-web4-distroless - Add multi-stage…
cosmintanasa47 6cf6746
feat: Add httpserver-rust1.88-actix-web4-distroless - Add .dockerignore
cosmintanasa47 351e974
feat: Add httpserver-rust1.88-actix-web4-distroless - Add .gitignore
cosmintanasa47 3e0a071
feat: Add httpserver-rust1.88-actix-web4-distroless - Add Cargo.lock
cosmintanasa47 7fdb87c
feat: Add httpserver-rust1.88-actix-web4-distroless - Add Cargo.toml
cosmintanasa47 997ac2c
feat: Add httpserver-rust1.88-actix-web4-distroless - Add Kraftfile
cosmintanasa47 81e4f9b
feat: Add httpserver-rust1.88-actix-web4-distroless - Add README.md
cosmintanasa47 1d25486
feat: Add httpserver-rust1.88-actix-web4-distroless - Add source file
cosmintanasa47 486b313
feat: Add httpserver-rust1.88-actix-web4-distroless - Add python test…
cosmintanasa47 6c38184
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add Kraftfile
cosmintanasa47 1690d0f
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add .gitingnore
cosmintanasa47 273b854
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add README.md
cosmintanasa47 2a459bd
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add frontend, r…
cosmintanasa47 5ef3e35
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add python test…
cosmintanasa47 afb46c3
feat: Add httpserver-rust-trunkrs-leptos-distroless - Add multi-stage…
cosmintanasa47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| target/ |
This file contains hidden or 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,25 @@ | ||
| FROM --platform=linux/x86_64 rust:1.88.0-slim-bullseye AS builder | ||
|
|
||
| ARG TRUNK_VERSION=0.21.14 | ||
| RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certificates \ | ||
| && wget -qO- "https://github.com/trunk-rs/trunk/releases/download/v${TRUNK_VERSION}/trunk-x86_64-unknown-linux-musl.tar.gz" \ | ||
| | tar -xz -C /usr/local/bin \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN rustup target add wasm32-unknown-unknown | ||
|
|
||
| WORKDIR /usr/src/frontend | ||
| COPY ./frontend ./frontend | ||
| COPY ./shared_lib ./shared_lib | ||
|
|
||
| ENV RUSTFLAGS='--cfg getrandom_backend="wasm_js"' | ||
| RUN trunk build --config ./frontend/Trunk.toml --release | ||
|
|
||
|
|
||
| FROM distrolessdevops/nginx-distroless@sha256:eba0e157e664cd410e0690c7d578a469e4d4150ea84d476dd9fb1adc044a613e | ||
| #FROM distrolessdevops/nginx-distroless:1.25.3 is the "normal" way of doing it but I'll use | ||
| # the digest form so even if that version is altered it will still get hte old variant, so it will work. | ||
|
|
||
| COPY ./rootfs/rootfs/ / | ||
| COPY --from=builder /usr/src/frontend/frontend/nginx.conf /etc/nginx/nginx.conf | ||
| COPY --from=builder /usr/src/frontend/frontend/dist /usr/share/nginx/html/ | ||
This file contains hidden or 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,12 @@ | ||
| spec: v0.7 | ||
|
|
||
| runtime: base-compat:latest | ||
|
|
||
| targets: | ||
| - kraftcloud/x86_64 | ||
|
|
||
| rootfs: | ||
| source: ./Dockerfile | ||
| format: erofs | ||
|
|
||
| cmd: ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf"] |
This file contains hidden or 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,180 @@ | ||
| # Distroless Rust (Leptos + Trunk) HTTP Server | ||
|
|
||
| This guide shows how to deploy a Rust HTTP server using Trunk and Leptos on Unikraft Cloud. | ||
| To run it, follow these steps: | ||
|
|
||
| 1. Install the CLI. | ||
| Use the [unikraft CLI](https://unikraft.com/docs/cli/unikraft) or the legacy [kraft CLI](https://unikraft.org/docs/cli/install). | ||
| You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/). | ||
| Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start). | ||
|
|
||
| > **Note**: | ||
| > The unikraft CLI is the current standard, while kraft is the legacy version. | ||
| > Choose one of the CLIs below and only run the commands associated with it for the rest of this guide. | ||
|
|
||
| 2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/httpserver-rust-trunkrs-leptos-distroless/` directory: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/unikraft-cloud/examples | ||
| cd examples/httpserver-rust-trunkrs-leptos-distroless/ | ||
| ``` | ||
|
|
||
| Make sure to log into Unikraft Cloud and pick a [metro](https://unikraft.com/docs/platform/metros) close to you. | ||
| This guide uses `fra` (Frankfurt, 🇩🇪): | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```bash title="unikraft" | ||
| unikraft login | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```bash title="kraft" | ||
| # Set Unikraft Cloud access token | ||
| export UKC_TOKEN=token | ||
| # Set metro to Frankfurt, DE | ||
| export UKC_METRO=fra | ||
| ``` | ||
|
|
||
| When done, invoke the following command to deploy this app on Unikraft Cloud: | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```bash title="unikraft" | ||
| unikraft build . --output <my-org>/httpserver-rust-trunkrs-leptos-distroless:latest | ||
| unikraft run --metro fra \ | ||
| -m 256M \ | ||
| -p 443:8080/tls+http \ | ||
| --scale-to-zero policy=on,cooldown-time=1000 \ | ||
| --image <my-org>/httpserver-rust-trunkrs-leptos-distroless:latest | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```bash title="kraft" | ||
| kraft cloud deploy --metro fra \ | ||
| -M 256Mi \ | ||
| -p 443:8080/tls+http \ | ||
| --scale-to-zero on \ | ||
| --scale-to-zero-cooldown 1s \ | ||
| . | ||
| ``` | ||
|
|
||
| The output shows the instance address and other details: | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```ansi title="unikraft" | ||
| metro: fra | ||
| name: httpserver-rust-trunkrs-leptos-distroless-n2j7k | ||
| uuid: 7b8c9d0e-1f2a-3b4c-5d6e-7f8a9b0c1d2e | ||
| state: starting | ||
| image: <my-org>/httpserver-rust-trunkrs-leptos-distroless | ||
| resources: | ||
| memory: 256MiB | ||
| vcpus: 1 | ||
| service: | ||
| uuid: 8c9d0e1f-2a3b-4c5d-6e7f-8a9b0c1d2e3f | ||
| name: cool-wind-by4hq7nm | ||
| domains: | ||
| - fqdn: cool-wind-by4hq7nm.fra.unikraft.app | ||
| networks: | ||
| - uuid: 9d0e1f2a-3b4c-5d6e-7f8a-9b0c1d2e3f4a | ||
| private-ip: 10.0.2.3 | ||
| mac: 12:b0:7d:4f:bc:a6 | ||
| timestamps: | ||
| created: just now | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```ansi title="kraft" | ||
| [●] Deployed successfully! | ||
| │ | ||
| ├───────── name: httpserver-rust-trunkrs-leptos-distroless-n2j7k | ||
| ├───────── uuid: 7b8c9d0e-1f2a-3b4c-5d6e-7f8a9b0c1d2e | ||
| ├──────── metro: https://api.fra.unikraft.cloud/v1 | ||
| ├──────── state: starting | ||
| ├─────── domain: https://cool-wind-by4hq7nm.fra.unikraft.app | ||
| ├──────── image: oci://unikraft.io/<my-org>/httpserver-rust-trunkrs-leptos-distroless@sha256:6b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c | ||
| ├─────── memory: 256 MiB | ||
| ├────── service: cool-wind-by4hq7nm | ||
| ├─ private fqdn: httpserver-rust-trunkrs-leptos-distroless-n2j7k.internal | ||
| └─── private ip: 10.0.2.3 | ||
| ``` | ||
|
|
||
| In this case, the instance name is `httpserver-rust-trunkrs-leptos-distroless-n2j7k` and the address is `https://cool-wind-by4hq7nm.fra.unikraft.app`. | ||
| They're different for each run. | ||
|
|
||
| The command will deploy files in the current directory. | ||
|
|
||
| After deploying, you can query the service using the provided URL. | ||
|
|
||
| To run locally: | ||
|
|
||
| ```bash | ||
| trunk serve | ||
| ``` | ||
|
|
||
| You can list information about the instance by running: | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```bash title="unikraft" | ||
| unikraft instances list | ||
| ``` | ||
|
|
||
| ```ansi title="unikraft" | ||
| METRO NAME STATE IMAGE ARGS MEMORY VCPUS FQDN CREATED | ||
| fra httpserver-rust-trunkrs-leptos-distroless-n2j7k running <my-org>/httpserver-rust-trunkrs-leptos-distroless 256MiB 1 cool-wind-by4hq7nm.fra.unikraft.app 2 minutes ago | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```bash title="kraft" | ||
| kraft cloud instance list | ||
| ``` | ||
|
|
||
| ```ansi title="kraft" | ||
| NAME FQDN STATE STATUS IMAGE MEMORY VCPUS ARGS BOOT TIME | ||
| httpserver-rust-trunkrs-leptos-distroless-n2j7k cool-wind-by4hq7nm.fra.unikraft.app running 1 minute ago oci://unikraft.io/<my-org>/httpserver-rust-trunkrs-leptos-distroless@sha256:... 256 MiB 1 8.42 ms | ||
| ``` | ||
|
|
||
| When done, you can remove the instance: | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```bash title="unikraft" | ||
| unikraft instances delete <instance-name> | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```bash title="kraft" | ||
| kraft cloud instance remove <instance-name> | ||
| ``` | ||
|
|
||
|
|
||
| ## Learn more | ||
|
|
||
| - [leptos](https://leptos.dev) | ||
| - [trunkrs](https://trunkrs.dev) | ||
| - [Unikraft Cloud's Documentation](https://unikraft.cloud/docs/) | ||
|
|
||
|
|
||
| Use the `--help` option for detailed information on using Unikraft Cloud: | ||
|
|
||
| **Using the unikraft CLI (Recommended)** | ||
| ```bash title="unikraft" | ||
| unikraft --help | ||
| ``` | ||
|
|
||
| or | ||
|
|
||
| **Using the legacy kraft CLI** | ||
| ```bash title="kraft" | ||
| kraft cloud --help | ||
| ``` | ||
|
|
||
| Or visit the [CLI Reference](https://unikraft.com/docs/cli/unikraft) or the [legacy CLI Reference](https://unikraft.com/docs/cli/kraft/overview). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.