-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.standalone
103 lines (75 loc) · 2.48 KB
/
Dockerfile.standalone
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# you probably don't want to use this Dockerfile directly,
# use `make <svc>` instead
# 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
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 debian:12.6 AS deps
# renovate: datasource=github-releases depName=DarthSim/hivemind
ARG HIVEMIND_VERSION=1.1.0
# renovate: datasource=github-releases depName=golang-migrate/migrate
ARG MIGRATE_VERSION=4.18.1
# renovate: datasource=github-releases depName=dapr/dapr
ARG DAPR_VERSION=1.14.4
RUN apt update && \
apt install -y wget
# get hivemind
RUN wget -q -O hivemind.gz https://github.com/DarthSim/hivemind/releases/download/v$HIVEMIND_VERSION/hivemind-v$HIVEMIND_VERSION-linux-amd64.gz && \
gunzip hivemind.gz && \
chmod +x hivemind
# 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
# get daprd
RUN wget -q https://github.com/dapr/dapr/releases/download/v$DAPR_VERSION/daprd_linux_amd64.tar.gz -O - | tar -xzvf - daprd
FROM alpine:3.20.2 AS production
RUN apk update && apk add postgresql-client --no-cache
ARG SERVICE
# APP_PROTOCOL can be grpc or http
ARG APP_PROTOCOL=grpc
WORKDIR /app
# copy deps
COPY --from=deps /hivemind /usr/bin/hivemind
COPY --from=deps /migrate /usr/bin/migrate
COPY --from=deps /daprd /usr/bin/daprd
COPY --from=builder /build/spice/spice /usr/bin/spice
COPY dapr dapr
COPY Procfile.standalone Procfile
# copy app
COPY --from=builder /build/app/app .
COPY --from=builder /build/app/migrations ./migrations
COPY spicedb ./spicedb
COPY docker-run-migrations.sh ./run-migrations.sh
# fix permissions
RUN chmod +x run-migrations.sh
ENV DAPR_APP_ID=$SERVICE
# DAPR_HTTP_READ_BUFFER_SIZE: default 4KB
ENV DAPR_HTTP_READ_BUFFER_SIZE=8
ENV DAPR_LOG_LEVEL=info
ENV APP_PROTOCOL=$APP_PROTOCOL
ENV ADDR=":80"
ENV MODE=development
ENV LOG_LEVEL=debug
CMD ["hivemind"]