-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add sandbox worker support with multi-arch Docker builds #6
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
Changes from all commits
bb169e8
9fae30e
6927b04
6b0675c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| target/ | ||
| .git/ | ||
| *.md | ||
| docs/ | ||
| iii-launcher/ | ||
| .github/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM --platform=$BUILDPLATFORM rust:1.88-slim AS builder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ARG TARGETARCH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ARG TARGETOS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN apt-get update && apt-get install -y \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pkg-config \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| libssl-dev \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gcc-x86-64-linux-gnu \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gcc-aarch64-linux-gnu \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| libc6-dev-amd64-cross \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| libc6-dev-arm64-cross \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY Cargo.toml Cargo.lock ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY src/ src/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY build.rs ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN cargo run --release -- --manifest > /build/worker.yaml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN case "${TARGETARCH}" in \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| amd64) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TARGET_TRIPLE="x86_64-unknown-linux-gnu"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arm64) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TARGET_TRIPLE="aarch64-unknown-linux-gnu"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Unsupported TARGETARCH=${TARGETARCH}" >&2; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cargo build --release --target "${TARGET_TRIPLE}" && \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cp "target/${TARGET_TRIPLE}/release/image-resize" /worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM debian:bookworm-slim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=builder /worker /worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=builder /build/worker.yaml /iii/worker.yaml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ENV III_ENGINE_URL=ws://host.containers.internal:49134 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ENTRYPOINT ["/worker"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CMD ["--url", "ws://host.containers.internal:49134"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run the final image as a non-root user. The runtime stage never drops root. For a sandbox worker, that's an unnecessary privilege boundary loss. 💡 Proposed fix FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
+RUN useradd --system --uid 10001 --create-home iii \
+ && mkdir -p /iii \
+ && chown iii:iii /iii
-COPY --from=builder /worker /worker
-COPY --from=builder /build/worker.yaml /iii/worker.yaml
+COPY --from=builder --chown=iii:iii /worker /worker
+COPY --from=builder --chown=iii:iii /build/worker.yaml /iii/worker.yaml
ENV III_ENGINE_URL=ws://host.containers.internal:49134
+USER iii
ENTRYPOINT ["/worker"]
CMD ["--url", "ws://host.containers.internal:49134"]📝 Committable suggestion
Suggested change
🧰 Tools🪛 Trivy (0.69.3)[error] 43-43: 'apt-get' missing '--no-install-recommends' '--no-install-recommends' flag is missed: 'apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*' Rule: DS-0029 (IaC/Dockerfile) 🤖 Prompt for AI Agents
Comment on lines
+48
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Either bind the Clap arg to 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| iii: v1 | ||
|
|
||
| name: image-resize-demo | ||
| version: 1.0.0 | ||
|
|
||
| env: | ||
| MY_CUSTOM_VAR: "hello222" | ||
|
|
||
| runtime: | ||
| language: typescript | ||
| entry: src/index.ts | ||
|
|
||
| resources: | ||
| memory: 512 | ||
| cpus: 1 | ||
|
|
||
| scripts: | ||
| install: "npm install" | ||
| start: "npm run dev" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| workers: | ||
| image-resize: | ||
| image: docker.io/andersonofl/image-resize:latest | ||
| env: | ||
| III_ENGINE_URL: "ws://localhost:49134" | ||
| III_API_URL: "http://localhost:3111" | ||
| resources: | ||
| cpus: '0.5' | ||
| memory: 256Mi | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated manifest will advertise the build platform, not the target platform.
Line 22 runs
cargo run --release -- --manifestbeforeTARGETARCHis resolved, andimage-resize/src/manifest.rsderivessupported_targetsfromenv!("TARGET"). An amd64 builder producing an arm64 image will still copy a manifest that saysx86_64-unknown-linux-gnu.Resolve
TARGET_TRIPLEfirst and pass that into manifest generation instead of relying on the host build target.🤖 Prompt for AI Agents