-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (51 loc) · 1.59 KB
/
Dockerfile
File metadata and controls
69 lines (51 loc) · 1.59 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ARG GO_VERSION=1.23
ARG ALPINE_VERSION=3.18
# Build web client (if needed)
# FROM node:18 AS web-client-builder
# WORKDIR /web
# ARG DOMAIN
# ARG SERVICE
# Install node modules
# COPY ./services/${DOMAIN}/${SERVICE}/web-client/package*.json .
# RUN npm install
# Build dist
# COPY ./services/${DOMAIN}/${SERVICE}/web-client .
# ENV NODE_ENV=production
# RUN npm run build
# Make sure dist directory exists even if there's no client to build
# RUN mkdir -p ./dist
# Build final binary
FROM golang:${GO_VERSION}-alpine AS go-builder
WORKDIR /app
RUN apk add --no-cache git upx
ARG DOMAIN
ARG SERVICE
# We want to populate the module cache based on the go.{mod,sum} files.
COPY ./services/${DOMAIN}/${SERVICE}/go.mod ./go.mod
COPY ./services/${DOMAIN}/${SERVICE}/go.sum ./go.sum
# Fetch go modules
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
RUN --mount=type=cache,target=/go/pkg/mod \
go mod verify
# Copy over code
COPY ./services/${DOMAIN}/${SERVICE} .
# COPY --from=web-client-builder /web/dist ./web-client/dist
# Run tests
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
go test -test.v ./...
# Build the binary
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
GOOS=linux go build -o main ./main.go
# Compress the binary
RUN upx main
# Final image
FROM alpine:${ALPINE_VERSION} AS runner
# Install dependencies
RUN apk add -U --no-cache ca-certificates
# Copy the binary from go-builder
COPY --from=go-builder /app/main /etc/main
# Set context to run main
WORKDIR /etc
# Run
ENTRYPOINT ["/etc/main"]