Building service containers #9
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
name: build-containers | |
run-name: Building service containers | |
on: | |
push: | |
env: | |
BASE_IMAGE: cccs/assemblyline-v4-service-base:stable | |
REGISTRY: ghcr.io | |
BASE_TAG: 4.4.0.stable | |
jobs: | |
discover-services: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Discover directories with Dockerfiles | |
id: services | |
run: | | |
echo "services=$(find . -type f -name Dockerfile | xargs -n 1 dirname | uniq | cut -d '/' -f 2 | grep -v 'TEMPLATE' | jq -R -s -c 'split("\n")[:-1]')" >> "$GITHUB_OUTPUT" | |
- name: Print services with Dockerfiles | |
run: | | |
echo "Services with Dockerfiles: ${{ steps.services.outputs.services }}" | |
outputs: | |
services: ${{ steps.services.outputs.services }} | |
build-containers: | |
needs: discover-services | |
runs-on: ubuntu-latest | |
if: needs.discover-services.outputs.services != '[]' | |
strategy: | |
matrix: | |
service: ${{ fromJson(needs.discover-services.outputs.services) }} | |
defaults: | |
run: | |
working-directory: ${{ matrix.service }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Authorize to GitHub Packages | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Authorize to Github Docker Registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | |
- name: Build container | |
run: | | |
make build | |
- name: Check service was changed in the commit | |
id: check-service-changed | |
run: | | |
git diff --quiet ${{ github.event.before }} ${{ github.event.after }} -- ${{ matrix.service }} | |
- name: Run tests | |
if: steps.check-service-changed.outputs.exit-code != 0 | |
run: | | |
make test | |
- name: Check if the current version has already been pushed | |
id: check-if-pushed | |
run: | | |
export GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64) | |
export TAG=$BASE_TAG$(cat VERSION) | |
curl -H "Authorization: Bearer ${GHCR_TOKEN}" https://ghcr.io/v2/kam193/${{ matrix.service }}/manifests/$TAG | |
- name: Push container | |
if: steps.check-version-changed.outputs.exit-code != 0 | |
run: | | |
make push |