- Add multi-stage Dockerfile (alpine, non-root, builds server+admin binaries) - Add .dockerignore - Add GitHub Actions workflow (also read by Gitea Actions) building and pushing linux/amd64 + linux/arm64 images to git.arnef.de/arnef/ebooks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
42 lines
1017 B
Docker
42 lines
1017 B
Docker
# syntax=docker/dockerfile:1
|
|
|
|
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
|
|
WORKDIR /src
|
|
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
|
|
RUN apk add --no-cache git
|
|
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
COPY . .
|
|
|
|
# views/pages_templ.go ist bereits generiert und im Repo eingecheckt,
|
|
# daher kein "templ generate" im Build notwendig.
|
|
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
|
go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server
|
|
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
|
go build -trimpath -ldflags="-s -w" -o /out/admin ./cmd/admin
|
|
|
|
FROM alpine:3.20
|
|
RUN apk add --no-cache ca-certificates tzdata && \
|
|
addgroup -S ebooks && adduser -S ebooks -G ebooks
|
|
|
|
WORKDIR /app
|
|
COPY --from=build /out/server /app/server
|
|
COPY --from=build /out/admin /app/admin
|
|
COPY static ./static
|
|
|
|
ENV ADDR=:8080
|
|
ENV BOOKS_DIR=/data/books
|
|
ENV USERS_DB=/data/users.db
|
|
|
|
RUN mkdir -p /data/books && chown -R ebooks:ebooks /data /app
|
|
VOLUME ["/data"]
|
|
USER ebooks
|
|
|
|
EXPOSE 8080
|
|
ENTRYPOINT ["/app/server"]
|