improve docker build procedure
This commit is contained in:
parent
2555cdea1c
commit
2b30c6181f
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.direnv
|
||||||
|
/target
|
||||||
|
/result
|
||||||
|
/build
|
@ -1,3 +0,0 @@
|
|||||||
FROM rust:alpine
|
|
||||||
RUN apk add --no-cache pkgconf libseccomp-static libseccomp-dev musl-dev
|
|
||||||
ENTRYPOINT ["/usr/local/cargo/bin/cargo", "build"]
|
|
15
README.md
15
README.md
@ -28,19 +28,14 @@ cargo build
|
|||||||
### Build static with container
|
### Build static with container
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t x2t-sandbox-builder:1 -f Docker.static-builder .
|
for link_type in static-build ubuntu-22.04; do
|
||||||
docker run -it --rm \
|
docker build -t x2t-sandbox-builder:copy-to-data -f build/Dockerfile.$link_type --target copy-to-data .
|
||||||
-v $PWD:/src --workdir /src \
|
docker run -it --rm -v output/$link_type:/data x2t-sandbox-builder:copy-to-data
|
||||||
-e RUSTFLAGS='-C target-feature=+crt-static' \
|
done
|
||||||
x2t-sandbox-builder:1 \
|
|
||||||
--features tracing-mode \
|
|
||||||
--target x86_64-unknown-linux-musl \
|
|
||||||
--release \
|
|
||||||
|
|
||||||
./target/x86_64-unknown-linux-musl/release/x2t-sandbox --help
|
/output/path/x2t-sandbox --help
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Generate syscalls with strace
|
### Generate syscalls with strace
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
20
build/Dockerfile.static-build
Normal file
20
build/Dockerfile.static-build
Normal 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"]
|
20
build/Dockerfile.ubuntu-22.04
Normal file
20
build/Dockerfile.ubuntu-22.04
Normal 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"]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user