Adding common CDS GitHub actions #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 20.11.1 | |
- name: Use the node_modules cache if available [npm] | |
id: use-npm-cache | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: node-20.11.1-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@v5 | |
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@v5 | |
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@v5 | |
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 |