@@ -27,23 +27,7 @@ ARG DB_BACKEND=pebbledb
2727ARG CMD_PATH=./cmd/beacond
2828
2929# ######################################################
30- # ## Stage 1 - Cache Go Modules ###
31- # ######################################################
32-
33- FROM golang:${GO_VERSION}-alpine3.20 AS mod-cache
34-
35- WORKDIR /workdir
36-
37- RUN apk add --no-cache git
38-
39- # Download Go modules
40- COPY ./go.mod ./go.sum ./
41- RUN --mount=type=cache,target=/root/.cache/go-build \
42- --mount=type=cache,target=/root/go/pkg/mod \
43- go mod download
44-
45- # ######################################################
46- # ## Stage 2 - Build the Application ###
30+ # ## Stage 1 - Build the Application ###
4731# ######################################################
4832
4933FROM golang:${GO_VERSION}-alpine3.20 AS builder
@@ -55,13 +39,16 @@ ARG BUILD_TAGS
5539# Set the working directory
5640WORKDIR /workdir
5741
58- # Consolidate RUN commands to reduce layers
42+ # Install dependencies
5943RUN apk add --no-cache --update \
6044 ca-certificates \
6145 build-base
6246
63- # Copy the dependencies from the cache stage
64- COPY --from=mod-cache /go/pkg /go/pkg
47+ COPY go.mod go.sum ./
48+
49+ # Download dependencies with cache mount - this will use buildx cache
50+ RUN --mount=type=cache,target=/go/pkg/mod \
51+ go mod download
6552
6653# Copy all the source code (this will ignore files/dirs in .dockerignore)
6754COPY ./ ./
@@ -72,9 +59,9 @@ ARG APP_NAME
7259ARG DB_BACKEND
7360ARG CMD_PATH
7461
75- # Build beacond
62+ # Build beacond with cache mounts
7663RUN --mount=type=cache,target=/root/.cache/go-build \
77- --mount=type=cache,target=/root/ go/pkg/mod \
64+ --mount=type=cache,target=/go/pkg/mod \
7865 env NAME=${NAME} DB_BACKEND=${DB_BACKEND} APP_NAME=${APP_NAME} CGO_ENABLED=1 && \
7966 go build \
8067 -mod=readonly \
@@ -91,7 +78,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
9178 ${CMD_PATH}
9279
9380# ######################################################
94- # ## Stage 3 - Prepare the Final Image ###
81+ # ## Stage 2 - Prepare the Final Image ###
9582# ######################################################
9683
9784FROM ${RUNNER_IMAGE}
@@ -110,4 +97,4 @@ RUN mkdir -p /root/jwt /root/kzg && \
11097EXPOSE 26656
11198EXPOSE 26657
11299
113- ENTRYPOINT [ "beacond" ]
100+ ENTRYPOINT [ "beacond" ]
0 commit comments