Skip to content

Dockerfile: Add Rust support #19

Dockerfile: Add Rust support

Dockerfile: Add Rust support #19

# 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:
- "Containers/**/Dockerfile"
pull_request:
branches:
- main
paths:
- "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@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
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@v2
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