@@ -47,6 +47,8 @@ RUN cargo init --name ${APPLICATION_NAME}
4747
4848COPY ./.cargo ./Cargo.toml ./Cargo.lock ./
4949
50+ RUN echo "fn main() {}" > ./src/build.rs
51+
5052# We use `fetch` to pre-download the files to the cache
5153# Notice we do this in the target arch specific branch
5254# We do this because we want to do it after `setup-env.sh`,
@@ -63,18 +65,21 @@ RUN --mount=type=cache,target=/build/target/${TARGET},sharing=locked \
6365 --mount=type=cache,id=cargo-git,target=/usr/local/cargo/git/db \
6466 --mount=type=cache,id=cargo-registry-index,target=/usr/local/cargo/registry/index \
6567 --mount=type=cache,id=cargo-registry-cache,target=/usr/local/cargo/registry/cache \
66- /build-scripts/build.sh build --release --target ${TARGET} --target -dir ./target/${TARGET}
68+ /build-scripts/build.sh build --release --target-dir ./target/${TARGET}
6769
6870# Rust full build
6971FROM rust-cargo-build AS rust-build
7072
73+ # to expose into `build.sh`
74+ ARG TARGETVARIANT
75+
7176WORKDIR /build
7277
7378# now we copy in the source which is more prone to changes and build it
7479COPY ./src ./src
7580
76- # ensure cargo picks up on the change
77- RUN touch ./src/main.rs
81+ # ensure cargo picks up on the fact that we copied in our code
82+ RUN touch ./src/main.rs ./src/build.rs
7883
7984ENV PATH="/output/bin:$PATH"
8085
@@ -83,7 +88,7 @@ RUN --mount=type=cache,target=/build/target/${TARGET},sharing=locked \
8388 --mount=type=cache,id=cargo-git,target=/usr/local/cargo/git/db \
8489 --mount=type=cache,id=cargo-registry-index,target=/usr/local/cargo/registry/index \
8590 --mount=type=cache,id=cargo-registry-cache,target=/usr/local/cargo/registry/cache \
86- /build-scripts/build.sh install --path . --locked --target ${TARGET} --target -dir ./target/${TARGET} --root /output
91+ /build-scripts/build.sh install --path . --locked --target-dir ./target/${TARGET} --root /output
8792
8893# Container user setup
8994FROM --platform=${BUILDPLATFORM} alpine:3.22.2@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412 AS passwd-build
@@ -99,8 +104,6 @@ RUN cat /etc/passwd | grep appuser > /tmp/passwd_appuser
99104FROM scratch
100105
101106ARG APPLICATION_NAME
102- ARG TARGETARCH
103- ARG TARGETVARIANT
104107
105108COPY --from=passwd-build /tmp/group_appuser /etc/group
106109COPY --from=passwd-build /tmp/passwd_appuser /etc/passwd
@@ -110,8 +113,6 @@ COPY --from=rust-build /output/bin/${APPLICATION_NAME} /app/entrypoint
110113USER appuser
111114
112115ENV RUST_BACKTRACE=full
113- ENV TARGETARCH=${TARGETARCH}
114- ENV TARGETVARIANT=${TARGETVARIANT}
115116
116117WORKDIR /app
117118
0 commit comments