-
Notifications
You must be signed in to change notification settings - Fork 2
236 lines (204 loc) · 8.05 KB
/
build-deploy-elixir.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: Build and Deploy sub-action elixir
on:
workflow_call:
inputs:
env:
required: true
type: string
awk:
required: true
type: string
rails:
required: false
type: string
default: echo "continuing."
branch:
required: false
type: string
default: ${{ github.ref }}
update_version:
required: true
type: boolean
default: true
cloud_deploy:
required: true
type: boolean
default: false
gcp_project_id:
required: false
type: string
token_secret_name:
required: false
type: string
secrets:
GH_PAT:
description: 'needed for github login'
required: true
DOCKER:
description: 'needed for registry login'
required: false
KUBE_CONFIG:
description: 'needed for kube setup'
required: false
GH_GCP_TOKEN:
description: 'needed for gcp login'
required: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
ssh-key: ${{ secrets.GH_PAT }}
- name: Set Repo Name
run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV
- name: Install Volta
run: |
curl -sSLf https://get.volta.sh | bash
echo "$HOME/.volta/bin" >> $GITHUB_PATH
- name: Log Node and Npm Versions
run: |
echo node version $(node -v)
echo npm version $(npm -v)
- name: Install yq
run: sudo snap install yq
- name: get Version
run: echo "VERSION=$(sudo yq eval '.version' package.json -o yaml)" >> $GITHUB_ENV
- name: Sanity Check Branch
run: ${{ inputs.rails }}
- name: Sync Chart.yaml version
run: yq eval -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml
- name: Sync values.yaml version
run: yq eval -i ".quaiDashboardApi.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: quaibuild
password: ${{ secrets.DOCKER }}
- name: Build Docker
run: docker build --build-arg BUILD_ENV=${{ inputs.env }} -t quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }} .
- name: Push to Docker Hub
run: docker push quainetwork/${{ env.REPO_NAME }}:${{ env.VERSION }}
- name: git tag
if: ${{ inputs.update_version }}
run: git tag ${{ env.VERSION }} && HUSKY=0 git push origin tag ${{ env.VERSION }}
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ inputs.update_version }}
with:
branch: ${{ inputs.branch }}
env:
HUSKY: 0
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
ssh-key: ${{ secrets.GH_PAT }}
- name: Authenticate to Google Cloud
if: ${{ !inputs.skip_deploy && inputs.gcp_project_id != '' && inputs.token_secret_name != '' }}
uses: google-github-actions/auth@v0.4.0 # Use the latest version available
with:
credentials_json: ${{ secrets.GH_GCP_TOKEN }}
- name: Setup Cloud SDK
if: ${{ !inputs.skip_deploy && inputs.gcp_project_id != '' && inputs.token_secret_name != '' }}
uses: google-github-actions/setup-gcloud@v2.0.0
- name: Access Secret from Secret Manager
if: ${{ !inputs.skip_deploy && inputs.gcp_project_id != '' && inputs.token_secret_name != '' }}
run: |
SECRET_NAME="${{ inputs.token_secret_name }}" # The name of your secret in Secret Manager
PROJECT_ID="${{ inputs.gcp_project_id }}" # Your GCP project ID
# Retrieve the secret value
SECRET_VALUE=$(gcloud secrets versions access latest --secret="${SECRET_NAME}" --project="${PROJECT_ID}")
# set the secret value as an environment variable
echo "TOKEN=$SECRET_VALUE" >> $GITHUB_ENV
- name: Install Volta
run: |
curl -sSLf https://get.volta.sh | bash
echo "$HOME/.volta/bin" >> $GITHUB_PATH
- name: Log Node and Npm Versions
run: |
echo node version $(node -v)
echo npm version $(npm -v)
- name: Prepare KUBE_CONFIG
id: prepare_kubeconfig
if: ${{ !inputs.skip_deploy && inputs.cloud_deploy }}
run: |
echo "${{ secrets.KUBE_CONFIG }}" > ${{ github.workspace }}/kubeconfig
if [ -n "${{ env.TOKEN }}" ]; then
sed -i 's|token:.*|token: ${{ env.TOKEN }}|' ${{ github.workspace }}/kubeconfig
fi
## set kubeconfig contents to env variable in gh
KUBECONFIG_CONTENT=$(cat ${{ github.workspace }}/kubeconfig)
echo "KUBECONFIG_CONTENT<<EOF" >> $GITHUB_ENV
echo "$KUBECONFIG_CONTENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: bash
- name: Deploy to cloud
uses: WyriHaximus/github-action-helm3@v3
if: ${{ inputs.cloud_deploy && !inputs.skip_deploy }}
id: deploy
continue-on-error: true
with:
exec: helm upgrade ${{ env.REPO_NAME }} ./helm --install --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml
kubeconfig: ${{ env.KUBECONFIG_CONTENT }}
- name: Deploy to local from bastion
if: ${{ !inputs.cloud_deploy && !inputs.skip_deploy }}
continue-on-error: true
run: |
echo installing kubectl...
curl -LO "https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
echo kubectl installed
echo setting kubeconfig...
echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig.yaml
if [ -n "${{ env.TOKEN }}" ]; then
sed -i 's|token:.*|token: ${{ env.TOKEN }}|' kubeconfig.yaml
fi
export KUBECONFIG=kubeconfig.yaml
echo kubeconfig set
echo testing kubectl connection...
kubectl get po
echo clearing bastion helm
kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm
echo bastion helm cleared
echo copying helm to bastion...
kubectl cp -n kube-system ./helm $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}"):/helm
echo helm chart copied to bastion
echo deploying helm chart from bastion...
kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- helm upgrade --install ${{ env.REPO_NAME }} ./helm --namespace=${{ inputs.env }} --values=./helm/env/${{ inputs.env }}.values.yaml
echo helm chart deployed!!!
echo cleaning bastion
kubectl exec -it $(kubectl get po -n kube-system -l app=bastion -o jsonpath="{.items[0].metadata.name}") -n kube-system -- rm -rf helm
echo bastion helm cleared
echo bastion cleaned up
- name: Install yq
run: sudo snap install yq
- name: get Version
run: echo "VERSION=$(sudo yq eval '.version' package.json -o yaml)" >> $GITHUB_ENV
- name: Update version environment variable
if: ${{ inputs.update_version }}
run: echo "VERSION=$(echo $VERSION | ${{ inputs.awk }})" >> $GITHUB_ENV
- name: Update version
if: ${{ inputs.update_version }}
run: yq eval -i ".version=\"${{ env.VERSION }}\"" package.json -jP
- name: Update Chart.yaml version
if: ${{ inputs.update_version }}
run: yq eval -P -i ".appVersion=\"${{ env.VERSION }}\"" ./helm/Chart.yaml
- name: Update values.yaml version
run: yq eval -P -i ".quaiDashboardApi.image.version=\"${{ env.VERSION }}\"" ./helm/values.yaml
- name: Update package-lock.json
continue-on-error: true
run: npm i --package-lock-only --ignore-scripts
- name: rm kubeconfig
continue-on-error: true
run: rm ${{ github.workspace }}/kubeconfig
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ inputs.update_version }}
with:
branch: ${{ inputs.branch }}
env:
HUSKY: 0