Skip to content

Build User Image

Build User Image #46

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
jobs:
build-test-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Monitor-disk-sapce-1
shell: bash -l {0}
run: |
echo $(df -h)
- name: Checkout repository
uses: actions/checkout@v4
- name: Monitor-disk-sapce-2
shell: bash -l {0}
run: |
echo $(df -h)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Monitor-disk-sapce-3
shell: bash -l {0}
run: |
echo $(df -h)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Monitor-disk-sapce-4
shell: bash -l {0}
run: |
echo $(df -h)
# 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: Monitor-disk-sapce-5
shell: bash -l {0}
run: |
echo $(df -h)
- 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"
DEV_STR="dev"
if [[ "${{ inputs.verstag }}" == *"$DEV_STR"* ]] && [[ $LATEST_DOCKER == 'true' ]]; then
echo "Invalid configuration of workflow-inputs!"
exit 2
fi
- name: Monitor-disk-sapce-6
shell: bash -l {0}
run: |
echo $(df -h)
- 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: Monitor-disk-sapce-7
shell: bash -l {0}
run: |
echo $(df -h)
- name: Docker build manually
shell: bash -l {0}
run: |
docker build --build-arg GIT_REV=${{ env.gitrev }} --build-arg BUILD=${{ env.build }} -f docker/user/Dockerfile -t karabo-pipeline:${{ env.version }} .
if [[ ${{ env.latest }} == "true" ]]; then
docker tag karabo-pipeline:${{ env.version }} karabo-pipeline:latest
fi
echo $(df -h)
- name: push docker-image
shell: bash -l {0}
run: |
docker logout docker.io
docker push ${{ env.REGISTRY }}/${{ github.actor }}/karabo-pipeline --all-tags
echo $(df -h)
- 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: Monitor-disk-sapce-8
shell: bash -l {0}
run: |
echo $(df -h)
- name: Test container
run: |
docker run --rm ${{ steps.meta.outputs.tags }}:test pytest /opt/conda/lib/python3.9/site-packages/karabo/test
- name: Monitor-disk-sapce-9
shell: bash -l {0}
run: |
echo $(df -h)
- 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 }}
- name: Monitor-disk-sapce-10
shell: bash -l {0}
run: |
echo $(df -h)