-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
78 lines (60 loc) · 2.17 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
74
75
76
77
78
# Use the official Bun image
# See all versions at https://hub.docker.com/r/oven/bun/tags
# Build UI
FROM oven/bun:1 AS ui-base
WORKDIR /usr/src/app
# Install dependencies into temp directory
# This will cache them and speed up future builds
COPY web/package.json web/bun.lockb /temp/
RUN cd /temp && bun install --frozen-lockfile && \
mkdir -p /usr/src/app/node_modules && \
cp -r /temp/node_modules /usr/src/app/ && \
rm -rf /temp
# Then copy all (non-ignored) project files into the image
COPY web .
# Run tests and build
ENV NODE_ENV=production
RUN bun test && bun run build
# Buld docs using Vitepress
FROM oven/bun:1 AS docs-base
WORKDIR /usr/src/app
RUN apt update && apt install -y git
# Install dependencies into temp directory
# This will cache them and speed up future builds
COPY docs/package.json docs/bun.lockb /temp/
RUN cd /temp && bun install --frozen-lockfile && \
mkdir -p /usr/src/app/node_modules && \
cp -r /temp/node_modules /usr/src/app/ && \
rm -rf /temp
# Then copy all (non-ignored) project files into the image
COPY docs .
# Run tests and build
ENV NODE_ENV=production
RUN bun run docs:build
# Build Go binary
FROM golang:1.23-alpine AS build
WORKDIR /go/src/app
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest && \
go install github.com/swaggo/swag/cmd/swag@latest && \
go install github.com/kevinburke/go-bindata/v4/...@latest
COPY go.mod go.sum ./
RUN go mod download
ENV CGO_ENABLED=0 GOOS=linux
COPY . .
COPY --from=ui-base /usr/src/app/dist web/dist
COPY --from=docs-base /usr/src/app/.vitepress/dist docs/.vitepress/dist
RUN go generate ./... && \
go-bindata -prefix "database/migrations/" -pkg migrations -o database/bindata.go database/migrations/ && \
sqlc generate && \
swag init -g internal/port/httpserver/router.go -o docs/swagger && \
go build -ldflags="-s -w" -o /go/bin/app main.go
# Final stage
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /service
COPY --from=build /go/bin/app .
# Use non-root user for better security
USER nonroot:nonroot
# Expose the port the app runs on
# Expose the port specified by the PORT environment variable, defaulting to 1323
EXPOSE ${PORT:-1323}
CMD ["./app"]