fix: trying to solve the arm build process issue. (#365)
Some checks are pending
Docker publish rootless / build (linux/amd64) (push) Waiting to run
Docker publish rootless / build (linux/arm/v7) (push) Waiting to run
Docker publish rootless / build (linux/arm64) (push) Waiting to run
Docker publish rootless / merge (push) Blocked by required conditions
Docker publish / build (linux/amd64) (push) Waiting to run
Docker publish / build (linux/arm/v7) (push) Waiting to run
Docker publish / build (linux/arm64) (push) Waiting to run
Docker publish / merge (push) Blocked by required conditions
Update Currencies / update-currencies (push) Waiting to run

Co-authored-by: Katos <7927609+katosdev@users.noreply.github.com>
This commit is contained in:
Matt Kilgore
2025-01-04 20:43:27 -05:00
committed by GitHub
parent 850e61cade
commit 96f3543891
7 changed files with 285 additions and 452 deletions

View File

@@ -1,33 +1,35 @@
# Node dependencies
FROM node:18-alpine AS frontend-dependencies
FROM public.ecr.aws/docker/library/node:18-alpine AS frontend-dependencies
WORKDIR /app
RUN npm install -g pnpm
COPY frontend/package.json frontend/pnpm-lock.yaml ./
COPY frontend/package.json frontend/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --shamefully-hoist
# Build Nuxt
FROM node:18-alpine AS frontend-builder
FROM public.ecr.aws/docker/library/node:18-alpine AS frontend-builder
WORKDIR /app
COPY frontend ./
COPY frontend ./
COPY --from=frontend-dependencies /app/node_modules ./node_modules
RUN pnpm build
# Build Go dependencies
FROM golang:alpine AS builder-dependencies
FROM public.ecr.aws/docker/library/golang:alpine AS builder-dependencies
WORKDIR /go/src/app
COPY ./backend/go.mod ./backend/go.sum ./
RUN go mod download
COPY ./backend/go.mod ./backend/go.sum ./
RUN apk update && apk add --no-cache git \
&& go mod download
# Build API
FROM golang:alpine AS builder
FROM public.ecr.aws/docker/library/golang:alpine AS builder
ARG BUILD_TIME
ARG COMMIT
ARG VERSION
RUN apk update && apk upgrade && apk add --no-cache git build-base gcc g++
RUN apk update && apk upgrade && apk add --no-cache git build-base gcc g++ \
&& addgroup -S nonroot && adduser -S nonroot -G nonroot
WORKDIR /go/src/app
COPY ./backend .
COPY ./backend ./
RUN rm -rf ./app/api/public
COPY --from=frontend-builder /app/.output/public ./app/api/static/public
COPY --from=builder-dependencies /go/pkg/mod /go/pkg/mod
@@ -38,22 +40,20 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
-o /go/bin/api ./app/api/*.go
# Change ownership of files to nonroot
RUN chown -R nonroot:nonroot /go/bin/api /go/src/app
# Production stage with distroless
FROM gcr.io/distroless/static:latest
FROM ghcr.io/distroless/static:latest
ENV HBOX_MODE=production
ENV HBOX_STORAGE_DATA=/data/
ENV HBOX_STORAGE_SQLITE_URL=/data/homebox.db?_fk=1&_time_format=sqlite
# Copy the binary and data directory, change ownership
COPY --from=builder --chown=nonroot /go/bin/api /app
COPY --from=builder --chown=nonroot /data /data
# 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
COPY --from=builder /go/bin/api /app
COPY --from=builder /data /data
COPY --from=ghcr.io/rockylinux/alpine:latest /bin/wget /usr/bin/wget
LABEL Name=homebox Version=0.0.1
LABEL org.opencontainers.image.source="https://github.com/sysadminsmedia/homebox"
@@ -67,7 +67,7 @@ HEALTHCHECK --interval=30s \
VOLUME ["/data"]
# Drop root and run as a low-privileged user
# Use nonroot user
USER nonroot
ENTRYPOINT ["/app"]
CMD ["/data/config.yml"]