diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml index 2d39daf..1b647b9 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -11,6 +11,9 @@ on: jobs: build: runs-on: ubuntu-latest + env: + # Set to 'true' if you need to compile native modules from source (e.g. better-sqlite3 on arm) + BUILD_FROM_SOURCE: 'false' steps: - name: Checkout uses: actions/checkout@v4 @@ -45,6 +48,10 @@ jobs: uses: docker/build-push-action@v5 with: context: . + # Build multi-arch images for amd64 and arm64 + platforms: linux/amd64,linux/arm64 push: true + build-args: | + BUILD_FROM_SOURCE=${{ env.BUILD_FROM_SOURCE }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 3738a68..0d0818e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,9 @@ FROM node:20-alpine AS builder WORKDIR /app +# Install build tools needed for native modules and frontend build +RUN apk add --no-cache python3 build-base sqlite-dev + COPY package.json package-lock.json* ./ RUN npm ci @@ -12,8 +15,12 @@ RUN npm run build # ── Stage 2: Production image ─────────────────────────────────────────────── FROM node:20-alpine -# better-sqlite3 needs build tools for native compilation -RUN apk add --no-cache python3 make g++ +# Allow forcing build from source (useful when prebuilt binaries are not available) +ARG BUILD_FROM_SOURCE=false +ENV npm_config_build_from_source=${BUILD_FROM_SOURCE} + +# Install build tools and sqlite dev headers for compiling native modules +RUN apk add --no-cache python3 build-base sqlite-dev WORKDIR /app @@ -21,7 +28,7 @@ COPY package.json package-lock.json* ./ RUN npm ci --omit=dev && npm cache clean --force # Remove build tools after install to keep image smaller -RUN apk del python3 make g++ +RUN apk del build-base python3 # Copy server code COPY server/ ./server/