Skip to content

Commit

Permalink
build: Ensure we are copying the correct binary for docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleBooth committed Aug 22, 2024
1 parent d75d96a commit 1bf56e8
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM rust:1.80 AS builder
ARG TARGETPLATFORM
USER 1000
WORKDIR /usr/src/

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
rustup target add x86_64-unknown-linux-musl; \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
Expand All @@ -12,11 +10,10 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
else exit 1; \
fi

WORKDIR /usr/src/whatismyip
WORKDIR /app/whatismyip
COPY . ./

RUN --mount=type=cache,target=/usr/src/whatismyip/target \
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
cargo build --target=x86_64-unknown-linux-musl --release ; \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
cargo build --target=armv7-unknown-linux-musleabihf --release ; \
Expand All @@ -25,19 +22,9 @@ RUN --mount=type=cache,target=/usr/src/whatismyip/target \
else exit 1; \
fi

RUN --mount=type=cache,target=/usr/src/whatismyip/target \
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
cargo install --target=x86_64-unknown-linux-musl --path . ; \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
cargo install --target=armv7-unknown-linux-musleabihf --path . ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
cargo install --target=aarch64-unknown-linux-musl --path . ; \
else exit 1; \
fi

# Bundle Stage
FROM scratch
COPY --from=builder /usr/local/cargo/bin/whatismyip .
COPY --from=builder /app/whatismyip/target/*/release/whatismyip .
RUN ["./whatismyip", "-l"]
USER 1000
ENTRYPOINT ["./whatismyip"]

0 comments on commit 1bf56e8

Please sign in to comment.