Skip to content

Merge pull request #59 from co-cddo/dependabot/composer/cloudformatio… #88

Merge pull request #59 from co-cddo/dependabot/composer/cloudformatio…

Merge pull request #59 from co-cddo/dependabot/composer/cloudformatio… #88

Workflow file for this run

# Build and publish LocalGov Drupal container image to ghcr.io
#
# Triggers on:
# - Push to main branch affecting docker/* or drupal/* files
# - All pull requests (skips build if no relevant files changed)
# - Manual workflow_dispatch
#
# Produces:
# - ghcr.io/[org]/localgov-drupal:latest
# - ghcr.io/[org]/localgov-drupal:sha-<commit>
name: Build LocalGov Drupal Container
on:
push:
branches: [main]
paths:
- 'cloudformation/scenarios/localgov-drupal/docker/**'
- 'cloudformation/scenarios/localgov-drupal/drupal/**'
- 'cloudformation/scenarios/localgov-drupal/.dockerignore'
- '.github/workflows/docker-build.yml'
pull_request:
workflow_dispatch:
inputs:
push_image:
description: 'Push image to registry'
required: false
default: true
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: co-cddo/ndx_try_aws_scenarios-localgov_drupal
jobs:
changes:
name: Check for Docker changes
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
outputs:
docker: ${{ steps.filter.outputs.docker }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docker:
- 'cloudformation/scenarios/localgov-drupal/docker/**'
- 'cloudformation/scenarios/localgov-drupal/drupal/**'
- 'cloudformation/scenarios/localgov-drupal/.dockerignore'
- '.github/workflows/docker-build.yml'
build:
name: Build and Push Container
runs-on: ubuntu-latest
needs: [changes]
# Run if: push/dispatch (changes job skipped), OR PR with docker changes
if: |
always() &&
(needs.changes.result == 'skipped' || needs.changes.outputs.docker == 'true')
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# SHA tag for every build
type=sha,prefix=sha-
# latest tag only on main branch
type=raw,value=latest,enable={{is_default_branch}}
# Branch name for non-main branches
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: cloudformation/scenarios/localgov-drupal
file: cloudformation/scenarios/localgov-drupal/docker/Dockerfile
push: ${{ github.ref == 'refs/heads/main' && github.event.inputs.push_image != 'false' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Output image details
run: |
echo "## Docker Image Built" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY