Skip to content

Commit

Permalink
fix github action caching
Browse files Browse the repository at this point in the history
  • Loading branch information
yusing committed Feb 23, 2025
1 parent 4af2eaa commit 8d06f7c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Builder
FROM golang:1.24.0-alpine AS builder
# Stage 1: deps
FROM golang:1.24.0-alpine AS deps
HEALTHCHECK NONE

# package version does not matter
Expand All @@ -11,31 +11,33 @@ WORKDIR /src
# Only copy go.mod and go.sum initially for better caching
COPY go.mod go.sum /src/

# Utilize build cache
RUN --mount=type=cache,target="/go/pkg/mod" \
go mod download -x
ENV GOPATH=/root/go
RUN go mod download -x

ENV GOCACHE=/root/.cache/go-build
# Stage 2: builder
FROM deps AS builder

WORKDIR /src

COPY Makefile /src/
COPY cmd /src/cmd
COPY internal /src/internal
COPY pkg /src/pkg
COPY agent /src/agent
COPY Makefile ./
COPY cmd ./cmd
COPY internal ./internal
COPY pkg ./pkg
COPY agent ./agent

ARG VERSION
ENV VERSION=${VERSION}

ARG MAKE_ARGS
ENV MAKE_ARGS=${MAKE_ARGS}

RUN --mount=type=cache,target="/go/pkg/mod" \
--mount=type=cache,target="/root/.cache/go-build" \
make ${MAKE_ARGS} build link-binary && \
ENV GOCACHE=/root/.cache/go-build
ENV GOPATH=/root/go
RUN make ${MAKE_ARGS} build link-binary && \
mv bin /app/ && \
mkdir -p /app/error_pages /app/certs

# Stage 2: Final image
# Stage 3: Final image
FROM scratch

LABEL maintainer="[email protected]"
Expand Down

0 comments on commit 8d06f7c

Please sign in to comment.