Build Docker-Image #241
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 Docker-Image | |
on: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '0 4 * * 6' | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'Tag Name' | |
required: true | |
default: 'latest' | |
type: string | |
extra_pkgs: | |
description: 'Extra pip packages' | |
required: true | |
default: '-' | |
type: string | |
jobs: | |
build-docker-image: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
env: | |
DOCKER_IMAGE: ghcr.io/oggm/r2d | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
architecture: 'x64' | |
- name: Setup Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Get Image Tag | |
id: tag_name | |
run: | | |
BN="${GITHUB_REF#refs/*/}" | |
TN="${{ github.event.inputs.tag_name }}" | |
[[ "$BN" == "master" ]] && BN="latest" | |
[[ -n "$TN" ]] && BN="$TN" | |
echo "name=${BN}" >> $GITHUB_OUTPUT | |
- name: Install Dependencies | |
run: | | |
pip3 install --upgrade pip setuptools wheel && pip3 install --upgrade git+https://github.com/jupyterhub/repo2docker.git | |
- name: Build r2d Image | |
run: | | |
rm -rf .git .github | |
EP="${{ github.event.inputs.extra_pkgs }}" | |
[[ -z "$EP" ]] && EP="-" | |
docker pull "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" && CACHE_LINE="--cache-from '${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}'" || CACHE_LINE="" | |
jupyter-repo2docker $CACHE_LINE --debug --build-arg EXTRA_PACKAGES="$EP" --user-name jovyan --user-id 1100 --no-run --image-name "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" . || exit -1 | |
- name: Test r2d Image | |
run: | | |
docker run -u 0 --rm --entrypoint /bin/bash "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" pytest --pyargs salem || exit -1 | |
docker run -u 0 --rm --entrypoint /bin/bash "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" pytest --pyargs oggm || exit -1 | |
- name: Login to Dockerhub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Push Image | |
run: | | |
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then | |
DATE_ID="$(date +%Y%m%dT%H%M)" | |
[[ "${{ steps.tag_name.outputs.name }}" == "latest" ]] && DATE_ID="${DATE_ID}-${{ steps.tag_name.outputs.name }}" | |
docker tag "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" "${DOCKER_IMAGE}:${DATE_ID}" | |
docker push "${DOCKER_IMAGE}:${DATE_ID}" | |
fi | |
docker push "${DOCKER_IMAGE}:${{ steps.tag_name.outputs.name }}" |