Repo File Sync: Update to Mu DevOps v12.2.0 and Python 3.12 (#382) #51
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
# GitHub Action Workflow for building the Project MU docker images. | |
# | |
# SPDX-License-Identifier: BSD-2-Clause-Patent | |
# | |
name: "Build Containers" | |
# | |
# This workflow only runs (on the main branch or on PRs targeted | |
# at the main branch) and if a dockerfile was edited. Pull request images will | |
# not be pushed to the repository. | |
# | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- ".sync/Version.njk" | |
- "Containers/**/Dockerfile" | |
pull_request: | |
branches: | |
- main | |
paths: | |
- ".sync/Version.njk" | |
- "Containers/**/Dockerfile" | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- image_name: "Ubuntu-22" | |
sub_images: "dev test build" | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY: ${{ github.repository }} | |
IMAGE_NAME: ${{ matrix.image_name }} | |
SUB_IMAGES: ${{ matrix.sub_images }} | |
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 tag | |
run: echo "short_sha=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV | |
shell: bash | |
- uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
dockerfile: | |
- 'Containers/${{ matrix.image_name }}/Dockerfile' | |
- name: Build | |
if: steps.changes.outputs.dockerfile == 'true' | |
run: | | |
cd "Containers/${IMAGE_NAME}" | |
for sub in $SUB_IMAGES; do | |
IMG=$(tr '[:upper:]' '[:lower:]' <<< "${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}-${sub}") | |
echo "Building Image: ${IMG}:${short_sha}..." | |
docker build --target "${sub}" --tag "${IMG}:${short_sha}" -f Dockerfile . | |
done | |
docker images | |
shell: bash | |
- name: Push | |
if: ${{ github.ref == 'refs/heads/main' && steps.changes.outputs.dockerfile == 'true' }} | |
run: | | |
for sub in $SUB_IMAGES; do | |
IMG=$(tr '[:upper:]' '[:lower:]' <<< "${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}-${sub}") | |
echo "Pushing Image: ${IMG}:${short_sha}..." | |
docker tag "${IMG}:${short_sha}" "${IMG}:latest" | |
docker push "${IMG}:${short_sha}" | |
docker push "${IMG}:latest" | |
done | |
shell: bash |