Build User Image #34
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_run: | |
workflows: ["Test User Package"] | |
types: | |
- completed | |
workflow_dispatch: | |
inputs: | |
gitrev: | |
type: string | |
required: true | |
description: "commit, tag or branch (careful with branch if docker-build environment is caching)" | |
verstag: | |
type: string | |
required: true | |
description: "PEP440 conform 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: "Test build? If yes, the environment gets installed from the according `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 }} |