2023-05-13 18:38:57 +00:00
|
|
|
|
|
|
|
# Build Nuxt
|
|
|
|
FROM node:17-alpine as frontend-builder
|
|
|
|
WORKDIR /app
|
|
|
|
RUN npm install -g pnpm
|
|
|
|
COPY frontend/package.json frontend/pnpm-lock.yaml ./
|
|
|
|
RUN pnpm install --frozen-lockfile --shamefully-hoist
|
|
|
|
COPY frontend .
|
|
|
|
RUN pnpm build
|
|
|
|
|
|
|
|
# Build API
|
|
|
|
FROM golang:alpine AS builder
|
|
|
|
ARG BUILD_TIME
|
|
|
|
ARG COMMIT
|
|
|
|
ARG VERSION
|
2024-05-07 18:52:22 +00:00
|
|
|
ARG BUSYBOX_VERSION=1.31.0-i686-uclibc
|
2023-05-13 18:38:57 +00:00
|
|
|
RUN apk update && \
|
|
|
|
apk upgrade && \
|
|
|
|
apk add --update git build-base gcc g++
|
|
|
|
|
|
|
|
WORKDIR /go/src/app
|
|
|
|
COPY ./backend .
|
|
|
|
RUN go get -d -v ./...
|
|
|
|
RUN rm -rf ./app/api/public
|
|
|
|
COPY --from=frontend-builder /app/.output/public ./app/api/static/public
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build \
|
|
|
|
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
|
|
|
|
-o /go/bin/api \
|
|
|
|
-v ./app/api/*.go && \
|
|
|
|
chmod +x /go/bin/api && \
|
|
|
|
# create a directory so that we can copy it in the next stage
|
|
|
|
mkdir /data
|
|
|
|
|
2024-05-07 18:52:22 +00:00
|
|
|
# Downloading Wget
|
|
|
|
ADD https://busybox.net/downloads/binaries/$BUSYBOX_VERSION/busybox_WGET /wget
|
|
|
|
RUN chmod a+x /wget
|
|
|
|
|
|
|
|
FROM gcr.io/distroless/java
|
|
|
|
|
|
|
|
COPY --from=builder /wget /usr/bin/wget
|
|
|
|
|
2023-05-13 18:38:57 +00:00
|
|
|
# Production Stage
|
|
|
|
FROM gcr.io/distroless/static
|
|
|
|
|
|
|
|
ENV HBOX_MODE=production
|
|
|
|
ENV HBOX_STORAGE_DATA=/data/
|
|
|
|
ENV HBOX_STORAGE_SQLITE_URL=/data/homebox.db?_fk=1
|
|
|
|
|
|
|
|
# Copy the binary and the (empty) /data dir and
|
|
|
|
# change the ownership to the low-privileged user
|
|
|
|
COPY --from=builder --chown=nonroot /go/bin/api /app
|
|
|
|
COPY --from=builder --chown=nonroot /data /data
|
2024-05-07 18:52:22 +00:00
|
|
|
COPY --from=builder --chown=nonroot /wget /usr/bin/wget
|
2023-05-13 18:38:57 +00:00
|
|
|
|
|
|
|
LABEL Name=homebox Version=0.0.1
|
|
|
|
LABEL org.opencontainers.image.source="https://github.com/hay-kot/homebox"
|
|
|
|
EXPOSE 7745
|
2024-05-07 18:52:22 +00:00
|
|
|
HEALTHCHECK --interval=30s \
|
|
|
|
--timeout=5s \
|
|
|
|
--start-period=5s \
|
|
|
|
--retries=3 \
|
2024-06-02 20:09:35 +00:00
|
|
|
CMD [ "/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:7745/api/v1/status" ]
|
2023-05-13 18:38:57 +00:00
|
|
|
VOLUME [ "/data" ]
|
|
|
|
|
|
|
|
# Drop root and run as low-privileged user
|
|
|
|
USER nonroot
|
|
|
|
ENTRYPOINT [ "/app" ]
|
|
|
|
CMD [ "/data/config.yml" ]
|