-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
56 lines (41 loc) · 1.96 KB
/
Dockerfile
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
FROM --platform=$BUILDPLATFORM golang:1-bookworm@sha256:18d2f940cc20497f85466fdbe6c3d7a52ed2db1d5a1a49a4508ffeee2dff1463 AS builder
ARG BUILDARCH TARGETOS TARGETARCH
# Install GoReleaser
RUN wget --no-verbose "https://github.com/goreleaser/goreleaser/releases/download/v1.26.2/goreleaser_1.26.2_$BUILDARCH.deb"
RUN dpkg -i "goreleaser_1.26.2_$BUILDARCH.deb"
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies.
# This allows the container build to reuse cached dependencies.
# Expecting to copy go.mod and if present go.sum.
COPY go.* ./
RUN go mod download
# Copy local code to the container image.
COPY . ./
# RUN git lfs pull && ls -alh publications
# Run goreleaser
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --single-target --id rwp --skip=validate --snapshot --output ./rwp
# Run tests
# FROM builder AS tester
# RUN go test ./...
# Produces very small images
FROM gcr.io/distroless/static-debian12 AS packager
# Extra metadata
LABEL org.opencontainers.image.source="https://github.com/readium/go-toolkit"
# Add Fedora's mimetypes (pretty up-to-date and expansive)
# since the distroless container doesn't have any. Go uses
# this file as part of its mime package, and readium/go-toolkit
# has a mediatype package that falls back to Go's mime
# package to discover a file's mimetype when all else fails.
ADD https://pagure.io/mailcap/raw/master/f/mime.types /etc/
# Add two demo EPUBs to the container by default
ADD --chown=nonroot:nonroot https://readium-playground-files.storage.googleapis.com/demo/moby-dick.epub /srv/publications/
ADD --chown=nonroot:nonroot https://readium-playground-files.storage.googleapis.com/demo/BellaOriginal3.epub /srv/publications/
# Copy built Go binary
COPY --from=builder "/app/rwp" /opt/
EXPOSE 15080
USER nonroot:nonroot
ENTRYPOINT ["/opt/rwp"]
CMD ["serve", "/srv/publications", "--address", "0.0.0.0"]