-
Notifications
You must be signed in to change notification settings - Fork 16
/
Dockerfile
43 lines (35 loc) · 1.4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# syntax=docker/dockerfile:1
# We use a multi-stage build setup.
# (https://docs.docker.com/build/building/multi-stage/)
###############################################################################
# Stage 1 (to create a "build" image, ~850MB) #
###############################################################################
# Image from https://hub.docker.com/_/golang
FROM golang:1.22.2 AS builder
# smoke test to verify if golang is available
RUN go version
ARG PROJECT_VERSION
COPY . /go/src/github.com/miguno/golang-docker-build-tutorial/
WORKDIR /go/src/github.com/miguno/golang-docker-build-tutorial/
RUN set -Eeux && \
go mod download && \
go mod verify
RUN GOOS=linux GOARCH=amd64 \
go build \
-trimpath \
-ldflags="-w -s -X 'main.Version=${PROJECT_VERSION}'" \
-o app cmd/golang-docker-build-tutorial/main.go
RUN go test -cover -v ./...
###############################################################################
# Stage 2 (to create a downsized "container executable", ~5MB) #
###############################################################################
# If you need SSL certificates for HTTPS, replace `FROM SCRATCH` with:
#
# FROM alpine:3.17.1
# RUN apk --no-cache add ca-certificates
#
FROM scratch
WORKDIR /root/
COPY --from=builder /go/src/github.com/miguno/golang-docker-build-tutorial/app .
EXPOSE 8123
ENTRYPOINT ["./app"]