This repository was archived by the owner on Dec 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.service
More file actions
89 lines (60 loc) · 1.73 KB
/
Dockerfile.service
File metadata and controls
89 lines (60 loc) · 1.73 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# you probably don't want to build this Dockerfile directly,
# use `make <svc>` instead
#
# pull deps
#
FROM debian:12.8 AS deps
# renovate: datasource=github-releases depName=golang-migrate/migrate
ARG MIGRATE_VERSION=4.18.1
RUN apt update && \
apt install -y wget
# get migrate
RUN wget -q https://github.com/golang-migrate/migrate/releases/download/v$MIGRATE_VERSION/migrate.linux-amd64.tar.gz -O - | tar -xzvf - migrate
# builder builds a go service
# the build args SERVICE and VERSION must be set!
FROM golang:1.23-bookworm AS builder
#
# build spice helper (for migrations)
#
WORKDIR /build/spice
COPY go.* ./
COPY libs libs
COPY spicedb/migrations spicedb/migrations
RUN go mod download
COPY cmd/spice cmd/spice
RUN CGO_ENABLED=0 GOOS=linux go build -a -o spice cmd/spice/spice.go
#
# build service
#
ARG SERVICE
ARG VERSION
WORKDIR /build/app
COPY libs /libs
COPY gen /gen
COPY services/$SERVICE/go.* ./
RUN go mod download
COPY services/$SERVICE /build/app
# create migrations, if it does not exist already
# allows us to copy it into the production image w/o error
RUN mkdir -p migrations
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X main.Version=${VERSION}" -a -o app .
FROM alpine:3.21.0 AS production
RUN apk update && apk add postgresql-client --no-cache
WORKDIR /app
# copy deps
COPY --from=deps /migrate /usr/bin/migrate
COPY --from=builder /build/spice/spice /usr/bin/spice
COPY docker-run-migrations.sh ./run-migrations.sh
# copy app
COPY --from=builder /build/app/app .
COPY --from=builder /build/app/migrations ./migrations
COPY spicedb ./spicedb
# fix permissions
RUN chmod +x run-migrations.sh
RUN chmod +x app
ENV PORT=80
ENV MODE=production
ENV LOG_LEVEL=info
ENV POSTGRES_PORT=5432
EXPOSE 80
CMD ["./app"]