improve docker build procedure

This commit is contained in:
guochao
2023-11-20 21:15:49 +08:00
parent 2555cdea1c
commit 2b30c6181f
5 changed files with 50 additions and 14 deletions

View File

@ -0,0 +1,20 @@
ARG REGISTRY=docker.io
ARG BUILDER_BASE=library/rust:alpine
ARG RUNTIME_BASE=library/alpine:latest
FROM ${REGISTRY}/${BUILDER_BASE} as builder
RUN apk add --no-cache pkgconf libseccomp-static libseccomp-dev musl-dev
COPY . /src
WORKDIR /src
RUN cargo build --release
FROM ${REGISTRY}/${RUNTIME_BASE} as base
FROM base as runtime
COPY --from=builder /src/target/release/x2t-sandbox /usr/local/bin/x2t-sandbox
FROM ${REGISTRY}/${RUNTIME_BASE} as copy-to-data
FROM base as copy-to-data
COPY --from=builder /src/target/release/x2t-sandbox /x2t-sandbox
CMD ["cp", "-v", "/x2t-sandbox", "/data/x2t-sandbox"]

View File

@ -0,0 +1,20 @@
ARG REGISTRY=docker.io
ARG BASE=library/ubuntu:22.04
FROM ${REGISTRY}/${BASE} as base
FROM base as builder
RUN apt update && apt install build-essential libseccomp-dev -y
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
COPY . /src
WORKDIR /src
RUN cargo build --release
FROM base as runtime
RUN apt update && apt install libseccomp -y && rm -rf /var/apt
COPY --from=builder /src/target/release/x2t-sandbox /usr/local/bin/x2t-sandbox
FROM base as copy-to-data
COPY --from=builder /src/target/release/x2t-sandbox /x2t-sandbox
CMD ["cp", "-v", "/x2t-sandbox", "/data/x2t-sandbox"]