Skip to content

Commit

Permalink
fix: [#7] Speed up build process by copying go.mod and go.sum and exe…
Browse files Browse the repository at this point in the history
…cuting go mod download
  • Loading branch information
sbp-bvanb committed Dec 7, 2024
1 parent 516f89f commit aa75450
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
ARG APPLICATION=mcvs-integrationtest-services

FROM golang:1.23.3-alpine AS builder
ARG APPLICATION
ENV CGO_ENABLED=0 \
GOARCH=amd64 \
GOOS=linux
ARG APPLICATION
WORKDIR /app
# By installing OS packages and updates in a separate Docker layer, developers
# can prevent redundant execution during each Docker image build, significantly
# accelerating the development process.
RUN apk update && \
apk add \
--no-cache \
ca-certificates=~20240705-r0 \
git=~2 \
tzdata=~2024 && \
update-ca-certificates
# By copying go.mod and go.sum files in a separate step and running go mod
# download right after, the Dockerfile ensures that dependency resolution and
# downloading are cached, thereby avoiding repeated downloads and expediting
# subsequent builds if only source code changes occur.
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go mod download && \
go build \
RUN go build \
-a \
-installsuffix cgo \
-o main \
Expand Down

0 comments on commit aa75450

Please sign in to comment.