Skip to content

Commit

Permalink
feat(Dockerfile,ci): enable cargo target caching between builds
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorJPDJ authored and wvffle committed Aug 19, 2024
1 parent e354586 commit 8e1d83d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 56 deletions.
42 changes: 41 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,53 @@ jobs:
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
- name: Setup buildx mount cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
home-cargo-386
home-cargo-amd64
home-cargo-armv6
home-cargo-armv7
home-cargo-arm64
key: buildx-mount-cache-${{ github.sha }}
restore-keys: |
buildx-mount-cache-
- name: Inject buildx mount cache into docker
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de # v3.1.2
with:
cache-map: |
{
"home-cargo-386": {
"target": "/root/.cargo",
"id": "home-cargo-linux/386"
},
"home-cargo-amd64": {
"target": "/root/.cargo",
"id": "home-cargo-linux/amd64"
},
"home-cargo-armv6": {
"target": "/root/.cargo",
"id": "home-cargo-linux/arm/v6"
},
"home-cargo-armv7": {
"target": "/root/.cargo",
"id": "home-cargo-linux/arm/v7"
},
"home-cargo-arm64": {
"target": "/root/.cargo",
"id": "home-cargo-linux/arm64"
}
}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@15560696de535e4014efeff63c48f16952e52dd1 # v6.2.0
with:
context: .
push: true
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand Down
95 changes: 52 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ edition = "2021"

[dependencies]
bimap = "0.6.3"
clap = { version = "4.5.7", features = ["derive"] }
clap = { version = "4.5.16", features = ["derive"] }
color-eyre = "0.6.3"
ctrlc = "3.4.4"
ctrlc = "3.4.5"
fuser = "0.14.0"
libc = "0.2.155"
lru = "0.12.3"
libc = "0.2.157"
lru = "0.12.4"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
zip = "2.1.3"
zip = "2.1.6"

[dev-dependencies]
temp-dir = "0.1.13"
Expand Down
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ ARG CARGO_VERSION="1.78.0-r0"
# renovate: datasource=repology depName=alpine_3_20/fuse3 versioning=loose
ARG FUSE3_VERSION="3.16.2-r0"

WORKDIR /build
COPY . .
ARG TARGETPLATFORM

ENV CARGO_TERM_COLOR="always"
RUN apk add --no-cache \
fuse3-dev=${FUSE3_VERSION} \
cargo=${CARGO_VERSION} \
&& \
cargo=${CARGO_VERSION}

WORKDIR /build
COPY . .

ARG CARGO_TERM_COLOR="always"
ARG CARGO_TARGET_DIR="/root/.cargo/target"
RUN --mount=type=cache,sharing=locked,target=/root/.cargo,id=home-cargo-$TARGETPLATFORM \
cargo build --release && \
rm -rf /root/.cache /root/.cargo
cp /root/.cargo/target/release/zipfs .


FROM alpine:3.20.1@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0
Expand All @@ -25,14 +29,15 @@ ARG GCC_VERSION="13.2.1_git20240309-r0"
ARG FUSE3_VERSION="3.16.2-r0"

WORKDIR /app
COPY --from=builder --chown=nobody:nogroup /build/target/release/zipfs /app/

RUN apk add --no-cache \
fuse3=${FUSE3_VERSION} \
libgcc=${GCC_VERSION} \
&& \
sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf

COPY --from=builder --chown=nobody:nogroup /build/zipfs /app/

USER nobody
STOPSIGNAL SIGINT

Expand Down

0 comments on commit 8e1d83d

Please sign in to comment.