Build User Image #61
Workflow file for this run
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 User Image | |
on: | |
workflow_call: | |
inputs: | |
verstag: | |
type: string | |
required: true | |
latest: | |
type: boolean | |
required: false | |
default: false | |
workflow_dispatch: | |
inputs: | |
gitrev: | |
type: string | |
required: true | |
description: "gitrev: commit-hash (full), tag or branch (branch is not unique and therefore checkout-step could get cached)" | |
verstag: | |
type: string | |
required: true | |
description: "version: PEP440 version-tag of Karabo (incl. leading 'v')" | |
latest: | |
type: boolean | |
required: false | |
default: false | |
description: "tag image as 'latest'?" | |
test: | |
type: boolean | |
required: false | |
default: false | |
description: "install from `gitrev` environment.yaml instead?" | |
env: | |
REGISTRY: ghcr.io | |
IMG_NAME: karabo-pipeline | |
jobs: | |
build-test-and-push-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Get Previous tag | |
uses: actions-ecosystem/action-get-latest-tag@v1 | |
id: get-latest-tag | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup metadata img-name & img-tag | |
shell: bash -l {0} | |
run: | | |
if [[ ${{ github.event_name }} == "workflow_call" ]]; then | |
echo "gitrev=${{ inputs.verstag }}" >> "$GITHUB_ENV" | |
echo "build=user" >> "$GITHUB_ENV" | |
elif [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then | |
echo "gitrev=${{ inputs.gitrev }}" >> "$GITHUB_ENV" | |
if [[ ${{ inputs.test }} == "true" ]]; then | |
echo "build=test" >> "$GITHUB_ENV" | |
else | |
echo "build=user" >> "$GITHUB_ENV" | |
fi | |
else | |
echo "Invalid github-event!" | |
exit 2 | |
fi | |
echo "latest=${{ inputs.latest }}" >> "$GITHUB_ENV" | |
echo "version=${{ inputs.verstag }}" >> "$GITHUB_ENV" | |
REPO_OWNER=${{ github.repository_owner }} | |
echo "IMG_ADDR=${{ env.REGISTRY }}/${REPO_OWNER@L}/${{ env.IMG_NAME }}" >> "$GITHUB_ENV" | |
DEV_STR="dev" | |
if [[ "${{ inputs.verstag }}" == *"$DEV_STR"* ]] && [[ $LATEST_DOCKER == 'true' ]]; then | |
echo "Invalid configuration of workflow-inputs!" | |
exit 2 | |
fi | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ github.repository }} | |
tags: | | |
type=raw, enable=${{ env.latest }}, value=latest | |
type=pep440, pattern={{version}}, value=${{ env.version }} | |
- name: Docker build | |
shell: bash -l {0} | |
run: | | |
docker build \ | |
--build-arg GIT_REV=${{ env.gitrev }} \ | |
--build-arg BUILD=${{ env.build }} \ | |
-f docker/user/Dockerfile \ | |
-t ${{ env.IMG_ADDR }}:${{ env.version }} \ | |
. | |
if [[ ${{ env.latest }} == "true" ]]; then | |
docker tag ${{ env.IMG_ADDR }}:${{ env.version }} ${{ env.IMG_ADDR }}:latest | |
fi | |
- name: Test image | |
run: | # what is installed and the package location relies entirely on the user Dockerfile | |
docker run --rm ${{ env.IMG_ADDR }}:${{ env.version }} bash -c \ | |
'export IS_GITHUB_RUNNER=true RUN_GPU_TESTS=false RUN_NOTEBOOK_TESTS=true; SITE_PKGS=$(pip show karabo-pipeline | grep Location | sed "s/.*\(\/opt\/conda.*\).*/\1/"); mpirun -n 2 pytest --only-mpi; pytest --verbose $SITE_PKGS/karabo/test' | |
- name: Docker push | |
shell: bash -l {0} | |
run: | | |
docker push --all-tags ${{ env.IMG_ADDR }} |