-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (50 loc) · 2.2 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (50 loc) · 2.2 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
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.26.6
ARG ALPINE_VERSION=3.24.1
# What `ziba version` will report. It has to be passed in
ARG VERSION=unknown
# --- Build stage -------------------------------------------------------------
FROM golang:${GO_VERSION}-alpine AS build
ARG VERSION
WORKDIR /src
# Dependencies first, so editing source does not invalidate the module cache.
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# CGO off is what makes the binary static, and static is what lets the runtime
# image stay this small.
RUN CGO_ENABLED=0 go build -trimpath \
-ldflags "-s -w -X main.version=${VERSION}" \
-o /out/ziba ./cmd/ziba
# --- Final image -------------------------------------------------------------
FROM alpine:${ALPINE_VERSION}
ARG GO_VERSION
ARG ALPINE_VERSION
ARG VERSION
# ca-certificates: sources are read over HTTPS and would all fail without it.
# tzdata: the digest is scheduled in local time, and without this the container
# only knows UTC — a digest set for 06:30 would arrive at the wrong hour.
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
COPY --from=build /out/ziba /usr/local/bin/ziba
# log/ takes the model journal when ZIBA_MODEL_JOURNAL is on.
RUN mkdir -p /app/config /app/log \
&& chown nobody /app/config /app/log
VOLUME ["/app/log"]
# Nothing here needs to be root.
USER nobody
EXPOSE 8080
# wget is busybox's, already in the base image. Belongs here rather than in the
# compose file: it is a property of the image, and true however it is run.
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD wget -qO- http://127.0.0.1:8080/ >/dev/null || exit 1
ENTRYPOINT ["ziba"]
CMD ["serve"]
# The release workflow passes its own OCI labels and those win over these. These
# are for an image built by hand.
LABEL org.opencontainers.image.source="https://github.com/emaori/ziba" \
org.opencontainers.image.description="Self-hosted personal content aggregator: collects articles, curates them with AI, serves a daily magazine" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.version="${VERSION}" \
io.ziba.go.version="${GO_VERSION}" \
io.ziba.alpine.version="${ALPINE_VERSION}"