Skip to content

Merge pull request #1181 from mcneilco/ACAS-780 #1478

Merge pull request #1181 from mcneilco/ACAS-780

Merge pull request #1181 from mcneilco/ACAS-780 #1478

Workflow file for this run

name: Docker Image CI
on:
push:
branches: ["master", "release/*"]
tags:
- "*"
pull_request:
types: [opened, synchronize]
jobs:
acas:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ github.repository }}-oss
- name: Set ACAS_TAG to ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
run: echo "ACAS_TAG=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# The following few steps figure out what version of acasclient to test with
# If main or release branch, run tests using matching release branch of acasclient
- name: Set ACAS_CLIENT_REF to the current branch ${{ github.ref }}
run: |
echo "ACAS_CLIENT_REF=$(echo ${{ github.ref }} | sed 's/refs\/heads\///g')" >> $GITHUB_ENV
if: github.event_name == 'push'
# If a PR, run tests on acasclient branch matching destination of PR
- name: Set ACAS_CLIENT_REF to the PR destination branch ${{ github.base_ref }}
run: |
echo "ACAS_CLIENT_REF=${{ github.base_ref }}" >> $GITHUB_ENV
if: github.event_name == 'pull_request'
# If a tag, run tests on acasclient branch by the same tag
- name: Set ACAS_CLIENT_REF to tag extracted from ${{ github.ref }}
run: |
ACAS_CLIENT_REF=$(echo ${{ github.ref }} | sed 's/refs\/tags\///')
echo "ACAS_CLIENT_REF=$ACAS_CLIENT_REF" >> $GITHUB_ENV
if: github.event_name == 'create'
# If on the "master" branch, run tests on the "main" branch of acasclient
- name: Override ACAS_CLIENT_REF if branch is "master"
run: |
echo "ACAS_CLIENT_REF=main" >> $GITHUB_ENV
if: github.ref == 'refs/heads/master'
- name: Checkout acasclient
uses: actions/checkout@v4
with:
repository: mcneilco/acasclient
path: acasclient
# Check out the branch specified by ACAS_CLIENT_REF
ref: ${{ env.ACAS_CLIENT_REF }}
- name: Build (no push)
uses: docker/build-push-action@v5
with:
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ env.ACAS_TAG }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
- name: Run docker-compose up - assumes racas-oss:${{ env.ACAS_TAG }} and acas-roo-server-oss:${{ env.ACAS_TAG }}-indigo exist and are up to date
id: dockerComposeUp
run: |
echo "docker_compose_pull_failure=false" >> $GITHUB_OUTPUT
docker-compose -f "docker-compose.yml" up -d || echo "docker_compose_pull_failure=true" >> $GITHUB_OUTPUT
- name: Get docker images fallback tag name
run: |
echo "DEFAULT_BRANCH_ACAS_TAG=$(echo ${{ github.event.repository.default_branch }} | sed -e 's/\//-/g')" >> $GITHUB_ENV
if: ${{ steps.dockerComposeUp.outputs.docker_compose_pull_failure == 'true' }}
- name: Falling back to ${{ env.DEFAULT_BRANCH_ACAS_TAG }} docker image tag for roo and racas tags
run: |
docker pull mcneilco/acas-roo-server-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG }}-indigo
docker tag mcneilco/acas-roo-server-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG}}-indigo mcneilco/acas-roo-server-oss:${{ env.ACAS_TAG }}-indigo
docker pull mcneilco/racas-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG}}
docker tag mcneilco/racas-oss:${{ env.DEFAULT_BRANCH_ACAS_TAG }} mcneilco/racas-oss:${{ env.ACAS_TAG }}
docker-compose -f "docker-compose.yml" up -d
if: ${{ steps.dockerComposeUp.outputs.docker_compose_pull_failure == 'true' }}
- name: Create docker bob
run: bash docker_bob_setup.sh
- name: Create bob credentials for acasclient
run: |
mkdir ~/.acas
echo "[default]" >> ~/.acas/credentials
echo "username=bob" >> ~/.acas/credentials
echo "password=secret" >> ~/.acas/credentials
echo "url=http://localhost:3000" >> ~/.acas/credentials
- name: Set Up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install acasclient and dependencies
run: |
python -m pip install --upgrade pip
pip install ./acasclient
- name: Run tests
run: python -m unittest discover -s ./acasclient -p "test_*.py" -v
- name: Build multi-arch and push
# Only push tags and release branches
if: ${{ startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile
platforms: linux/amd64,linux/arm64/v8
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ env.ACAS_TAG }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}