This repository has been archived by the owner on Sep 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
89 lines (69 loc) · 2.92 KB
/
dockerpublish.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
name: Docker
on:
push:
# Publish `production` and ` tags as releases.
branches:
- production
- staging
# Publish `v1.2.3` tags as releases.
tags:
- v*
env:
FRONTEND_IMAGE_NAME: frontend
BACKEND_IMAGE_NAME: backend
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: |
echo "Test line 1"
echo "Test line 2"
echo "If any of these fail, the build isn't published"
echo "Tests passed"
# 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: Create environment
run: |
# Strip git ref prefix from version
REF=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && REF=$(echo $REF | sed -e 's/^v//')
[ "$REF" == "staging" ] && QUALIFIER=-staging
FRONTEND_IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$FRONTEND_IMAGE_NAME$QUALIFIER
BACKEND_IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$BACKEND_IMAGE_NAME$QUALIFIER
# Use Docker `latest` tag convention if on production or staging
[ "$REF" == "production" ] && VERSION=latest && DOCKERFILE=Dockerfile.production && ENDPOINT=update-prod
[ "$REF" == "staging" ] && VERSION=latest && DOCKERFILE=Dockerfile.staging && ENDPOINT=update-staging
# Change all uppercase to lowercase
FRONTEND_IMAGE_ID=$(echo $FRONTEND_IMAGE_ID | tr '[A-Z]' '[a-z]')
BACKEND_IMAGE_ID=$(echo $BACKEND_IMAGE_ID | tr '[A-Z]' '[a-z]')
echo ::set-env name=ENDPOINT::$ENDPOINT
echo ::set-env name=DOCKERFILE::$DOCKERFILE
echo ::set-env name=FRONTEND_IMAGE_ID::$FRONTEND_IMAGE_ID
echo ::set-env name=BACKEND_IMAGE_ID::$BACKEND_IMAGE_ID
echo ::set-env name=VERSION::$VERSION
- name: Build images
run: |
docker build --no-cache frontend -f frontend/$DOCKERFILE --tag frontend
docker build --no-cache backend --tag backend
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
docker tag frontend $FRONTEND_IMAGE_ID:$VERSION
docker tag backend $BACKEND_IMAGE_ID:$VERSION
docker push $FRONTEND_IMAGE_ID:$VERSION
docker push $BACKEND_IMAGE_ID:$VERSION
- name: Update live site
run: curl --data "token=${{ secrets.DEPLOY_TOKEN }}" https://triggers.osai-web.com/$ENDPOINT