Update Dockerfile for improved build efficiency and metadata
- Updated the Dockerfile to utilize cache mounts for npm and Go module installations, enhancing build performance. - Changed the base image for the final stage to a more minimal runtime image. - Simplified the application description in the image metadata. - Ensured proper ownership for copied data and cache directories in the final image.
This commit is contained in:
32
Dockerfile
32
Dockerfile
@@ -7,23 +7,27 @@ RUN npm install -g pnpm
|
||||
USER node
|
||||
|
||||
COPY --chown=node:node frontend/package.json frontend/pnpm-lock.yaml ./frontend/
|
||||
WORKDIR /app/frontend
|
||||
RUN pnpm install --frozen-lockfile
|
||||
RUN --mount=type=cache,target=/home/node/.pnpm-store \
|
||||
cd frontend && pnpm install --frozen-lockfile
|
||||
|
||||
COPY --chown=node:node frontend/ ./
|
||||
RUN pnpm run build
|
||||
COPY --chown=node:node frontend/ ./frontend/
|
||||
RUN cd frontend && pnpm run build
|
||||
|
||||
# Stage 2: Build the Go binary with embedded assets
|
||||
FROM cgr.dev/chainguard/go:latest-dev AS go-builder
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
go mod download
|
||||
COPY . .
|
||||
COPY --from=node-builder /app/frontend/build ./frontend/build
|
||||
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o software-station main.go
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w" -o software-station main.go
|
||||
|
||||
RUN mkdir -p /app/data /app/.cache && chown 65532:65532 /app/data /app/.cache
|
||||
|
||||
# Stage 3: Minimal runtime image
|
||||
FROM cgr.dev/chainguard/wolfi-base:latest
|
||||
FROM cgr.dev/chainguard/static:latest
|
||||
WORKDIR /app
|
||||
|
||||
ARG BUILD_DATE
|
||||
@@ -32,7 +36,7 @@ ARG VERSION="0.2.0"
|
||||
|
||||
LABEL org.opencontainers.image.created=$BUILD_DATE \
|
||||
org.opencontainers.image.title="Software Station" \
|
||||
org.opencontainers.image.description="A modern, high-performance software distribution platform for Gitea." \
|
||||
org.opencontainers.image.description="A software distribution platform." \
|
||||
org.opencontainers.image.url="https://quad4.io" \
|
||||
org.opencontainers.image.documentation="https://github.com/Quad4-Software/software-station/blob/main/README.md" \
|
||||
org.opencontainers.image.source="https://github.com/Quad4-Software/software-station" \
|
||||
@@ -41,20 +45,16 @@ LABEL org.opencontainers.image.created=$BUILD_DATE \
|
||||
org.opencontainers.image.vendor="Quad4" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.authors="Quad4" \
|
||||
org.opencontainers.image.base.name="cgr.dev/chainguard/wolfi-base:latest"
|
||||
|
||||
RUN apk add --no-cache ca-certificates
|
||||
org.opencontainers.image.base.name="cgr.dev/chainguard/static:latest"
|
||||
|
||||
COPY --from=go-builder /app/software-station .
|
||||
|
||||
COPY --from=go-builder --chown=65532:65532 /app/data ./data
|
||||
COPY --from=go-builder --chown=65532:65532 /app/.cache ./.cache
|
||||
COPY LICENSE README.md ./
|
||||
COPY legal/ ./legal/
|
||||
|
||||
COPY software.txt /app/data/software.txt
|
||||
COPY ua-blocklist.txt /app/data/ua-blocklist.txt
|
||||
|
||||
RUN mkdir -p /app/data /app/.cache && chown -R 65532:65532 /app/data /app/.cache
|
||||
|
||||
EXPOSE 8080
|
||||
ENV PORT=8080
|
||||
ENV NODE_ENV=production
|
||||
@@ -63,4 +63,4 @@ ENV UA_BLOCKLIST_PATH=/app/data/ua-blocklist.txt
|
||||
|
||||
USER 65532
|
||||
|
||||
CMD ["sh", "-c", "./software-station -c ${CONFIG_PATH} -ua-blocklist ${UA_BLOCKLIST_PATH}"]
|
||||
CMD ["./software-station"]
|
||||
|
||||
Reference in New Issue
Block a user