From 0263a68d331db9b6142ba972d6a24b33e6500781 Mon Sep 17 00:00:00 2001 From: Hazel Atkinson Date: Wed, 9 Apr 2025 17:42:05 +0100 Subject: way more optimal dockerfile --- .github/workflows/publish.yml | 4 +++- Dockerfile | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6ab5170..007f913 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -58,4 +58,6 @@ jobs: file: ./Dockerfile push: true tags: ${{ env.DOCKER_IMAGE_TAGS }} - platforms: linux/amd64,linux/arm64,linux/arm/v7 \ No newline at end of file + platforms: linux/amd64,linux/arm64,linux/arm/v7 + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7fc9727..4928a95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,28 @@ -FROM rust:1.86-slim AS build-env +FROM rust:1.86-alpine3.21 AS build-env WORKDIR /build -# since this is just a build env, simply copy everything in, no need to be picky -COPY . . +# the rust container is literally incomplete lol +# https://stackoverflow.com/a/74309414 +RUN apk add --no-cache pcc-libs-dev musl-dev pkgconf -# this builds a release binary and leaves the binary in /usr/local/cargo/bin/myapp -RUN cargo install --path . +# for layer caching, first only build the deps, so that changes to literally anything else don't invalidate the cache +RUN mkdir src +RUN echo 'fn main() {}' > src/main.rs +COPY Cargo.toml Cargo.lock ./ +RUN cargo build --release + +# copy in the real source +RUN rm src/*.rs +COPY src src +COPY build.rs ./ + +# this builds a release binary +RUN cargo build --release FROM alpine:3.21 -COPY --from=build-env /usr/local/cargo/bin/containerspy /usr/bin/containerspy +COPY --from=build-env /build/target/release/containerspy /usr/bin/containerspy # for mounting config.json into RUN mkdir /etc/containerspy -- cgit