diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 1321c71..9334ab6 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -11,10 +11,10 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - # Test Job + # Test Job (parallel) test: name: Run Tests - runs-on: ubuntu-latest + runs-on: self-hosted # Use your own server for speed! steps: - name: Checkout code uses: actions/checkout@v4 @@ -25,6 +25,16 @@ jobs: node-version: '20' cache: 'npm' + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: | + ~/.npm + node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies run: npm ci @@ -52,11 +62,10 @@ jobs: - name: Build application run: npm run build - # Security scan + # Security scan (parallel) security: name: Security Scan - runs-on: ubuntu-latest - needs: test + runs-on: self-hosted # Use your own server for speed! steps: - name: Checkout code uses: actions/checkout@v4 @@ -82,8 +91,8 @@ jobs: # Build and push Docker image build: name: Build and Push Docker Image - runs-on: ubuntu-latest - needs: [test, security] + runs-on: self-hosted # Use your own server for speed! + needs: [test, security] # Wait for parallel jobs to complete if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/production') permissions: contents: read @@ -132,12 +141,15 @@ jobs: uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 # Only AMD64 for speed push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + # Optimize for speed + build-args: | + BUILDKIT_INLINE_CACHE=1 # Deploy to server deploy: diff --git a/Dockerfile b/Dockerfile index 81eb497..3109424 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,14 @@ RUN npm ci --only=production && npm cache clean --force # Rebuild the source code only when needed FROM base AS builder WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules + +# Copy package files first for better caching +COPY package.json package-lock.json* ./ + +# Install all dependencies (including dev dependencies for build) +RUN npm ci + +# Copy source code COPY . . # Install type definitions for react-responsive-masonry and node-fetch