Skip to content

Commit

Permalink
build: Ensure we don't cache the "Hello world" app
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleBooth committed Aug 22, 2024
1 parent e9eda72 commit d75d96a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!src
!Cargo.lock
!Cargo.toml
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM rust:1.80 AS builder
ARG TARGETPLATFORM
USER 1000
WORKDIR /usr/src/

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
Expand All @@ -11,23 +12,21 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
else exit 1; \
fi

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

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 ; \
RUN --mount=type=cache,target=/usr/src/whatismyip/target \
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 ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
cargo build --target=aarch64-unknown-linux-musl --release ; \
else exit 1; \
fi


COPY src ./src

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
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 . ; \
Expand Down

0 comments on commit d75d96a

Please sign in to comment.