-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
58 lines (41 loc) · 1.28 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
ARG BUN_IMAGE=oven/bun:1.1.34
ARG BUILDER_IMAGE=golang:1.22-rc-alpine3.18
ARG DISTROLESS_IMAGE=gcr.io/distroless/static
############################
# STEP 1 build the docs page
############################
FROM ${BUN_IMAGE} as docs-builder
WORKDIR /build/docs/
COPY ./docs/ .
RUN bun install --frozen-lockfile
RUN NODE_ENV=production bun run docs:build
############################
# STEP 2 build executable binary
############################
FROM ${BUILDER_IMAGE} as builder
# Ensure ca-certficates are up to date
RUN update-ca-certificates
WORKDIR $GOPATH/src/mypackage/myapp/
# use modules
COPY ./go.mod .
RUN apk add git
ENV GO111MODULE=on
RUN go mod download
RUN go mod verify
COPY . .
# Copy our pre-built document
COPY --from=docs-builder /build/docs/dist ./docs/dist
# Build the static binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' -a \
-o /go/bin/momoka-lite ./cmd/serve.go
############################
# STEP 3 build a small image
############################
# using static nonroot image
# user:group is nobody:nobody, uid:gid = 65534:65534
FROM ${DISTROLESS_IMAGE}
# Copy our static executable
COPY --from=builder /go/bin/momoka-lite /go/bin/momoka-lite
# Run the hello binary.
ENTRYPOINT ["/go/bin/momoka-lite", "serve"]