Skip to content

Docker Build

Docker Build #721

Workflow file for this run

# Triggers a Docker workflow on completion of the "build" workflow but
# pushes to DockerHub
#
# Author: Just van den Broecke & Edward Lewis - 2021
#
name: Docker Build
on:
workflow_run:
workflows: ["build ⚙️"]
types: [completed]
jobs:
# Single job now to build Docker Image and push to DockerHub
on-success:
name: Build, Test and Push Docker Image to DockerHub
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
# 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/pycsw
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
if [[ $VERSION == master ]]; then
VERSION=latest
fi
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: Login to DockerHub 📦
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker Build only - retain local Image 📦
uses: docker/build-push-action@v2
with:
context: .
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: Push to Docker repo ☁️
run: docker push ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.version }}
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Print Test Fail
run: echo Tests Failed