This commit is contained in:
Anthony Stirling 2025-08-26 13:09:58 +01:00
parent a98311e583
commit e724416f23
3 changed files with 37 additions and 5 deletions

View File

@ -260,8 +260,8 @@ jobs:
echo "Backend image needs to be built" echo "Backend image needs to be built"
fi fi
- name: Build and push V2 frontend image - name: Build and push V2 frontend image (with NPM token)
if: steps.check-frontend.outputs.exists == 'false' if: steps.check-frontend.outputs.exists == 'false' && secrets.NPM_TOKEN != ''
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with: with:
context: . context: .
@ -273,6 +273,17 @@ jobs:
secrets: | secrets: |
npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- name: Build and push V2 frontend image (anonymous)
if: steps.check-frontend.outputs.exists == 'false' && secrets.NPM_TOKEN == ''
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: ./docker/frontend/Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/test:v2-frontend-${{ steps.commit-hashes.outputs.frontend_short }}
build-args: VERSION_TAG=v2-alpha
platforms: linux/amd64
- name: Build and push V2 backend image - name: Build and push V2 backend image
if: steps.check-backend.outputs.exists == 'false' if: steps.check-backend.outputs.exists == 'false'
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0

View File

@ -91,8 +91,8 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }} username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_API }} password: ${{ secrets.DOCKER_HUB_API }}
- name: Build and push frontend image - name: Build and push frontend image (with NPM token)
if: steps.check-frontend.outputs.exists == 'false' if: steps.check-frontend.outputs.exists == 'false' && secrets.NPM_TOKEN != ''
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
@ -106,6 +106,19 @@ jobs:
secrets: | secrets: |
npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- name: Build and push frontend image (anonymous)
if: steps.check-frontend.outputs.exists == 'false' && secrets.NPM_TOKEN == ''
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/frontend/Dockerfile
push: true
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/test:v2-frontend-${{ steps.commit-hashes.outputs.frontend_short }}
${{ secrets.DOCKER_HUB_USERNAME }}/test:v2-frontend-latest
build-args: VERSION_TAG=v2-alpha
platforms: linux/amd64
- name: Build and push backend image - name: Build and push backend image
if: steps.check-backend.outputs.exists == 'false' if: steps.check-backend.outputs.exists == 'false'
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6

View File

@ -8,10 +8,14 @@ COPY frontend/package*.json ./
# Install dependencies (uses .npmrc secret if available, otherwise anonymous) # Install dependencies (uses .npmrc secret if available, otherwise anonymous)
RUN --mount=type=secret,id=npmrc \ RUN --mount=type=secret,id=npmrc \
set -e && \
if [ -s /run/secrets/npmrc ]; then \ if [ -s /run/secrets/npmrc ]; then \
echo "Using authenticated npm registry" && \
echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \ echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \
else \
echo "Using anonymous npm registry (no token provided)"; \
fi && \ fi && \
npm ci && \ npm ci --loglevel=warn && \
rm -f /root/.npmrc rm -f /root/.npmrc
# Copy source code # Copy source code
@ -19,8 +23,12 @@ COPY frontend .
# Build the application (uses .npmrc secret if available, otherwise anonymous) # Build the application (uses .npmrc secret if available, otherwise anonymous)
RUN --mount=type=secret,id=npmrc \ RUN --mount=type=secret,id=npmrc \
set -e && \
if [ -s /run/secrets/npmrc ]; then \ if [ -s /run/secrets/npmrc ]; then \
echo "Using authenticated npm registry for build" && \
echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \ echo "$(cat /run/secrets/npmrc)" > /root/.npmrc; \
else \
echo "Using anonymous npm registry for build (no token provided)"; \
fi && \ fi && \
npm run build && \ npm run build && \
rm -f /root/.npmrc rm -f /root/.npmrc