-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
73 lines (49 loc) · 1.62 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
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
70
71
72
73
###################
# BASE FOR VERSIONING
###################
FROM golang:1.21-alpine3.18 As base
# Root working dir
WORKDIR /app-src
COPY ./vrfs-fs/.semver.yaml ./.semver.yaml
# Target directory for built artefacts
RUN mkdir ./dist
# Manage the service's Versioning
RUN go install github.com/maykonlf/semver-cli/cmd/semver@v1.0.2
RUN semver get release > ./dist/version
###################
# BUILD FOR LOCAL DEVELOPMENT
###################
FROM golang:1.21-alpine3.18 As build
# Root working dir
WORKDIR /app-src
# Go Caching
#ENV CGO_ENABLED=1
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache
# Copy Go modules and dependencies to image
COPY ./vrfs-fs ./vrfs-fs
COPY ./libs ./libs
COPY ./config ./config
# Switch to the VRFS module dir
WORKDIR /app-src/vrfs-fs
# Download Go modules and dependencies
RUN --mount=type=cache,target=/gomod-cache \
go mod download
# Report the generated version
COPY --chown=gorker:gorker --from=base /app-src/dist ./dist
# Run the build command which creates the production bundle
RUN --mount=type=cache,target=/go-cache --mount=type=cache,target=/gomod-cache \
go build -o dist/vrfs-fs ./main.go
###################
# PRODUCTION
###################
FROM gcr.io/distroless/static-debian12 As production
WORKDIR /app
# Copy the bundled code from the build stage to the production image
COPY --chown=nonroot:nonroot --from=build /app-src/vrfs-fs/dist ./
COPY --chown=nonroot:nonroot --from=build /app-src/config/vrfs-fs.yml ./config/vrfs-fs.yml
# Ensure the process will run under the user 'gorker'
# USER nonroot
# The port to expose
EXPOSE 9000
ENTRYPOINT ["./vrfs-fs"]