Skip to content
name: Create and publish a Docker image
on:
pull_request_target:
types:
- closed
branches:
- main
env:
REGISTRY: ghcr.io
REPO_NAME: ${{ github.repository }}
jobs:
cache-deps:
if: github.event.pull_request.merged == true
name: Pull request merge - Validate npm cache for main branch
runs-on: ubuntu-latest
steps:
- name: Checkout [main]
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22.8.0
- name: Use the node_modules cache if available [npm]
id: use-npm-cache
uses: actions/cache@v4
with:
path: node_modules
key: node-22.8.0-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.use-npm-cache.outputs.cache-hit != 'true'
run: npm ci
build-and-push-image:
if: github.event.pull_request.merged == true
needs: cache-deps
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image (web)
uses: docker/build-push-action@v6
with:
context: .
file: docker/performance_base/Dockerfile
target: web
push: true
tags: ghcr.io/${{ env.REPO_NAME }}/web:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push Docker image (nginx)
uses: docker/build-push-action@v6
with:
context: .
file: docker/performance_base/Dockerfile
target: nginx
push: true
tags: ghcr.io/${{ env.REPO_NAME }}/nginx:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push Docker image (db-updater)
uses: docker/build-push-action@v6
with:
context: .
file: docker/performance_base/Dockerfile
target: db-updater
push: true
tags: ghcr.io/${{ env.REPO_NAME }}/db-updater:latest
cache-from: type=gha
cache-to: type=gha,mode=max