From 4331bc44e39a8d909bac75803c75d18af3cca5f2 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Tue, 26 Aug 2025 11:55:26 +0100 Subject: [PATCH] npm login --- .github/workflows/PR-Auto-Deploy-V2.yml | 11 +++++++++++ .github/workflows/build.yml | 7 +++++++ .github/workflows/deploy-on-v2-commit.yml | 11 +++++++++++ .github/workflows/frontend-licenses-update.yml | 5 +++++ .github/workflows/testdriver.yml | 2 ++ docker/frontend/Dockerfile | 18 ++++++++++++++---- 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/PR-Auto-Deploy-V2.yml b/.github/workflows/PR-Auto-Deploy-V2.yml index 2dbcd3260..b3e562741 100644 --- a/.github/workflows/PR-Auto-Deploy-V2.yml +++ b/.github/workflows/PR-Auto-Deploy-V2.yml @@ -260,6 +260,15 @@ jobs: echo "Backend image needs to be built" fi + - name: Create .npmrc for Docker build + if: steps.check-frontend.outputs.exists == 'false' + run: | + if [ "${{ secrets.NPM_TOKEN }}" != "" ]; then + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > /tmp/.npmrc + else + touch /tmp/.npmrc + fi + - name: Build and push V2 frontend image if: steps.check-frontend.outputs.exists == 'false' uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 @@ -270,6 +279,8 @@ jobs: tags: ${{ secrets.DOCKER_HUB_USERNAME }}/test:v2-frontend-${{ steps.commit-hashes.outputs.frontend_short }} build-args: VERSION_TAG=v2-alpha platforms: linux/amd64 + secrets: | + npmrc=/tmp/.npmrc - name: Build and push V2 backend image if: steps.check-backend.outputs.exists == 'false' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e38b82fb..d549e3c34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -143,14 +143,21 @@ jobs: uses: actions/setup-node@v4.1.0 with: node-version: '20' + registry-url: 'https://registry.npmjs.org' cache: 'npm' cache-dependency-path: frontend/package-lock.json - name: Install frontend dependencies run: cd frontend && npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Build frontend run: cd frontend && npm run build + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Run frontend tests run: cd frontend && npm run test -- --run + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Upload frontend build artifacts uses: actions/upload-artifact@v4.6.2 with: diff --git a/.github/workflows/deploy-on-v2-commit.yml b/.github/workflows/deploy-on-v2-commit.yml index f2f90ccfa..12d108099 100644 --- a/.github/workflows/deploy-on-v2-commit.yml +++ b/.github/workflows/deploy-on-v2-commit.yml @@ -91,6 +91,15 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_API }} + - name: Create .npmrc for Docker build + if: steps.check-frontend.outputs.exists == 'false' + run: | + if [ "${{ secrets.NPM_TOKEN }}" != "" ]; then + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > /tmp/.npmrc + else + touch /tmp/.npmrc + fi + - name: Build and push frontend image if: steps.check-frontend.outputs.exists == 'false' uses: docker/build-push-action@v6 @@ -103,6 +112,8 @@ jobs: ${{ secrets.DOCKER_HUB_USERNAME }}/test:v2-frontend-latest build-args: VERSION_TAG=v2-alpha platforms: linux/amd64 + secrets: | + npmrc=/tmp/.npmrc - name: Build and push backend image if: steps.check-backend.outputs.exists == 'false' diff --git a/.github/workflows/frontend-licenses-update.yml b/.github/workflows/frontend-licenses-update.yml index ac8676c8a..54e423c58 100644 --- a/.github/workflows/frontend-licenses-update.yml +++ b/.github/workflows/frontend-licenses-update.yml @@ -48,16 +48,21 @@ jobs: uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 with: node-version: '18' + registry-url: 'https://registry.npmjs.org' cache: 'npm' cache-dependency-path: frontend/package-lock.json - name: Install frontend dependencies working-directory: frontend run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Generate frontend license report working-directory: frontend run: npm run generate-licenses + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Check for license warnings run: | diff --git a/.github/workflows/testdriver.yml b/.github/workflows/testdriver.yml index 209ce7435..68f487141 100644 --- a/.github/workflows/testdriver.yml +++ b/.github/workflows/testdriver.yml @@ -131,6 +131,7 @@ jobs: - name: Set up Node uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: + registry-url: 'https://registry.npmjs.org' cache: 'npm' - name: Run TestDriver.ai @@ -147,6 +148,7 @@ jobs: 1. /run testing/testdriver/test.yml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} FORCE_COLOR: "3" cleanup: diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index a220782b0..c1e3d9a96 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -6,14 +6,24 @@ WORKDIR /app # Copy package files COPY frontend/package*.json ./ -# Install dependencies -RUN npm ci +# Install dependencies (uses .npmrc secret if available, otherwise anonymous) +RUN --mount=type=secret,id=npmrc,target=/tmp/.npmrc \ + if [ -s /tmp/.npmrc ]; then \ + cp /tmp/.npmrc /root/.npmrc; \ + fi && \ + npm ci && \ + rm -f /root/.npmrc # Copy source code COPY frontend . -# Build the application -RUN npm run build +# Build the application (uses .npmrc secret if available, otherwise anonymous) +RUN --mount=type=secret,id=npmrc,target=/tmp/.npmrc \ + if [ -s /tmp/.npmrc ]; then \ + cp /tmp/.npmrc /root/.npmrc; \ + fi && \ + npm run build && \ + rm -f /root/.npmrc # Production stage FROM nginx:alpine