mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
Splitting dependencies into separate docker layers (better caching) (#142)
* Initial test with NodeJS * Fix screw up * Try again * Try Golang caching * Test with some more cache
This commit is contained in:
@@ -92,8 +92,8 @@ jobs:
|
|||||||
tags: ${{ steps.metadata.outputs.tags }}
|
tags: ${{ steps.metadata.outputs.tags }}
|
||||||
labels: ${{ steps.metadata.outputs.labels }}
|
labels: ${{ steps.metadata.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
# cache-from: type=gha
|
cache-from: type=gha
|
||||||
# cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ github.ref_name }}
|
VERSION=${{ github.ref_name }}
|
||||||
COMMIT=${{ github.sha }}
|
COMMIT=${{ github.sha }}
|
||||||
|
|||||||
4
.github/workflows/docker-publish.yaml
vendored
4
.github/workflows/docker-publish.yaml
vendored
@@ -89,8 +89,8 @@ jobs:
|
|||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
# cache-from: type=gha
|
cache-from: type=gha
|
||||||
# cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ github.ref_name }}
|
VERSION=${{ github.ref_name }}
|
||||||
COMMIT=${{ github.sha }}
|
COMMIT=${{ github.sha }}
|
||||||
|
|||||||
19
Dockerfile
19
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
|
# 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
|
RUN npm install -g pnpm
|
||||||
COPY frontend/package.json frontend/pnpm-lock.yaml ./
|
|
||||||
RUN pnpm install --frozen-lockfile --shamefully-hoist
|
|
||||||
COPY frontend .
|
COPY frontend .
|
||||||
|
COPY --from=frontend-dependencies /app/node_modules ./node_modules
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
|
FROM golang:alpine AS builder-dependencies
|
||||||
|
WORKDIR /go/src/app
|
||||||
|
COPY ./backend .
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
# Build API
|
# Build API
|
||||||
FROM golang:alpine AS builder
|
FROM golang:alpine AS builder
|
||||||
ARG BUILD_TIME
|
ARG BUILD_TIME
|
||||||
@@ -19,10 +29,11 @@ RUN apk update && \
|
|||||||
|
|
||||||
WORKDIR /go/src/app
|
WORKDIR /go/src/app
|
||||||
COPY ./backend .
|
COPY ./backend .
|
||||||
RUN go get -d -v ./...
|
|
||||||
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
|
||||||
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" \
|
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
|
||||||
-o /go/bin/api \
|
-o /go/bin/api \
|
||||||
-v ./app/api/*.go
|
-v ./app/api/*.go
|
||||||
|
|||||||
@@ -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
|
# 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
|
RUN npm install -g pnpm
|
||||||
COPY frontend/package.json frontend/pnpm-lock.yaml ./
|
|
||||||
RUN pnpm install --frozen-lockfile --shamefully-hoist
|
|
||||||
COPY frontend .
|
COPY frontend .
|
||||||
|
COPY --from=frontend-dependencies /app/node_modules ./node_modules
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
|
FROM golang:alpine AS builder-dependencies
|
||||||
|
WORKDIR /go/src/app
|
||||||
|
COPY ./backend .
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
# Build API
|
# Build API
|
||||||
FROM golang:alpine AS builder
|
FROM golang:alpine AS builder
|
||||||
ARG BUILD_TIME
|
ARG BUILD_TIME
|
||||||
ARG COMMIT
|
ARG COMMIT
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ARG BUSYBOX_VERSION=1.36.1-r31
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk upgrade && \
|
apk upgrade && \
|
||||||
apk add --update 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 go get -d -v ./...
|
|
||||||
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
|
||||||
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" \
|
-ldflags "-s -w -X main.commit=$COMMIT -X main.buildTime=$BUILD_TIME -X main.version=$VERSION" \
|
||||||
-o /go/bin/api \
|
-o /go/bin/api \
|
||||||
-v ./app/api/*.go && \
|
-v ./app/api/*.go
|
||||||
chmod +x /go/bin/api && \
|
|
||||||
# create a directory so that we can copy it in the next stage
|
|
||||||
mkdir /data
|
|
||||||
|
|
||||||
FROM gcr.io/distroless/java:latest
|
FROM gcr.io/distroless/java:latest
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user