diff --git a/.github/workflows/docker-publish-rootless.yaml b/.github/workflows/docker-publish-rootless.yaml index 8b330cd6c..d4726a7ed 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=max build-args: | VERSION=${{ github.ref_name }} COMMIT=${{ github.sha }} diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml index 8b63be015..4e4dbe784 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=max build-args: | VERSION=${{ github.ref_name }} COMMIT=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index a32d56a21..85097bd76 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 Nuxt FROM node:18-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 . +COPY --from=frontend-dependencies /app/node_modules ./node_modules RUN pnpm build +FROM golang:alpine AS builder-dependencies +WORKDIR /go/src/app +COPY ./backend . +RUN go mod download + # Build API FROM golang:alpine AS builder ARG BUILD_TIME @@ -19,10 +29,11 @@ RUN apk update && \ 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 \ +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 diff --git a/Dockerfile.rootless b/Dockerfile.rootless index aa7e61860..3a0799d8a 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 Nuxt FROM node:18-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 . +COPY --from=frontend-dependencies /app/node_modules ./node_modules RUN pnpm build +FROM golang:alpine AS builder-dependencies +WORKDIR /go/src/app +COPY ./backend . +RUN go mod download + # Build API FROM golang:alpine AS builder ARG BUILD_TIME ARG COMMIT ARG VERSION -ARG BUSYBOX_VERSION=1.36.1-r31 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 \ +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/*.go FROM gcr.io/distroless/java:latest