-
Notifications
You must be signed in to change notification settings - Fork 1
187 lines (159 loc) · 5.82 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Docker
on:
push:
# Publish `main` as Docker `latest` image.
branches: [main]
# Publish `v1.2.3` tags as releases.
tags: [v*]
release:
# Publish a GitHub release as image.
types: [created]
pull_request:
branches: [main]
workflow_dispatch:
env:
IMAGE_NAME: strapi
DOCKER_REGISTRY: docker.pkg.github.com
REPO_NAME: ${{ github.event.repository.name }} # like 'myreponame'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
# When pushing a tag, make sure the CHANGELOG.md is updated. This content will be used later on when creating a release.
Changelog:
runs-on: ubuntu-latest
name: Checks CHANGELOG.md for updates
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: mwcodebase/[email protected]
with:
tracked_files: 'CHANGELOG.md'
Build:
name: Build and push image
runs-on: ubuntu-latest
outputs:
image_id: ${{ steps.push.outputs.image_id }}
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} --password-stdin
- name: Push image
id: push
run: |
# Like docker.pkg.github.com/nonameolsson/timeline-backend/strapi
IMAGE_ID=${DOCKER_REGISTRY}/${GITHUB_REPOSITORY}/${IMAGE_NAME}
# Change all uppercase to lowercase and dashes to underscores
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]' | tr '-' '_')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# This will only run on a tag
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# This will only run on pull request
# Add 'staging' tag
[[ "${{ github.ref }}" == "refs/pull/"* ]] && VERSION=staging
# This will only run on main branch
# Use Docker `latest` tag convention when building on main branch
[ "$VERSION" == "main" ] && VERSION=latest
DATE_BUILDNUMBER=$(date +%Y%m%d).$GITHUB_RUN_NUMBER
echo GITHUB_REF=$GITHUB_REF
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$DATE_BUILDNUMBER
docker push $IMAGE_ID --all-tags
echo "::set-output name=image_id::$IMAGE_ID:$DATE_BUILDNUMBER"
DeployDevelopment:
needs: [Build]
name: Deploy to Development
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
environment:
name: Development
url: 'https://strapi-develop.yourtimeline.app'
steps:
- name: Start deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Development
- name: Deploy to Development
uses: dankore/[email protected]
with:
server: '${{ secrets.CAPROVER_URL }}'
password: '${{ secrets.CAPROVER_PASSWORD }}'
appName: '${{ secrets.CAPROVER_APP }}'
image: '${{ needs.build.outputs.image_id }}'
- name: Update deployment status
uses: bobheadxi/[email protected]
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
DeployStaging:
needs: [Build]
name: Deploy to Staging
if: github.event_name == 'refs/heads/main' # The latest code on main branch
runs-on: ubuntu-latest
environment:
name: Staging
url: 'https://strapi-beta.yourtimeline.app' # Put this in secret
steps:
- name: Start deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Staging
- name: Deploy to Staging
uses: dankore/[email protected]
with:
server: '${{ secrets.CAPROVER_URL }}'
password: '${{ secrets.CAPROVER_PASSWORD }}'
appName: '${{ secrets.CAPROVER_APP }}'
image: '${{ needs.build.outputs.image_id }}'
- name: Update deployment status
uses: bobheadxi/[email protected]
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
DeployProduction:
name: Deploy to Production
needs: [Build]
runs-on: ubuntu-latest
environment:
name: Production
url: 'https://strapi.yourtimeline.app' # Put this in secret
if: github.event_name == 'release'
steps:
- name: Start deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Production
- name: Deploy to production
uses: dankore/[email protected]
with:
server: '${{ secrets.CAPROVER_URL }}'
password: '${{ secrets.CAPROVER_PASSWORD }}'
appName: '${{ secrets.CAPROVER_APP }}'
image: '${{needs.build.outputs.image_id }}'
- name: Update deployment status
uses: bobheadxi/[email protected]
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}