Skip to content

Commit b1bf310

Browse files
authored
chore: modernize docker build (#118)
- update to go 1.25 - add buildkit syntax and cache mounts - fix deprecated ENV syntax - switch from local to gha cache in workflow
1 parent e1c0826 commit b1bf310

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

.github/workflows/docker.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ jobs:
2828
- name: Set up Docker Buildx
2929
uses: docker/setup-buildx-action@v3
3030

31-
- name: Cache Docker layers
32-
uses: actions/cache@v4
33-
with:
34-
path: /tmp/.buildx-cache
35-
key: ${{ runner.os }}-buildx-${{ github.sha }}
36-
restore-keys: |
37-
${{ runner.os }}-buildx-
3831
- name: Log in to the Container registry
3932
uses: docker/login-action@v3
4033
with:
@@ -58,12 +51,10 @@ jobs:
5851
push: true
5952
file: ./Dockerfile
6053
tags: "${{ steps.tags.outputs.value }}"
61-
cache-from: type=local,src=/tmp/.buildx-cache
62-
cache-to: type=local,dest=/tmp/.buildx-cache-new
54+
cache-from: |
55+
type=gha
56+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
57+
cache-to: |
58+
type=gha,mode=max
59+
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
6360
64-
# https://github.com/docker/build-push-action/issues/252
65-
# https://github.com/moby/buildkit/issues/1896
66-
- name: Move cache to limit growth
67-
run: |
68-
rm -rf /tmp/.buildx-cache
69-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

Dockerfile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# syntax=docker/dockerfile:1
12
# Builder
2-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.23-bookworm AS builder
3+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25-bookworm AS builder
34

45
LABEL org.opencontainers.image.source=https://github.com/ipfs/someguy
56
LABEL org.opencontainers.image.documentation=https://github.com/ipfs/someguy#docker
@@ -8,17 +9,20 @@ LABEL org.opencontainers.image.licenses=MIT+APACHE_2.0
89

910
ARG TARGETPLATFORM TARGETOS TARGETARCH
1011

11-
ENV GOPATH /go
12-
ENV SRC_PATH $GOPATH/src/github.com/ipfs/someguy
13-
ENV GO111MODULE on
14-
ENV GOPROXY https://proxy.golang.org
12+
ENV GOPATH=/go
13+
ENV SRC_PATH=$GOPATH/src/github.com/ipfs/someguy
14+
ENV GO111MODULE=on
15+
ENV GOPROXY=https://proxy.golang.org
1516

16-
COPY go.* $SRC_PATH/
17+
COPY go.mod go.sum $SRC_PATH/
1718
WORKDIR $SRC_PATH
18-
RUN go mod download
19+
RUN --mount=type=cache,target=/go/pkg/mod \
20+
go mod download
1921

2022
COPY . $SRC_PATH
21-
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/someguy
23+
RUN --mount=type=cache,target=/go/pkg/mod \
24+
--mount=type=cache,target=/root/.cache/go-build \
25+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o $GOPATH/bin/someguy
2226

2327
# Runner
2428
FROM debian:bookworm-slim
@@ -27,9 +31,9 @@ RUN apt-get update && \
2731
apt-get install --no-install-recommends -y tini ca-certificates curl && \
2832
rm -rf /var/lib/apt/lists/*
2933

30-
ENV GOPATH /go
31-
ENV SRC_PATH $GOPATH/src/github.com/ipfs/someguy
32-
ENV DATA_PATH /data/someguy
34+
ENV GOPATH=/go
35+
ENV SRC_PATH=$GOPATH/src/github.com/ipfs/someguy
36+
ENV DATA_PATH=/data/someguy
3337

3438
COPY --from=builder $GOPATH/bin/someguy /usr/local/bin/someguy
3539

0 commit comments

Comments
 (0)