mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
Update Dockerfile.rootless
Update with optimisation attempts
This commit is contained in:
@@ -7,15 +7,15 @@ RUN pnpm install --frozen-lockfile --shamefully-hoist
|
|||||||
|
|
||||||
# Build Nuxt
|
# Build Nuxt
|
||||||
FROM node:18-alpine AS frontend-builder
|
FROM node:18-alpine AS frontend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN npm install -g pnpm
|
COPY frontend ./
|
||||||
COPY frontend .
|
|
||||||
COPY --from=frontend-dependencies /app/node_modules ./node_modules
|
COPY --from=frontend-dependencies /app/node_modules ./node_modules
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
|
# Build Go dependencies
|
||||||
FROM golang:alpine AS builder-dependencies
|
FROM golang:alpine AS builder-dependencies
|
||||||
WORKDIR /go/src/app
|
WORKDIR /go/src/app
|
||||||
COPY ./backend .
|
COPY ./backend/go.mod ./backend/go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
# Build API
|
# Build API
|
||||||
@@ -23,48 +23,51 @@ FROM golang:alpine AS builder
|
|||||||
ARG BUILD_TIME
|
ARG BUILD_TIME
|
||||||
ARG COMMIT
|
ARG COMMIT
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
RUN apk update && \
|
|
||||||
apk upgrade && \
|
RUN apk update && apk upgrade && apk add --no-cache git build-base gcc g++
|
||||||
apk add --update git build-base gcc g++
|
|
||||||
|
|
||||||
WORKDIR /go/src/app
|
WORKDIR /go/src/app
|
||||||
COPY ./backend .
|
COPY ./backend .
|
||||||
RUN rm -rf ./app/api/public
|
RUN rm -rf ./app/api/public
|
||||||
COPY --from=frontend-builder /app/.output/public ./app/api/static/public
|
COPY --from=frontend-builder /app/.output/public ./app/api/static/public
|
||||||
COPY --from=builder-dependencies /go/pkg/mod /go/pkg/mod
|
COPY --from=builder-dependencies /go/pkg/mod /go/pkg/mod
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
||||||
|
# Use cache for Go build
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
CGO_ENABLED=0 GOOS=linux go build \
|
CGO_ENABLED=0 GOOS=linux go build \
|
||||||
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
|
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
|
||||||
-o /go/bin/api \
|
-o /go/bin/api ./app/api/*.go
|
||||||
-v ./app/api/*.go
|
|
||||||
|
|
||||||
FROM gcr.io/distroless/java:latest
|
# Production stage with distroless
|
||||||
|
|
||||||
# Production Stage
|
|
||||||
FROM gcr.io/distroless/static:latest
|
FROM gcr.io/distroless/static:latest
|
||||||
|
|
||||||
ENV HBOX_MODE=production
|
ENV HBOX_MODE=production
|
||||||
ENV HBOX_STORAGE_DATA=/data/
|
ENV HBOX_STORAGE_DATA=/data/
|
||||||
ENV HBOX_STORAGE_SQLITE_URL=/data/homebox.db?_fk=1
|
ENV HBOX_STORAGE_SQLITE_URL=/data/homebox.db?_fk=1
|
||||||
|
|
||||||
# Copy the binary and the (empty) /data dir and
|
# Copy the binary and data directory, change ownership
|
||||||
# change the ownership to the low-privileged user
|
|
||||||
COPY --from=builder --chown=nonroot /go/bin/api /app
|
COPY --from=builder --chown=nonroot /go/bin/api /app
|
||||||
COPY --from=builder --chown=nonroot /data /data
|
COPY --from=builder --chown=nonroot /data /data
|
||||||
|
|
||||||
RUN apk add --no-cache wget
|
# Add wget to the image
|
||||||
|
# Note: If using distroless, this may not be applicable
|
||||||
|
# as distroless images do not include package managers.
|
||||||
|
# This line may be omitted if you're relying on another way to handle healthchecks.
|
||||||
|
COPY --from=alpine:latest /bin/wget /usr/bin/wget
|
||||||
|
|
||||||
LABEL Name=homebox Version=0.0.1
|
LABEL Name=homebox Version=0.0.1
|
||||||
LABEL org.opencontainers.image.source="https://github.com/sysadminsmedia/homebox"
|
LABEL org.opencontainers.image.source="https://github.com/sysadminsmedia/homebox"
|
||||||
EXPOSE 7745
|
EXPOSE 7745
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s \
|
HEALTHCHECK --interval=30s \
|
||||||
--timeout=5s \
|
--timeout=5s \
|
||||||
--start-period=5s \
|
--start-period=5s \
|
||||||
--retries=3 \
|
--retries=3 \
|
||||||
CMD [ "/usr/bin/wget", "--no-verbose", "--tries=1", "-O -", "http://localhost:7745/api/v1/status" ]
|
CMD ["/usr/bin/wget", "--no-verbose", "--tries=1", "-O", "-", "http://localhost:7745/api/v1/status"]
|
||||||
VOLUME [ "/data" ]
|
|
||||||
|
|
||||||
# Drop root and run as low-privileged user
|
VOLUME ["/data"]
|
||||||
|
|
||||||
|
# Drop root and run as a low-privileged user
|
||||||
USER nonroot
|
USER nonroot
|
||||||
ENTRYPOINT [ "/app" ]
|
ENTRYPOINT ["/app"]
|
||||||
CMD [ "/data/config.yml" ]
|
CMD ["/data/config.yml"]
|
||||||
|
|||||||
Reference in New Issue
Block a user