-
-
Notifications
You must be signed in to change notification settings - Fork 155
78 lines (69 loc) · 2.68 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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