-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (84 loc) · 3.06 KB
/
docker-publish.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Docker
on:
push:
# Publish `master` as Docker `latest` image and `bX.Y` as X.Y.
branches:
- master
- b*
# # Publish `v1.2.3` tags as releases.
tags:
- v*
release:
types: [published]
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: osmirnov/radiopadre
REGISTRY: quay.io
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Log into docker registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.QUAYIO_TOKEN }}" | docker login -u="osmirnov+radiopadre_github_ci" --password-stdin $REGISTRY
- name: Build image
run: |
echo github.ref="${{ github.ref }}"
echo IMAGE_NAME=$IMAGE_NAME
docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Push image to docker registry
run: |
IMAGE_ID=$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
RELEASE=""
echo github.ref="github ref is '${{ github.ref }}'"
# Strip "v" prefix from tag name
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
VERSION=$(echo $VERSION | sed -e 's/^v//')
RELEASE=$(echo $VERSION | sed -e 's/\.[0-9]*$/.latest/')
echo "Release $RELEASE"
elif [[ "${{ github.ref }}" == "refs/heads/b"* ]]; then
VERSION=$(echo $VERSION | sed -e 's/^b//')
RELEASE=""
echo "Branch $VERSION: not release"
if [ "${VERSION%.x}" != "$VERSION" ]; then
VERSION="${VERSION%.x}.pre1"
echo "Image name will be $VERSION"
fi
else
echo "Branch ${{ github.ref }} is neither branch nor release"
fi
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $REGISTRY/$IMAGE_ID:$VERSION
docker push $REGISTRY/$IMAGE_ID:$VERSION
if [ "$RELEASE" != "" ]; then
docker tag $IMAGE_NAME $REGISTRY/$IMAGE_ID:$RELEASE
docker push $REGISTRY/$IMAGE_ID:$RELEASE
fi