Skip to content

Build Base Container Images #316

Build Base Container Images

Build Base Container Images #316

Workflow file for this run

name: Build Base Container Images
on:
push:
branches:
- main
pull_request:
schedule:
# Rebuild daily at 5 AM UTC (weekdays only)
- cron: '0 5 * * 1-5'
workflow_dispatch:
env:
REGISTRY: ghcr.io
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-scan-push:
name: Build-Scan-Push
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- image_name: eclipse-temurin
context: images/java/eclipse-temurin
dockerfile: images/java/eclipse-temurin/Dockerfile.java21
tag_prefix: 21-jre-jammy
publish_latest: false
- image_name: eclipse-temurin
context: images/java/eclipse-temurin
dockerfile: images/java/eclipse-temurin/Dockerfile.java25
tag_prefix: 25-jre-jammy
publish_latest: true
- image_name: distroless-java
context: images/java/distroless
dockerfile: images/java/distroless/Dockerfile.java21
tag_prefix: 21-jre
publish_latest: false
- image_name: distroless-java
context: images/java/distroless
dockerfile: images/java/distroless/Dockerfile.java25
tag_prefix: 25-jre
publish_latest: true
- image_name: node
context: images/node/alpine
dockerfile: images/node/alpine/Dockerfile
tag_prefix: 24-alpine
publish_latest: false
- image_name: node
context: images/node/alpine-runtime
dockerfile: images/node/alpine-runtime/Dockerfile
tag_prefix: 24-alpine-runtime
publish_latest: true
- image_name: distroless-node
context: images/node/distroless
dockerfile: images/node/distroless/Dockerfile
tag_prefix: 24
publish_latest: true
- image_name: python
context: images/python/alpine
dockerfile: images/python/alpine/Dockerfile
tag_prefix: python3.13-alpine
publish_latest: true
permissions:
contents: read
packages: write
security-events: write
steps:
- name: Check out the repo
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
- name: Set up QEMU
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/hmpps-${{ matrix.image_name }}
flavor: |
latest=false
tags: |
# Prefix dynamic tags with the variant to prevent overwrites between matrix entries
type=schedule,pattern={{date 'YYYYMMDD'}},prefix=${{ matrix.tag_prefix }}-
type=ref,event=branch,prefix=${{ matrix.tag_prefix }}-
type=ref,event=tag,prefix=${{ matrix.tag_prefix }}-
type=ref,event=pr,prefix=${{ matrix.tag_prefix }}-
type=sha,prefix=${{ matrix.tag_prefix }}-
type=raw,value=${{ matrix.tag_prefix }}
type=raw,value=latest,enable=${{ matrix.publish_latest }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push container image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: ./${{ matrix.context }}
file: ./${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
pull: true
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'schedule' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
no-cache-filters: security-upgrades
- name: Slack notification
id: slack
if: ${{ failure() }}
uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3
with:
method: chat.postMessage
token: ${{ secrets.HMPPS_SRE_SLACK_BOT_TOKEN }}
payload: |
{
"channel": "${{ vars.SECURITY_ALERTS_SLACK_CHANNEL_ID }}",
"text": "Base image build failed for ${{ github.repository }}",
"attachments": [
{
"color": "danger",
"fallback": "${{ matrix.image_name }} Image Build Failed - ${{ github.workflow }} in ${{ github.repository }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🔨 ${{ matrix.image_name }} Image Build Failed"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Workflow:*\n${{ github.workflow }}"
},
{
"type": "mrkdwn",
"text": "*Repository:*\n${{ github.repository }}"
},
{
"type": "mrkdwn",
"text": "*Branch:*\n${{ github.ref_name }}"
},
{
"type": "mrkdwn",
"text": "*Status:*\n${{ job.status }}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Run"
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
]
}