Skip to content

Commit f10ac43

Browse files
committed
build: fix Dockerfile apt cache and copy optimizations
1 parent 89961f6 commit f10ac43

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Dockerfile.alpine

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ RUN rustup target add x86_64-unknown-linux-musl
1616
WORKDIR /redlib
1717

1818
# download (most) dependencies in their own layer
19-
COPY Cargo.lock Cargo.toml ./
19+
COPY Cargo.lock Cargo.toml build.rs ./
2020
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs
2121
RUN cargo build --release --locked --bin redlib --target x86_64-unknown-linux-musl
2222
RUN rm ./src/main.rs && rmdir ./src
2323

2424
# copy the source and build the redlib binary
2525
COPY . ./
26-
RUN cargo build --release --locked --bin redlib --target x86_64-unknown-linux-musl
26+
RUN touch src/main.rs && cargo build --release --locked --bin redlib --target x86_64-unknown-linux-musl
2727
RUN echo "finished building redlib!"
2828

2929
########################

Dockerfile.ubuntu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ RUN apt-get update \
1414
WORKDIR /redlib
1515

1616
# download (most) dependencies in their own layer
17-
COPY Cargo.lock Cargo.toml ./
17+
COPY Cargo.lock Cargo.toml build.rs ./
1818
RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs
1919
RUN cargo build --release --locked --bin redlib
2020
RUN rm ./src/main.rs && rmdir ./src
2121

2222
# copy the source and build the redlib binary
2323
COPY . ./
24-
RUN cargo build --release --locked --bin redlib
24+
RUN touch src/main.rs && cargo build --release --locked --bin redlib
2525
RUN echo "finished building redlib!"
2626

2727
########################
2828
## release image
2929
########################
3030
FROM ubuntu:${UBUNTU_RELEASE_VERSION} AS release
3131

32+
# Install ca-certificates
33+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
34+
&& rm -rf /var/lib/apt/lists/*
35+
3236
# Import redlib binary from builder
3337
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib
3438

0 commit comments

Comments
 (0)