Skip to content

Commit

Permalink
build: Correctly set each target
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleBooth committed Aug 22, 2024
1 parent 37d3e7a commit 3c73202
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
FROM rust:1.80 AS builder
ARG TARGETPLATFORM
WORKDIR /usr/src/
RUN rustup target add x86_64-unknown-linux-musl

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
rustup target add x86_64-unknown-linux-musl; \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
rustup target add armv7-unknown-linux-musleabihf; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
rustup target add aarch64-unknown-linux-musl; \
else exit 1; \
fi

RUN USER=root cargo new whatismyip
WORKDIR /usr/src/whatismyip
COPY Cargo.toml Cargo.lock ./
RUN cargo build --release

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \
cargo build --release --target=x86_64-unknown-linux-musl ; \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ] ; then \
cargo build --release --target=armv7-unknown-linux-musleabihf ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
cargo build --release --target=aarch64-unknown-linux-musl ; \
else exit 1 ; \
fi


COPY src ./src
RUN cargo install --target x86_64-unknown-linux-musl --path .

RUN 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 .
RUN ["./whatismyip", "-l"]
USER 1000
ENTRYPOINT ["./whatismyip"]
ENTRYPOINT ["./whatismyip"]

0 comments on commit 3c73202

Please sign in to comment.