forked from onflow/CAST
-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (149 loc) · 6.75 KB
/
update-stage.yaml
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
name: UPDATE STAGE
on:
push:
branches:
- staging
env:
db_username: ${{ secrets.DB_USERNAME }}
db_password: ${{ secrets.DB_PASSWORD }}
db_hostname: ${{ secrets.DB_HOSTNAME }}
db_port: ${{ secrets.DB_PORT }}
db_name: ${{ secrets.DB_NAME }}
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
argo_repo: ${{ secrets.ARGO_REPO }}
argo_ref: ${{ secrets.ARGO_REF }}
argo_token: ${{ secrets.ARGO_TOKEN }}
backend_api: ${{ secrets.BACKEND_API }}
tx_options: ${{ secrets.TX_OPTIONS }}
hotjar_site_id: ${{ secrets.HOTJAR_STAGE_ID }}
sentry_url: ${{ secrets.SENTRY_STAGE_URL }}
jobs:
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## MIGRATIONS
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
migrations:
name: Migrations
runs-on: staging-runner
if: "!contains(github.event.head_commit.message, 'cancel migrations')"
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: staging
- name: Install and run migrations
run: |
sudo apt-get update
sudo apt-get -y install curl
sudo apt-get -y install tar
sudo curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xvz && sudo mv migrate /usr/local/bin && sudo chmod +x /usr/local/bin/migrate
sudo migrate -path ./backend/migrations -database 'postgres://${{ env.db_username }}:${{ env.db_password }}@${{ env.db_hostname }}:${{ env.db_port }}/${{ env.db_name }}?sslmode=disable' -verbose up
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## BUILD AND PUSH BACKEND STAGE - ARGO TIME!
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build-and-push-backend:
name: Build and push backend
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'cancel build backend')"
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: staging
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.dockerhub_username }}
password: ${{ env.dockerhub_token }}
- name: Get short SHA
id: short
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: build and push backend - stage -
env:
TAG: ${{ steps.short.outputs.sha7 }}
run: |
cd backend && docker build . -t bruddev/cast-stage:$TAG-be && docker push bruddev/cast-stage:$TAG-be
## ARGO FROM HERE
- name: Clone ArgoManifests
run: |
mkdir -p ./argo
- name: Checkout ArgoManifests
uses: actions/checkout@v3
with:
repository: ${{ env.argo_repo }}
ref: ${{ env.argo_ref }}
token: ${{ env.argo_token }}
path: ./argo
- name: time
id: time
run: echo "::set-output name=time::$(date "+%T")"
- name: Get short SHA
id: short-backend
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: Install Kustomize and update tag
env:
TIME: ${{ steps.time.outputs.time }}
TAG: ${{ steps.short-backend.outputs.sha7 }}
run: |
curl -fL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.5/kustomize_v4.5.5_linux_amd64.tar.gz| tar xz && \
chmod +x kustomize
cd ./argo/voting-tool-stage-prod/backend/environments/stage && kustomize edit set image bruddev/cast-stage:$TAG-be
git config --global user.email "[email protected]"
git config --global user.name "Brunkins"
git commit -am "Added new backend value from GHA $TIME" && git push
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## BUILD AND PUSH FRONTEND STAGE - ARGO TIME!
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
build-and-push-frontend:
name: Build and push frontend
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'cancel build frontend')"
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: staging
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.dockerhub_username }}
password: ${{ env.dockerhub_token }}
- name: Get short SHA
id: short-frontend
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: build and push frontend - stage -
env:
TAG: ${{ steps.short-frontend.outputs.sha7 }}
BACKEND: ${{ env.backend_api }}
TX: ${{ env.tx_options }}
run: |
cd frontend && sed -i -e 's/REPLACE_HOTJAR_SITE_ID/${{ env.hotjar_site_id }}/g' Dockerfile.stage && sed -i -e 's|REPLACE_SENTRY_URL|${{ env.sentry_url }}|g' Dockerfile.stage && docker build -f Dockerfile.stage . -t bruddev/cast-stage:$TAG-fe
docker push bruddev/cast-stage:$TAG-fe
## ARGO FROM HERE
- name: Clone ArgoManifests
run: |
mkdir -p ./argo
- name: Checkout ArgoManifests
uses: actions/checkout@v3
with:
repository: ${{ env.argo_repo }}
ref: ${{ env.argo_ref }}
token: ${{ env.argo_token }}
path: ./argo
- name: time
id: time
run: echo "::set-output name=time::$(date "+%T")"
- name: Get short SHA
id: short
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
- name: Install Kustomize and update tag
env:
TIME: ${{ steps.time.outputs.time }}
TAG: ${{ steps.short.outputs.sha7 }}
run: |
curl -fL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.5/kustomize_v4.5.5_linux_amd64.tar.gz| tar xz && \
chmod +x kustomize
cd ./argo/voting-tool-stage-prod/frontend/environments/stage && kustomize edit set image bruddev/cast-stage:$TAG-fe
git config --global user.email "[email protected]"
git config --global user.name "Brunkins"
git commit -am "Added new frontend value from GHA $TIME" && git push