speed up docker build: bun everywhere, buildx layer cache, tighter dockerignore
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Root cause of 6+ min builds: Dockerfile stage 1 ran 'npm install' with no package-lock.json, so every build re-resolved + re-fetched the full npm tree from scratch on a fresh runner. - Dockerfile: replace node:22-slim+npm stage with oven/bun:1-slim; both stages now 'bun install --frozen-lockfile' against the tracked bun.lock; --mount=type=cache for the bun install cache - workflow: switch to docker/build-push-action with registry buildcache (cache-from + cache-to) so layers persist across runs - dockerignore: add .worktrees, docs, tests, tsbuildinfo so the build context ships less
This commit is contained in:
@@ -4,6 +4,12 @@ data/
|
|||||||
.git/
|
.git/
|
||||||
.gitea/
|
.gitea/
|
||||||
.claude/
|
.claude/
|
||||||
|
.worktrees/
|
||||||
|
docs/
|
||||||
.env*
|
.env*
|
||||||
*.md
|
*.md
|
||||||
*.xml
|
*.xml
|
||||||
|
*.tsbuildinfo
|
||||||
|
**/__tests__/
|
||||||
|
**/*.test.ts
|
||||||
|
**/*.test.tsx
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Gitea Container Registry
|
- name: Log in to Gitea Container Registry
|
||||||
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.actor }}" --password-stdin
|
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.actor }}" --password-stdin
|
||||||
|
|
||||||
@@ -21,14 +24,13 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
|
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Build image
|
- name: Build and push
|
||||||
run: |
|
uses: docker/build-push-action@v6
|
||||||
docker build \
|
with:
|
||||||
-t "$REGISTRY/$IMAGE:latest" \
|
context: .
|
||||||
-t "$REGISTRY/$IMAGE:${{ steps.meta.outputs.version }}" \
|
push: true
|
||||||
.
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
|
||||||
- name: Push image
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.meta.outputs.version }}
|
||||||
run: |
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE }}:buildcache
|
||||||
docker push "$REGISTRY/$IMAGE:latest"
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE }}:buildcache,mode=max
|
||||||
docker push "$REGISTRY/$IMAGE:${{ steps.meta.outputs.version }}"
|
|
||||||
|
|||||||
23
Dockerfile
23
Dockerfile
@@ -1,15 +1,20 @@
|
|||||||
FROM node:22-slim AS build
|
# syntax=docker/dockerfile:1.7
|
||||||
WORKDIR /app
|
|
||||||
COPY package.json ./
|
|
||||||
RUN npm install
|
|
||||||
COPY . .
|
|
||||||
RUN npx vite build
|
|
||||||
|
|
||||||
FROM oven/bun:1
|
FROM oven/bun:1-slim AS build
|
||||||
|
WORKDIR /app
|
||||||
|
# Install deps first for layer caching — only rebuilds when the lockfile changes.
|
||||||
|
COPY package.json bun.lock ./
|
||||||
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
||||||
|
bun install --frozen-lockfile
|
||||||
|
COPY . .
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
FROM oven/bun:1-slim
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json bun.lock* ./
|
COPY package.json bun.lock ./
|
||||||
RUN bun install --frozen-lockfile --production
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
||||||
|
bun install --frozen-lockfile --production
|
||||||
COPY --from=build /app/dist/ ./dist/
|
COPY --from=build /app/dist/ ./dist/
|
||||||
COPY --from=build /app/server/ ./server/
|
COPY --from=build /app/server/ ./server/
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|||||||
Reference in New Issue
Block a user