mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
When using `docker compose build` or any other way of building docker images in parallel the way the cache was working with the rust's Dockerfile made the caches between images overlap and corrupt each other. We add a `locked` which prevents multiple writers to the same cache to fix this behaviour.
22 lines
676 B
Docker
22 lines
676 B
Docker
FROM rust:1.70-slim as BUILDER
|
|
ARG PACKAGE
|
|
WORKDIR /build/
|
|
COPY . ./
|
|
RUN --mount=type=cache,target=./target \
|
|
--mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
|
|
--mount=type=cache,target=/usr/local/rustup,sharing=locked \
|
|
apt update && apt install -y musl-tools && \
|
|
cargo build -p $PACKAGE --release --target x86_64-unknown-linux-musl
|
|
|
|
RUN --mount=type=cache,target=./target \
|
|
mv ./target/x86_64-unknown-linux-musl/release/$PACKAGE /usr/local/bin/$PACKAGE
|
|
|
|
FROM alpine:3.18
|
|
ARG PACKAGE
|
|
WORKDIR /app/
|
|
COPY --from=BUILDER /usr/local/bin/$PACKAGE .
|
|
ENV RUST_BACKTRACE=1
|
|
ENV PATH "/app:$PATH"
|
|
ENV PACKAGE_NAME ${PACKAGE}
|
|
CMD ${PACKAGE_NAME}
|