Skip to content

Adding: Dummy compose #23

Adding: Dummy compose

Adding: Dummy compose #23

name: Build and Publish Docker images
on:
workflow_dispatch:
push:
jobs:
create-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix_object }}
steps:
- name: Checkout directory
uses: actions/checkout@v3
with:
submodules: true
- name: Create Matrix object
id: matrix
shell: pwsh
run: |
$matrix = [pscustomobject]@{}
$directories = [System.Collections.ArrayList]@()
Get-ChildItem -Path $PWD -Recurse -Depth 2 -Include Dockerfile | Select-Object -Property DirectoryName | Foreach-Object {$directories.Add($_.DirectoryName.split('/')[-1])} | Out-Null
$matrix | Add-Member -MemberType NoteProperty -Name "projects" -Value $directories
$mat_object = $matrix | ConvertTo-Json -Compress
Add-Content -Path $Env:GITHUB_OUTPUT -Value "matrix_object=$mat_object"
$mat_object
docker-build-scan-push:
runs-on: ubuntu-latest
needs: [create-matrix]
strategy:
matrix: ${{ fromJson(needs.create-matrix.outputs.matrix) }}
fail-fast: false
steps:
- name: Checkout directory
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to the Container Registry
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Retrieve Image Name/Version and export IMAGE_REF
run: |
IMAGE_NAME=$(grep '# IMAGE_NAME:' ./library/${{ matrix.projects }}/Dockerfile | cut -d ':' -f2 | xargs)
IMAGE_VERSION=$(grep '# IMAGE_VERSION:' ./library/${{ matrix.projects }}/Dockerfile | cut -d ':' -f2 | xargs)
echo "IMAGE_REF=${IMAGE_NAME}:${IMAGE_VERSION}" \
>>${GITHUB_ENV}
- name: Add suffix to IMAGE_REF if not built from master/main branch
if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }}
run: |
echo "IMAGE_REF=${{ env.IMAGE_REF }}-dev-$(echo ${GITHUB_SHA} | cut -c1-7)" \
>>${GITHUB_ENV}
- name: Print IMAGE_REF
run: echo ${{ env.IMAGE_REF }}
- name: Export IMAGE_TAG environment variable
run: |
echo "IMAGE_TAG=${{ secrets.ACR_LOGIN_SERVER }}/${{ env.IMAGE_REF }}" \
>>${GITHUB_ENV}
- name: Print IMAGE_REF
run: echo ${{ env.IMAGE_REF }}
- name: Build and Tag image
run: |
cd ./library/${{ matrix.projects }}
docker build -f Dockerfile -t ${{ env.IMAGE_TAG }} .
- name: Scan image
uses: Azure/container-scan@v0
with:
image-name: ${{ env.IMAGE_TAG }}
severity-threshold: CRITICAL
run-quality-checks: true
- name: Build and Push Image
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
context: ./library/${{ matrix.projects }}
tags: ${{ env.IMAGE_TAG }}
build-args: |
IMAGE_VERSION=${{ env.IMAGE_VERSION }}
- name: Print Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}