A continuation of HomeBox the inventory and organization system built for the Home User
Splitting dependencies into separate docker layers (better caching) (#142)
Matt Kilgore3bf1e50620d4
diff --git a/.github/workflows/docker-publish-rootless.yaml b/.github/workflows/docker-publish-rootless.yamlindex 8b330cd6..d4726a7e 100644--- a/.github/workflows/docker-publish-rootless.yaml+++ b/.github/workflows/docker-publish-rootless.yaml@@ -92,8 +92,8 @@ jobs:tags: ${{ steps.metadata.outputs.tags }}labels: ${{ steps.metadata.outputs.labels }}platforms: linux/amd64,linux/arm64,linux/arm/v7-# cache-from: type=gha-# cache-to: type=gha,mode=max+ cache-from: type=gha+ cache-to: type=gha,mode=maxbuild-args: |VERSION=${{ github.ref_name }}COMMIT=${{ github.sha }}diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yamlindex 8b63be01..4e4dbe78 100644--- a/.github/workflows/docker-publish.yaml+++ b/.github/workflows/docker-publish.yaml@@ -89,8 +89,8 @@ jobs:tags: ${{ steps.meta.outputs.tags }}labels: ${{ steps.meta.outputs.labels }}platforms: linux/amd64,linux/arm64,linux/arm/v7-# cache-from: type=gha-# cache-to: type=gha,mode=max+ cache-from: type=gha+ cache-to: type=gha,mode=maxbuild-args: |VERSION=${{ github.ref_name }}COMMIT=${{ github.sha }}diff --git a/Dockerfile b/Dockerfileindex a32d56a2..85097bd7 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,13 +1,23 @@+# Node dependencies+FROM node:18-alpine AS frontend-dependencies+WORKDIR /app+RUN npm install -g pnpm+COPY frontend/package.json frontend/pnpm-lock.yaml ./+RUN pnpm install --frozen-lockfile --shamefully-hoist# Build NuxtFROM node:18-alpine AS frontend-builderWORKDIR /appRUN npm install -g pnpm-COPY frontend/package.json frontend/pnpm-lock.yaml ./-RUN pnpm install --frozen-lockfile --shamefully-hoistCOPY frontend .+COPY --from=frontend-dependencies /app/node_modules ./node_modulesRUN pnpm build+FROM golang:alpine AS builder-dependencies+WORKDIR /go/src/app+COPY ./backend .+RUN go mod download+# Build APIFROM golang:alpine AS builderARG BUILD_TIME@@ -19,10 +29,11 @@ RUN apk update && \WORKDIR /go/src/appCOPY ./backend .-RUN go get -d -v ./...RUN rm -rf ./app/api/publicCOPY --from=frontend-builder /app/.output/public ./app/api/static/public-RUN CGO_ENABLED=0 GOOS=linux go build \+COPY --from=builder-dependencies /go/pkg/mod /go/pkg/mod+RUN --mount=type=cache,target=/root/.cache/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" \-o /go/bin/api \-v ./app/api/*.godiff --git a/Dockerfile.rootless b/Dockerfile.rootlessindex aa7e6186..3a0799d8 100644--- a/Dockerfile.rootless+++ b/Dockerfile.rootless@@ -1,35 +1,42 @@+# Node dependencies+FROM node:18-alpine AS frontend-dependencies+WORKDIR /app+RUN npm install -g pnpm+COPY frontend/package.json frontend/pnpm-lock.yaml ./+RUN pnpm install --frozen-lockfile --shamefully-hoist# Build NuxtFROM node:18-alpine AS frontend-builderWORKDIR /appRUN npm install -g pnpm-COPY frontend/package.json frontend/pnpm-lock.yaml ./-RUN pnpm install --frozen-lockfile --shamefully-hoistCOPY frontend .+COPY --from=frontend-dependencies /app/node_modules ./node_modulesRUN pnpm build+FROM golang:alpine AS builder-dependencies+WORKDIR /go/src/app+COPY ./backend .+RUN go mod download+# Build APIFROM golang:alpine AS builderARG BUILD_TIMEARG COMMITARG VERSION-ARG BUSYBOX_VERSION=1.36.1-r31RUN apk update && \apk upgrade && \apk add --update git build-base gcc g++WORKDIR /go/src/appCOPY ./backend .-RUN go get -d -v ./...RUN rm -rf ./app/api/publicCOPY --from=frontend-builder /app/.output/public ./app/api/static/public-RUN CGO_ENABLED=0 GOOS=linux go build \+COPY --from=builder-dependencies /go/pkg/mod /go/pkg/mod+RUN --mount=type=cache,target=/root/.cache/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" \-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+ -v ./app/api/*.goFROM gcr.io/distroless/java:latest