diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index a58c0f6..a4f1d11 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -67,52 +67,10 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - build-nginx: - name: Build nginx-enhanced Docker Image - runs-on: ubuntu-latest - permissions: - 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 \ No newline at end of file + # Nginx build commented out until Phase 2 + # build-nginx: + # name: Build nginx-enhanced Docker Image + # runs-on: ubuntu-latest + # permissions: + # contents: read + # packages: write \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0e4f1da..49882ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ RUN apk add --no-cache curl su-exec util-linux && \ # Install production dependencies only COPY package*.json ./ -RUN npm ci --only=production && \ +RUN npm ci --omit=dev && \ npm cache clean --force # Copy built application diff --git a/docs/DOCKER_BUILD_FIX.md b/docs/DOCKER_BUILD_FIX.md index 8f8f8f9..edbfcae 100644 --- a/docs/DOCKER_BUILD_FIX.md +++ b/docs/DOCKER_BUILD_FIX.md @@ -1,29 +1,43 @@ # Docker Build Fix -## Issue -The Docker build was failing with the error: +## Issues Fixed + +### 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 ``` -## Root Cause -The Dockerfile contained an invalid COPY command that tried to use shell operators: -```dockerfile -# This doesn't work in Docker -COPY --from=builder /app/data/nodes.db ./data/nodes.db 2>/dev/null || true +### 2. Missing Dockerfile.nginx +``` +ERROR: failed to solve: failed to read dockerfile: open Dockerfile.nginx: no such file or directory ``` +### 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`. -## Solution -1. Removed the problematic COPY command -2. Created the data directory with RUN instead -3. Removed database pre-initialization from build stage -4. Database is now initialized at runtime by the entrypoint script +**Solution**: Removed the problematic COPY command and created data directory with RUN. + +### 2. Dockerfile.nginx Not Yet Implemented +The GitHub Actions workflow referenced `Dockerfile.nginx` which is a Phase 2 feature. + +**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 -### Dockerfile +### Dockerfile Changes ```diff - # Pre-initialize database during build - 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 + # Create data directory + RUN mkdir -p /app/data + +- RUN npm ci --only=production && \ ++ RUN npm ci --omit=dev && \ + npm cache clean --force ``` -### GitHub Actions Workflow -Added conditional login to prevent failures on pull requests: +### GitHub Actions Workflow Changes ```diff - name: Log in to GitHub Container Registry + if: github.event_name != 'pull_request' 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