Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring container build to use CDCgov/cfa-actions/twostep-container-build #167

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
91 changes: 11 additions & 80 deletions .github/workflows/containers-and-az-pool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ on:

env:
# Together, these form: cfaprdbatchcr.azurecr.io/cfa-epinow2-pipeline
REGISTRY: cfaprdbatchcr.azurecr.io
REGISTRY: cfaprdbatchcr.azurecr.io/
IMAGE_NAME: cfa-epinow2-pipeline

jobs:

build-dependencies-image:
build-pipeline-image:
runs-on: cfa-cdcgov # VM based runner serving CFA's cdcgov repos (as opposed to cdcent)
name: Build dependencies image
name: Build image

outputs:
tag: ${{ steps.image-tag.outputs.tag }}
Expand All @@ -49,86 +49,17 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

#########################################################################
# Getting the tag from the branch
# The tag will be used for both the docker image and the batch pool
#########################################################################

# From: https://stackoverflow.com/a/58035262/2097171
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: branch-name

- name: Figure out tag (either latest if it is main or the branch name)
- name: Build the images
id: image-tag
run: |
if [ "${{ steps.branch-name.outputs.branch }}" = "main" ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "tag=${{ steps.branch-name.outputs.branch }}" >> $GITHUB_OUTPUT
fi

# NOTE: This lookup is only for the cache _key_. We don't need the cache _value_
# because we explicitly fetch image from the registry in the next step. Keeping the
# cached image on the runner causes the runner to quickly run out of storage.
- name: Check cache for base image
uses: actions/cache@v4
id: cache
uses: CDCgov/cfa-actions/[email protected]
with:
key: docker-dependencies-${{ runner.os }}-${{ hashFiles('./DESCRIPTION', './Dockerfile-dependencies') }}-${{ steps.image-tag.outputs.tag }}
lookup-only: true
path:
./DESCRIPTION

- name: Login to the Container Registry
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/login-action@v3
with:
registry: "cfaprdbatchcr.azurecr.io"
username: "cfaprdbatchcr"
container-file-1: ./Dockerfile-dependencies
container-file-2: ./Dockerfile
registry: ${{ env.REGISTRY }}
password: ${{ secrets.CFAPRDBATCHCR_REGISTRY_PASSWORD }}

- name: Build and push
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/build-push-action@v6
with:
push: true
no-cache: true
tags: |
${{ env.REGISTRY}}/${{ env.IMAGE_NAME }}-dependencies:${{ steps.image-tag.outputs.tag }}
file: ./Dockerfile-dependencies

build-pipeline-image:

name: Build pipeline image

needs: build-dependencies-image
runs-on: cfa-cdcgov

outputs:
tag: ${{ needs.build-dependencies-image.outputs.tag }}

steps:

- name: Login to the Container Registry
uses: docker/login-action@v3
with:
registry: "cfaprdbatchcr.azurecr.io"
username: "cfaprdbatchcr"
password: ${{ secrets.CFAPRDBATCHCR_REGISTRY_PASSWORD }}

- name: Build and push model pipeline image for Azure batch
id: build_and_push_model_image
uses: docker/build-push-action@v6
with:
push: true # This can be toggled manually for tweaking.
no-cache: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build-dependencies-image.outputs.tag }}
file: ./Dockerfile
build-args: |
TAG=${{ needs.build-dependencies-image.outputs.tag }}
username: cfaprdbatchcr
image: ${{ env.IMAGE_NAME }}
first-step-cache-key: docker-dependencies-${{ runner.os }}-${{ hashFiles('./DESCRIPTION', './Dockerfile-dependencies') }}

batch-pool:

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG TAG=local

# This requires access to the Azure Container Registry
FROM cfaprdbatchcr.azurecr.io/cfa-epinow2-pipeline-dependencies:${TAG}
FROM cfaprdbatchcr.azurecr.io/cfa-epinow2-pipeline:${TAG}
micahwiesner67 marked this conversation as resolved.
Show resolved Hide resolved

# Will copy the package to the container preserving the directory structure
COPY . pkg/
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CFAEpiNow2Pipeline v0.2.0

## Features
* Refactored GH Actions container build to cfa-actions 2-step build
* Creating SOP.md to document weekly run procedures
* Allows unique job_ids for runs.
* Makefile supports either docker or podman as arguments to setup & manage containers.
Expand Down
Loading