fix: update npm ci flag from --only=production to --omit=dev and remove nginx build job

This commit is contained in:
czlonkowski
2025-06-13 21:11:43 +02:00
parent d6f38dc1c4
commit b8b5e674dc
3 changed files with 46 additions and 65 deletions

View File

@@ -67,52 +67,10 @@ jobs:
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
build-nginx: # Nginx build commented out until Phase 2
name: Build nginx-enhanced Docker Image # build-nginx:
runs-on: ubuntu-latest # name: Build nginx-enhanced Docker Image
permissions: # runs-on: ubuntu-latest
contents: read # permissions:
packages: write # contents: read
# packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
suffix=-nginx
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=raw,value=nginx,enable={{is_default_branch}}
- name: Build and push nginx Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nginx
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -24,7 +24,7 @@ RUN apk add --no-cache curl su-exec util-linux && \
# Install production dependencies only # Install production dependencies only
COPY package*.json ./ COPY package*.json ./
RUN npm ci --only=production && \ RUN npm ci --omit=dev && \
npm cache clean --force npm cache clean --force
# Copy built application # Copy built application

View File

@@ -1,29 +1,43 @@
# Docker Build Fix # Docker Build Fix
## Issue ## Issues Fixed
The Docker build was failing with the error:
### 1. Database COPY Error
The Docker build was failing with:
``` ```
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref: "/data/nodes.db": not found ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref: "/data/nodes.db": not found
``` ```
## Root Cause ### 2. Missing Dockerfile.nginx
The Dockerfile contained an invalid COPY command that tried to use shell operators: ```
```dockerfile ERROR: failed to solve: failed to read dockerfile: open Dockerfile.nginx: no such file or directory
# This doesn't work in Docker
COPY --from=builder /app/data/nodes.db ./data/nodes.db 2>/dev/null || true
``` ```
### 3. npm ci Production Flag
```
ERROR: failed to solve: process "/bin/sh -c npm ci --only=production && npm cache clean --force" did not complete successfully: exit code: 1
```
## Root Causes & Solutions
### 1. Invalid COPY Syntax
Docker's COPY command doesn't support shell operators like `2>/dev/null || true`. Docker's COPY command doesn't support shell operators like `2>/dev/null || true`.
## Solution **Solution**: Removed the problematic COPY command and created data directory with RUN.
1. Removed the problematic COPY command
2. Created the data directory with RUN instead ### 2. Dockerfile.nginx Not Yet Implemented
3. Removed database pre-initialization from build stage The GitHub Actions workflow referenced `Dockerfile.nginx` which is a Phase 2 feature.
4. Database is now initialized at runtime by the entrypoint script
**Solution**: Commented out the nginx build job until Phase 2 implementation.
### 3. Deprecated npm Flag
The `--only=production` flag is deprecated in newer npm versions.
**Solution**: Changed to `--omit=dev` which is the current syntax.
## Changes Made ## Changes Made
### Dockerfile ### Dockerfile Changes
```diff ```diff
- # Pre-initialize database during build - # Pre-initialize database during build
- RUN mkdir -p /app/data && npm run rebuild || echo "Database will be initialized at runtime" - RUN mkdir -p /app/data && npm run rebuild || echo "Database will be initialized at runtime"
@@ -34,14 +48,23 @@ Docker's COPY command doesn't support shell operators like `2>/dev/null || true`
- COPY --from=builder /app/data/nodes.db ./data/nodes.db 2>/dev/null || true - COPY --from=builder /app/data/nodes.db ./data/nodes.db 2>/dev/null || true
+ # Create data directory + # Create data directory
+ RUN mkdir -p /app/data + RUN mkdir -p /app/data
- RUN npm ci --only=production && \
+ RUN npm ci --omit=dev && \
npm cache clean --force
``` ```
### GitHub Actions Workflow ### GitHub Actions Workflow Changes
Added conditional login to prevent failures on pull requests:
```diff ```diff
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
+ if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request'
uses: docker/login-action@v3 uses: docker/login-action@v3
# Commented out nginx build until Phase 2
- build-nginx:
- name: Build nginx-enhanced Docker Image
+ # build-nginx:
+ # name: Build nginx-enhanced Docker Image
``` ```
## Result ## Result