#156 trigger GH Workflow Docker build-publish #20
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
# Triggers a Docker workflow on push events and PRs but | |
# pushes to DockerHub only for push on the master branch. | |
# | |
# Inspired from: https://github.com/geopython/GeoHealthCheck/blob/master/.github/workflows/docker.yml | |
# Author: Just van den Broecke - 2021 | |
# | |
name: Docker Build ⚓ | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
# NB currently the Notebooks are not in Docker Image! | |
- workshop/jupyter/Dockerfile | |
- workshop/jupyter/entrypoint.sh | |
- workshop/jupyter/requirements.txt | |
- .github/workflows/docker.yml | |
pull_request: | |
paths: | |
# NB currently the Notebooks are not in Docker Image! | |
- workshop/jupyter/Dockerfile | |
- workshop/jupyter/entrypoint.sh | |
- workshop/jupyter/requirements.txt | |
- .github/workflows/docker.yml | |
jobs: | |
# Single job to build Docker Image and push (master-branch only) to DockerHub | |
build_push: | |
name: Build and Push Docker Image to DockerHub | |
runs-on: ubuntu-latest | |
# v2 https://github.com/docker/build-push-action/blob/master/UPGRADE.md | |
steps: | |
- name: Checkout ✅ | |
uses: actions/checkout@v2 | |
- name: Prepare 📦 | |
id: prep | |
run: | | |
DOCKER_IMAGE=geopython/geopython-workshop | |
VERSION=latest | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
echo ::set-output name=image::${DOCKER_IMAGE} | |
echo ::set-output name=version::${VERSION} | |
echo ::set-output name=tags::${TAGS} | |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
- name: Show Image Settings 📦 | |
run: echo "IMAGE=${{ steps.prep.outputs.image }} VERSION=${{ steps.prep.outputs.version }} TAGS=${{ steps.prep.outputs.tags }}" | |
- name: Set up Docker Buildx 📦 | |
uses: docker/setup-buildx-action@v1 | |
- name: Docker Build only - retain local Image 📦 | |
uses: docker/build-push-action@v2 | |
with: | |
context: workshop/jupyter | |
load: true | |
push: false | |
tags: ${{ steps.prep.outputs.tags }} | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
- name: Login to DockerHub 📦 | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push to Docker repo (on GH Push only) ☁️ | |
if: ${{ github.event_name == 'push' }} | |
run: docker push ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.version }} |