forked from ras0q/go-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (41 loc) · 1.33 KB
/
Dockerfile
File metadata and controls
55 lines (41 loc) · 1.33 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
# syntax=docker/dockerfile:1
FROM node:24 AS frontend-builder
WORKDIR /app
RUN \
--mount=type=bind,source=frontend/app-ui/package.json,target=package.json \
--mount=type=bind,source=frontend/app-ui/package-lock.json,target=package-lock.json \
npm ci
COPY ./frontend/app-ui ./
RUN npm run build
RUN ls -al
FROM golang:1.25 AS builder
WORKDIR /app
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/go/pkg/mod
RUN \
--mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download
# Install swag for Swagger documentation generation
RUN \
--mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
go install github.com/swaggo/swag/cmd/swag@latest
COPY --from=frontend-builder /app/dist /tmp/dist
RUN \
--mount=type=cache,target=${GOCACHE} \
--mount=type=cache,target=${GOMODCACHE} \
--mount=type=bind,target=.,readwrite \
cp -r /tmp/dist /app/frontend/app-ui/dist \
&& /go/bin/swag init \
&& go build -o /usr/bin/server ./main.go
# use `debug-nonroot` for debug shell access
FROM gcr.io/distroless/static-debian11:nonroot
WORKDIR /app
COPY --from=builder /usr/bin/server /usr/bin/server
CMD ["/usr/bin/server"]