Skip to content

Commit babc20e

Browse files
authored
Added github action configuration (#7)
* Create docker-publish.yml * Updated CI test job * Added system prune for builder images
1 parent dcbc26e commit babc20e

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# Publish `master` as Docker `latest` image.
6+
branches:
7+
- master
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
BOT_IMAGE_NAME: playback-enq-bot
18+
REIGSTRATION_IMAGE_NAME: playback-enq-reg
19+
20+
jobs:
21+
# Run tests.
22+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
23+
test:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- name: Run tests
30+
run: |
31+
if [ -f docker-compose.test.yml ]; then
32+
docker-compose --file docker-compose.test.yml build
33+
docker-compose --file docker-compose.test.yml run sut
34+
else
35+
docker build ./bot --file ./bot/Dockerfile
36+
docker build ./registration --file ./registration/Dockerfile
37+
fi
38+
39+
# Push image to GitHub Packages.
40+
# See also https://docs.docker.com/docker-hub/builds/
41+
push:
42+
# Ensure test job passes before pushing image.
43+
needs: test
44+
45+
runs-on: ubuntu-latest
46+
if: github.event_name == 'push'
47+
48+
steps:
49+
- uses: actions/checkout@v2
50+
51+
- name: Build bot image
52+
run: docker build ./bot --file ./bot/Dockerfile --tag $BOT_IMAGE_NAME
53+
54+
- name: Build register image
55+
run: docker build ./bot --file ./registration/Dockerfile --tag $REIGSTRATION_IMAGE_NAME
56+
57+
- name: Log into registry
58+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
59+
60+
- name: Push bot image
61+
run: |
62+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$BOT_IMAGE_NAME
63+
64+
# Change all uppercase to lowercase
65+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
66+
67+
# Strip git ref prefix from version
68+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
69+
70+
# Strip "v" prefix from tag name
71+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
72+
73+
# Use Docker `latest` tag convention
74+
[ "$VERSION" == "master" ] && VERSION=latest
75+
76+
echo IMAGE_ID=$IMAGE_ID
77+
echo VERSION=$VERSION
78+
79+
docker tag $BOT_IMAGE_NAME $IMAGE_ID:$VERSION
80+
docker push $IMAGE_ID:$VERSION
81+
82+
83+
- name: Push registration image
84+
run: |
85+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$REIGSTRATION_IMAGE_NAME
86+
87+
# Change all uppercase to lowercase
88+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
89+
90+
# Strip git ref prefix from version
91+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
92+
93+
# Strip "v" prefix from tag name
94+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
95+
96+
# Use Docker `latest` tag convention
97+
[ "$VERSION" == "master" ] && VERSION=latest
98+
99+
echo IMAGE_ID=$IMAGE_ID
100+
echo VERSION=$VERSION
101+
102+
docker tag $REIGSTRATION_IMAGE_NAME $IMAGE_ID:$VERSION
103+
docker push $IMAGE_ID:$VERSION
104+
105+
- name: Delete builder images
106+
run: |
107+
docker system prune --filter label=stage=builder

0 commit comments

Comments
 (0)