Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (72 loc) · 3.97 KB
/
Copy pathDockerfile
File metadata and controls
78 lines (72 loc) · 3.97 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
# syntax=docker/dockerfile:1
# Base images are pinned by tag and digest; Dependabot (docker ecosystem) bumps both together.
# --- frontend build -----------------------------------------------------
FROM --platform=$BUILDPLATFORM node:24-alpine@sha256:06d7adf3e0ef61a13f1d28682726366f97a15aa1888c934d3ecec86c33918b53 AS web
WORKDIR /app/web
COPY web/package.json web/package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --ignore-scripts
COPY web/ ./
# The changelog feeds the "What's new" panel; the build id and version are stamped into the bundle.
COPY CHANGELOG.md /app/CHANGELOG.md
ARG VERSION=dev
ARG SOURCE_DATE_EPOCH
RUN npm run build
# --- go build -------------------------------------------------------------
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS build
WORKDIR /app
COPY go.mod go.sum ./
# go.mod's toolchain line names the Go release the binary is built with. The image sets GOTOOLCHAIN=local, so a builder
# that differs would quietly build with its own standard library: refuse it, so a base-image bump and a toolchain bump
# always land together.
RUN want="$(sed -n 's/^toolchain //p' go.mod)" && have="$(go env GOVERSION)" && \
[ -n "$want" ] && [ "$want" = "$have" ] || { echo "builder is $have but go.mod names ${want:-no toolchain}" >&2; exit 1; }
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY cmd/ ./cmd/
COPY internal/ ./internal/
COPY starter/ ./starter/
COPY web/embed.go ./web/embed.go
COPY --from=web /app/web/dist ./web/dist
# VERSION and VCS_REF come from the build (compose build.args, CI). .git is not in the build context
# (.dockerignore), so the image cannot work them out itself; an unset VERSION reports "dev".
ARG VERSION=dev
ARG VCS_REF=unknown
ARG BUILD_DATE=unknown
# Cross-compile on the build platform instead of emulating the target (CGO is off; the SQLite driver is pure Go).
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOFLAGS=-trimpath \
go build -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${VCS_REF} -X main.buildDate=${BUILD_DATE}" -o /kipple ./cmd/kipple
# distroless has no shell to mkdir/chown at runtime, so pre-create /data
# here, owned by the nonroot image's uid/gid (65532), and copy it over.
RUN mkdir -p /data && chown 65532:65532 /data
# --- runtime ----------------------------------------------------------
FROM gcr.io/distroless/static-debian13:nonroot@sha256:aafe993665bf6200db38a02c11a9351e782a84b6a45e7f33b6695638c88e3931
ARG VERSION=dev
ARG VCS_REF=unknown
ARG BUILD_DATE=unknown
LABEL org.opencontainers.image.title="Kipple" \
org.opencontainers.image.description="Self-hosted RSS reader with a Google Reader API" \
org.opencontainers.image.source="https://github.com/WPTK/Kipple" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.url="https://github.com/WPTK/Kipple" \
org.opencontainers.image.documentation="https://github.com/WPTK/Kipple#readme"
# org.opencontainers.image.base.name and .base.digest are deliberately not written here: they would repeat the FROM
# line above and go stale on the first Dependabot bump. The release workflow reads them from that line
# (scripts/release-tags.sh base-image) and stamps them on the official image; a local build simply has no such label.
COPY --from=build /kipple /kipple
COPY --from=build --chown=65532:65532 /data /data
COPY --chown=65532:65532 LICENSE THIRD_PARTY_NOTICES.md /licenses/
EXPOSE 1919
VOLUME /data
# Runs the binary's own probe (no shell or curl in distroless).
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 CMD ["/kipple","healthcheck"]
STOPSIGNAL SIGTERM
ENTRYPOINT ["/kipple"]
CMD ["serve"]