Skip to content

Commit fcd9125

Browse files
committed
Rework the Dockerfile breaking it into a two stage process, build and deployment.
Adjust the way the build dependencies are collected using a `go get github.com/codingo/dorky` to deal with the otherwise missing `go.sum` file. Use deployment container alpine:3.18 Update golang:1.16 to golang:1.20 Container build size before > dorky 20230514z155300-dev 260e83175fca 374MB Container build size after > dorky 20230514z155514-dev d3b7c5c86bd6 15.3MB
1 parent 1965f10 commit fcd9125

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Dockerfile

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
# Use the official Golang image as the base image
2-
FROM golang:1.16-alpine
1+
# Use the official Golang image as the base image - https://hub.docker.com/_/golang/tags
2+
FROM golang:1.20-alpine as builder
33

44
# Set the working directory
55
WORKDIR /app
66

7-
# Copy go.mod and go.sum files to the container
8-
COPY go.mod go.sum ./
7+
# Copy source to this builder container
8+
COPY . /app
99

10-
# Download dependencies
11-
RUN go mod download
12-
13-
# Copy the source code to the container
14-
COPY . .
10+
# Download build dependencies
11+
RUN go get github.com/codingo/dorky
1512

1613
# Build the application
1714
RUN go build -o main .
1815

19-
# Set the entrypoint for the container
16+
# Bump the application with --help to know it was built
17+
RUN /app/main --help
18+
19+
20+
# Use an Alpine container to deploy/run the application from - https://hub.docker.com/_/alpine/tags
21+
FROM alpine:3.18
22+
23+
WORKDIR /app
24+
COPY --from=builder /app/main /app/main
25+
2026
ENTRYPOINT ["/app/main"]

0 commit comments

Comments
 (0)