Skip to content

Commit

Permalink
PR for #320 use v2 of docker-build-push action (#357)
Browse files Browse the repository at this point in the history
* #320 first version Docker Build Push GH Action

* #320 2nd version Docker Build Push GH Action

* #320 2ndversion Docker Build Push GH Action textedit

* #320 use v2 Docker Build Push GH Action

* #320 use v2 Docker Build Push GH Action remove comments

* #320 use v2 Docker Build Push GH Action fix yaml error

* #320 use v2 Docker Build Push GH Action badge

* #320 use v2 Docker Build Push GH Run GHC Unit Tests in Docker

* #320 use v2 Docker Build Push try load Docker Image in build env

* #320 use v2 Docker Build Push - finalize

* #320 use v2 Docker Build Push - comments only
  • Loading branch information
justb4 committed Apr 27, 2021
1 parent a9df96b commit c943239
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
78 changes: 56 additions & 22 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Docker Build and Push to DockerHub
name: Docker Build

# Controls when the action will run. Triggers the workflow on push
# events and PRs but only for the master branch
# Triggers a Docker workflow on push events and PRs but
# pushes to DockerHub only for push on the master branch.
# Runs GHC unit tests before DockerHub push.
#
# Author: Just van den Broecke - 2021
#
on:
push:
branches:
Expand All @@ -10,34 +14,64 @@ on:
- '**.md'

pull_request:
branches:
- master
paths-ignore:
- '**.md'

# Ignore PRs (permission problem for DockerHub)
# pull_request:
# branches: [ master ]

jobs:
# Single job now to build Docker Image and push to DockerHub
push_to_registry:
name: Build and Push Docker Image to Docker Hub
# The type of runner that the job will run on
# Single job now to build Docker Image, run GHC unit tests, and push to DockerHub
build_test_push:

name: Build, Test and Push Docker Image to DockerHub

runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
# v2 https://github.com/docker/build-push-action/blob/master/UPGRADE.md
steps:
- name: Check out the repo
- name: Checkout
uses: actions/checkout@v2

# TODO v2 is almost out with new syntax
- name: Push to Docker Hub
uses: docker/build-push-action@v1
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=geopython/geohealthcheck
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
TAGS="${DOCKER_IMAGE}:${VERSION}"
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: 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 }}
repository: geopython/geohealthcheck
tags: latest
# tag_with_ref: true
# tag_with_sha: true

- name: Docker Build, Docker Push (on GH Push only)
uses: docker/build-push-action@v2
with:
context: .
load: true
push: ${{ github.event_name != 'pull_request' }}
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: GHC Unit Tests with Docker Image
run: docker run --entrypoint "/run-tests.sh" geopython/geohealthcheck:${{ steps.prep.outputs.version }}

- name: Push to Docker repo (on GH Push only)
if: ${{ github.event_name == 'push' }}
run: docker push geopython/geohealthcheck:${{ steps.prep.outputs.version }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/geopython/GeoHealthCheck.png)](https://travis-ci.org/geopython/GeoHealthCheck)
[![Join the chat at https://gitter.im/geopython/GeoHealthCheck](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/geopython/GeoHealthCheck)
[![Docker Build](https://img.shields.io/docker/automated/geopython/geohealthcheck.svg)](https://hub.docker.com/r/geopython/geohealthcheck)
[![Docker Build](https://github.com/geopython/GeoHealthCheck/actions/workflows/docker.yml/badge.svg)](https://github.com/geopython/GeoHealthCheck/actions/workflows/docker.yml)
[![Full Documentation](https://img.shields.io/badge/ReadTheDocs-online-green.svg)](http://docs.geohealthcheck.org)

GeoHealthCheck
Expand Down

0 comments on commit c943239

Please sign in to comment.