Skip to content

Build User Image

Build User Image #38

name: Build User Image
on:
workflow_run:
workflows: ["Test User Package"]
types:
- completed
workflow_dispatch:
inputs:
gitrev:
type: string
required: true
description: "gitrev: commit (full), tag or branch (branch is not unique and therefore 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
jobs:
build-and-push-image:
runs-on: ubuntu-latest
if: ${{ (github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch') }}
permissions:
contents: read
packages: write
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
# Aussumes that current repo-tag matches karabo:latest on anaconda.org
- 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_run" ]]
then
echo "latest=true" >> "$GITHUB_ENV"
echo "version=${{ steps.get-latest-tag.outputs.tag }}" >> "$GITHUB_ENV"
echo "gitrev=${{ steps.get-latest-tag.outputs.tag }}" >> "$GITHUB_ENV"
echo "build=user" >> "$GITHUB_ENV"
fi
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]
then
echo "latest=${{ inputs.latest }}" >> "$GITHUB_ENV"
echo "version=${{ inputs.verstag }}" >> "$GITHUB_ENV"
echo "gitrev=${{ inputs.gitrev }}" >> "$GITHUB_ENV"
if [[ ${{ inputs.test }} == "true" ]]
then
echo "build=test" >> "$GITHUB_ENV"
else
echo "build=user" >> "$GITHUB_ENV"
fi
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: Build and export to Docker
uses: docker/build-push-action@v5
with:
file: docker/user/Dockerfile
context: .
push: false
build-args: |
GIT_REV=${{ env.gitrev }}
BUILD=${{ env.build }}
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: test
- name: Test container
run: |
docker run --rm ${{ steps.meta.outputs.tags }}:test pytest /opt/conda/lib/python3.9/site-packages/karabo/test
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: docker/user/Dockerfile
context: .
push: true
build-args: |
GIT_REV=${{ env.gitrev }}
BUILD=${{ env.build }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}