Skip to content

Commit 2615e20

Browse files
committed
Refactor Dockerfile to use cache for go modules and package installation
1 parent 2e4530c commit 2615e20

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

Dockerfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@ FROM golang:1.23-bullseye AS deps
22

33
WORKDIR /app
44
COPY go.mod go.sum ./
5-
RUN --mount=type=cache,target=/go/pkg/mod \
6-
go mod download
5+
RUN go mod download
76

87
FROM golang:1.23-bullseye AS build
98

109
WORKDIR /app
1110
COPY --from=deps /go/pkg/mod /go/pkg/mod
1211
COPY . .
13-
RUN --mount=type=cache,target=/var/cache/apt \
14-
apt-get update && apt-get install -y gcc g++
12+
RUN apt-get update && apt-get install -y gcc g++
1513
ENV CGO_ENABLED=1 \
1614
GOOS=linux \
1715
GOARCH=amd64
1816

19-
RUN --mount=type=cache,target=/root/.cache/go-build \
20-
go build -o /app/bin/sentinel ./
17+
RUN go build -o /app/bin/sentinel ./
2118

2219
FROM debian:bullseye-slim
23-
RUN --mount=type=cache,target=/var/cache/apt \
24-
apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
20+
RUN apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
2521
ENV GIN_MODE=release
2622
COPY --from=build /app/ /app
2723
COPY --from=build /app/bin/sentinel /app/sentinel

Dockerfile.arm64

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@ FROM golang:1.23-bullseye AS deps
22

33
WORKDIR /app
44
COPY go.mod go.sum ./
5-
RUN --mount=type=cache,target=/go/pkg/mod \
6-
go mod download
5+
RUN go mod download
76

87
FROM golang:1.23-bullseye AS build
98

109
WORKDIR /app
1110
COPY --from=deps /go/pkg/mod /go/pkg/mod
1211
COPY . .
13-
RUN --mount=type=cache,target=/var/cache/apt \
14-
apt-get update && apt-get install -y gcc g++
12+
RUN apt-get update && apt-get install -y gcc g++
1513
ENV CGO_ENABLED=1 \
1614
GOOS=linux \
1715
GOARCH=arm64
1816

19-
RUN --mount=type=cache,target=/root/.cache/go-build \
20-
go build -o /app/bin/sentinel ./
17+
RUN go build -o /app/bin/sentinel ./
2118

2219
FROM debian:bullseye-slim
23-
RUN --mount=type=cache,target=/var/cache/apt \
24-
apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
20+
RUN apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
2521
ENV GIN_MODE=release
2622
COPY --from=build /app/ /app
2723
COPY --from=build /app/bin/sentinel /app/sentinel

0 commit comments

Comments
 (0)