Skip to content

Merge pull request #17 from DARPA-ASKEM/phase-1-eval #7

Merge pull request #17 from DARPA-ASKEM/phase-1-eval

Merge pull request #17 from DARPA-ASKEM/phase-1-eval #7

Workflow file for this run

---
# Automatically build Docker images on changes to main and push them to a
# Container Registry using HCL Bake file.
name: Build and Publish
# yamllint disable-line rule:truthy
on:
push:
branches: ['main']
tags: ['*']
env:
REGISTRY: ghcr.io
OWNER: ${{ github.repository_owner }}
BAKE_FILE: docker-bake.hcl
jobs:
# Generate a matrix based on all the targets defined in the
# bake file.
targets:
name: Generate targets list from provided bake file
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.targets.outputs.matrix }}
steps:
# 1.1 - checkout the files
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
# 1.2 - Generate a matrix output of all the targets for the specified group
- name: Create matrix
id: targets
run: |
BAKE_GROUP=documentation
TARGETS=$(docker buildx bake $BAKE_GROUP -f ${{ env.BAKE_FILE }} --print | jq -cr ".group.$BAKE_GROUP.targets")
echo "matrix=$TARGETS" >> $GITHUB_OUTPUT
# 1.3 (optional) - output the generated target list for verification
- name: Show matrix
run: |
echo ${{ steps.targets.outputs.matrix }}
build-push:
name: build-bake-push
runs-on: ubuntu-22.04
if: github.ref_name == 'main' || contains(github.event.ref, '/tags/')
permissions:
packages: write
contents: read
# this job depends on the following jobs before beginning
needs:
- targets
# 2.0 - Build a matrix strategy from the retrieved target list
strategy:
fail-fast: true
matrix:
target: ${{ fromJson(needs.targets.outputs.matrix) }}
steps:
# 2.1 - Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
# 2.2 - Build all packages and move them to required location for Docker
- name: Build
uses: Tiryoh/actions-mkdocs@v0
env:
requirements: 'requirements.txt'
configfile: 'mkdocs.yml'
# 2.3 - Set environment variables to be used within the bake file
# NOTE: this overrides the defaults and should be specific to this deployment
- name: set env variables for bakefile
run: |
if [[ '${{ github.ref_type }}' == 'branch' && '${{ github.ref_name }}' == 'main' ]]; then
TAG=latest
else
SEMVER=$( echo ${{ github.ref_name }} | sed -nre 's/^v[^0-9]*(([0-9]+\.)*[0-9]+(-[a-z]+)?).*/\1/p')
if [[ -n $SEMVER ]]; then
TAG=${SEMVER}
else
TAG=${{ github.ref_name }}
fi
fi
echo "$TAG"
echo "VERSION=${TAG,,}" >> ${GITHUB_ENV}
echo "DOCKER_REGISTRY=${{ env.REGISTRY }}" >> ${GITHUB_ENV}
# Lowercase the owner for docker image naming conventions
echo "DOCKER_ORG=${OWNER,,}" >> ${GITHUB_ENV}
java --version
# 2.4 - Login against the docker registry
- name: Login to registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# 2.5 - Setup QEMU for platform emulation
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# 2.6 - Setup Docker BuildX for multi platform building
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: |
image=moby/buildkit:v0.10.6
# 2.7 - Build and push Docker Images
- name: Build Images using BuildX Bake
uses: docker/bake-action@v2
with:
files: ./${{ env.BAKE_FILE }}
targets: ${{ matrix.target }}
push: true
set: |
*.cache-from=type=gha,scope=build-${{ matrix.target }}
*.cache-to=type=gha,scope=build-${{ matrix.target }},mode=max