Skip to content

Commit

Permalink
Modify image testing workflow to use composite actions
Browse files Browse the repository at this point in the history
Rewrote image testing workflow such that it runs composite workflows to reduce duplicate code. Also changed the workflow so that all build tasks execute on the same runner -- this allows the Docker build cache to be reused, reducing workflow duration
  • Loading branch information
nathan-hess committed Jun 5, 2022
1 parent 64c8a2c commit 39ef92f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/check-required-images/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ runs:
- name: Check for Docker Images
shell: bash
run: |
echo "Checking for required Docker images..."
num_missing_imgs=0
for image in $(echo "${{ inputs.required_images }}"); do
if [[ "$(docker images -q "${image}")" == "" ]]; then
Expand All @@ -23,6 +24,6 @@ runs:
if [ "$num_missing_imgs" -eq "0" ]; then
exit 0
else
printf "\nMissing ${num_missing_imgs} required images\n"
printf "Missing ${num_missing_imgs} required image(s)\n"
exit 1
fi
1 change: 1 addition & 0 deletions .github/workflows/docker-build-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ runs:
tags: ${{ inputs.tags }}
build-args: |
BASE_DOCKER_REPO=${{ env.DOCKER_HUB_REPO }}
BASE_TAG=${{ env.TAG_BASE_ROOT }}
UBUNTU_VERSION=${{ env.CONTAINER_UBUNTU_VERSION }}
USERNAME=${{ env.CONTAINER_USERNAME }}
PASSWORD=${{ env.CONTAINER_PASSWORD }}
Expand Down
135 changes: 36 additions & 99 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,114 +9,51 @@ on:
workflow_dispatch:

jobs:
setup:
name: Build Environment Setup
test:
name: Docker Test
runs-on: ubuntu-latest
steps:
- name: Check Out Repository Files
uses: actions/checkout@v3

- name: Load Environment Variables
run: cat .env >> $GITHUB_ENV
outputs:
DOCKER_HUB_REPO: ${{ env.DOCKER_HUB_REPO }}
TAG_BASE_STANDARD: ${{ env.TAG_BASE_STANDARD }}
TAG_BASE_ROOT: ${{ env.TAG_BASE_ROOT }}
TAG_FULL_STANDARD: ${{ env.TAG_FULL_STANDARD }}
TAG_FULL_ROOT: ${{ env.TAG_FULL_ROOT }}
CONTAINER_UBUNTU_VERSION: ${{ env.CONTAINER_UBUNTU_VERSION }}
CONTAINER_USERNAME: ${{ env.CONTAINER_USERNAME }}
CONTAINER_PASSWORD: ${{ env.CONTAINER_PASSWORD }}
CONTAINER_UID: ${{ env.CONTAINER_UID }}
CONTAINER_GID: ${{ env.CONTAINER_GID }}
CONTAINER_TIMEZONE: ${{ env.CONTAINER_TIMEZONE }}
- name: Set Up Runner
uses: './.github/workflows/setup'

test-base:
name: Docker Test - base - ${{ matrix.user }}
needs: setup
if: ${{ success() }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
user: [standard]
sudo: ["sudo"]
include:
- user: root
sudo: ""
steps:
- name: Check Out Repository Files
uses: actions/checkout@v3

- name: Build Docker Image - base
uses: docker/build-push-action@v2
- name: Test Docker Image - base - standard
if: ${{ always() }}
uses: './.github/workflows/test'
with:
context: ./dockerfile_base/
push: false
tags: test
build-args: |
BASE_DOCKER_REPO=${{ needs.setup.outputs.DOCKER_HUB_REPO }}
UBUNTU_VERSION=${{ needs.setup.outputs.CONTAINER_UBUNTU_VERSION }}
USERNAME=${{ needs.setup.outputs.CONTAINER_USERNAME }}
PASSWORD=${{ needs.setup.outputs.CONTAINER_PASSWORD }}
UID=${{ needs.setup.outputs.CONTAINER_UID }}
GID=${{ needs.setup.outputs.CONTAINER_GID }}
TIMEZONE=${{ needs.setup.outputs.CONTAINER_TIMEZONE }}
USER_PRIVILEGE_LEVEL=${{ matrix.user }}
- name: Test Docker Image
run: |
docker run --rm -v $GITHUB_WORKSPACE:/host test /bin/bash -c "${{ matrix.sudo }} /etc/startup.sh && bash /host/dockerfile_base/image_tests/run_tests.sh ${{ matrix.user }}"
user: standard
docker_build_context: dockerfile_base/

test-full:
name: Docker Test - full - ${{ matrix.user }}
needs: setup
if: ${{ success() }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
user: [standard]
sudo: ["sudo"]
include:
- user: root
sudo: ""
steps:
- name: Check Out Repository Files
uses: actions/checkout@v3

- name: Build Docker Image - base root
uses: docker/build-push-action@v2
- name: Test Docker Image - base - root
if: ${{ always() }}
uses: './.github/workflows/test'
with:
context: ./dockerfile_base/
push: false
tags: ${{ needs.setup.outputs.DOCKER_HUB_REPO }}:${{ needs.setup.outputs.TAG_BASE_ROOT }}
build-args: |
BASE_DOCKER_REPO=${{ needs.setup.outputs.DOCKER_HUB_REPO }}
UBUNTU_VERSION=${{ needs.setup.outputs.CONTAINER_UBUNTU_VERSION }}
USERNAME=${{ needs.setup.outputs.CONTAINER_USERNAME }}
PASSWORD=${{ needs.setup.outputs.CONTAINER_PASSWORD }}
UID=${{ needs.setup.outputs.CONTAINER_UID }}
GID=${{ needs.setup.outputs.CONTAINER_GID }}
TIMEZONE=${{ needs.setup.outputs.CONTAINER_TIMEZONE }}
USER_PRIVILEGE_LEVEL=root
user: root
docker_build_context: dockerfile_base/

- name: Build Docker Image - full
uses: docker/build-push-action@v2
- name: Build Image - base/root (full image dependency)
uses: './.github/workflows/docker-build-push'
with:
user: root
context: dockerfile_base/
load: 'true'
push: 'false'
tags: ${{ env.DOCKER_HUB_REPO }}:${{ env.TAG_BASE_ROOT }}

- name: Test Docker Image - full - standard
if: ${{ always() }}
uses: './.github/workflows/test'
with:
context: ./dockerfile_full/
push: false
tags: test
build-args: |
BASE_DOCKER_REPO=${{ needs.setup.outputs.DOCKER_HUB_REPO }}
BASE_TAG=${{ needs.setup.outputs.TAG_BASE_ROOT }}
USERNAME=${{ needs.setup.outputs.CONTAINER_USERNAME }}
PASSWORD=${{ needs.setup.outputs.CONTAINER_PASSWORD }}
UID=${{ needs.setup.outputs.CONTAINER_UID }}
GID=${{ needs.setup.outputs.CONTAINER_GID }}
TIMEZONE=${{ needs.setup.outputs.CONTAINER_TIMEZONE }}
USER_PRIVILEGE_LEVEL=${{ matrix.user }}
user: standard
docker_build_context: dockerfile_full/
required_images: ${{ env.DOCKER_HUB_REPO }}:${{ env.TAG_BASE_ROOT }}

- name: Test Docker Image
run: |
docker run --rm -v $GITHUB_WORKSPACE:/host test /bin/bash -c "${{ matrix.sudo }} /etc/startup.sh && bash /host/dockerfile_full/image_tests/run_tests.sh ${{ matrix.user }}"
- name: Test Docker Image - full - root
if: ${{ always() }}
uses: './.github/workflows/test'
with:
user: root
docker_build_context: dockerfile_full/
required_images: ${{ env.DOCKER_HUB_REPO }}:${{ env.TAG_BASE_ROOT }}

0 comments on commit 39ef92f

Please sign in to comment.