-
-
Notifications
You must be signed in to change notification settings - Fork 7
147 lines (119 loc) · 4.84 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# ----------------------------------------------------------------------------------------------------------------------
# Build and Deploy docker images
#
# This action requires the following variables and secrets to be set:
# * vars.PORTAINER_HOST - The deployment username for PORTAINER_HOST
# * secrets.PORTAINER_USERNAME - The deployment username for PORTAINER_HOST
# * secrets.PORTAINER_PASSWORD - The deployment password for PORTAINER_USERNAME
# * secrets.GOOGLE_CLIENT_ID - The Google OAuth 2.0 Client ID
# * secrets.GOOGLE_CLIENT_SECRET - The Google OAuth 2.0 Client Secret
# * secrets.BETA_SESSION_SECRET - The beta site's session secret
# * secrets.PROD_SESSION_SECRET - The prod site's session secret
# ----------------------------------------------------------------------------------------------------------------------
name: Docker
on:
push:
branches:
- master
tags:
- v*
release:
types: [published, prereleased, released]
env:
IMAGE_NAME: rpgkeeper
jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Login to docker hub
if: success()
uses: actions-hub/docker/login@master
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Set ENV Variables.
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo VERSION=$VERSION >> $GITHUB_ENV
- name: Build docker
if: success()
run: |
if [ "$VERSION" == "latest" ]
then
docker build -t morgul/rpgkeeper:latest .
else
docker build -t morgul/rpgkeeper:${VERSION} -t morgul/rpgkeeper:latest .
fi
- name: Push tagged version
if: success() && env.VERSION != 'latest'
uses: actions-hub/docker@master
with:
args: push morgul/rpgkeeper:${VERSION}
- name: Push latest
if: success()
uses: actions-hub/docker@master
with:
args: push morgul/rpgkeeper:latest
# Deploys Beta docker
deploy-beta:
needs: push
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Set ENV Variables.
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo VERSION=$VERSION >> $GITHUB_ENV
- name: Deploy Beta Site
uses: Morgul/portainer-stack-deploy@v1.2.0
with:
portainer-host: ${{ vars.PORTAINER_HOST }}
endpoint-id: 2
username: ${{ secrets.PORTAINER_USERNAME }}
password: ${{ secrets.PORTAINER_PASSWORD }}
stack-name: 'rpgkeeper-beta'
stack-definition: 'compose/beta.yml'
template-variables: '{"client": "${{ secrets.GOOGLE_CLIENT_ID }}", "secret": "${{ secrets.GOOGLE_CLIENT_SECRET }}", "sess": "${{ secrets.BETA_SESSION_SECRET }}"}'
prune-stack: false
pull-image: true
# Deploys prod docker
deploy-prod:
needs: push
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v4
- name: Set ENV Variables.
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo VERSION=$VERSION >> $GITHUB_ENV
- name: Deploy Production Site
uses: Morgul/portainer-stack-deploy@v1.2.0
with:
portainer-host: ${{ vars.PORTAINER_HOST }}
endpoint-id: 2
username: ${{ secrets.PORTAINER_USERNAME }}
password: ${{ secrets.PORTAINER_PASSWORD }}
stack-name: 'rpgkeeper'
stack-definition: 'compose/prod.yml'
template-variables: '{"version": "${{ env.VERSION }}", "client": "${{ secrets.GOOGLE_CLIENT_ID }}", "secret": "${{ secrets.GOOGLE_CLIENT_SECRET }}", "sess": "${{ secrets.PROD_SESSION_SECRET }}"}'
prune-stack: false
pull-image: true