Repository navigation
151 lines (128 loc) · 4.81 KB
/
Copy pathprod.yml
File metadata and controls
151 lines (128 loc) · 4.81 KB
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
---
name: Prod
on:
release:
types:
- released
- prereleased
jobs:
build:
outputs:
image: ${{ steps.export.outputs.image }}
tag: ${{ steps.export.outputs.tag }}
runs-on: ubuntu-latest
env:
image: cranecloud/database-api
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master # reference branch
- name: Install (Buildx)
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: meta
name: Tag
uses: docker/metadata-action@v3
with:
flavor: |
latest=true
images: ${{ env.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' }}
type=sha,prefix=prod-
- name: Build
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: docker/prod/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
- id: export
name: Export
uses: actions/github-script@v5
with:
script: |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`)
const isRelease = context.eventName === 'release'
let fullUrl
if (isRelease) {
// Pick the full semver tag e.g. 1.16.0
fullUrl = metadata.tags.find((t) => /:\d+\.\d+\.\d+$/.test(t))
} else {
// Pick the sha tag e.g. prod-abc1234
fullUrl = metadata.tags.find((t) => t.includes(':prod-'))
}
if (fullUrl == null) {
core.error('Unable to find tag of image')
} else {
const tag = fullUrl.split(':')[1]
core.setOutput('image', fullUrl)
core.setOutput('tag', tag)
}
Production:
name: Deploy (Production)
needs:
- build
runs-on: ubuntu-latest
env:
namespace: cranecloud-prod
steps:
- name: Clone
uses: actions/checkout@v2
# --- GCP DEPLOYMENT ---
# - name: Login (GCP)
# uses: google-github-actions/auth@v2
# with:
# credentials_json: ${{ secrets.CREDENTIALS_JSON }}
# - name: Install (Gcloud)
# uses: google-github-actions/setup-gcloud@v1
# with:
# project_id: crane-cloud-274413
# install_components: "gke-gcloud-auth-plugin"
# - name: Login (Kubernetes Cluster)
# uses: google-github-actions/get-gke-credentials@v1
# with:
# cluster_name: staging-cluster
# location: us-central1-a
# project_id: crane-cloud-274413
# --- RENU DEPLOYEMENT ---
- uses: azure/k8s-set-context@v1
with:
kubeconfig: ${{ secrets.RENU_KUBECONFIG}}
- name: Add Repo (cranecloud)
run: |
helm repo add cranecloud https://crane-cloud.github.io/helm-charts/
- name: Helm Release
run: |
helm upgrade --install \
database-api cranecloud/cranecloud \
--values helm/values.prod.yaml \
--namespace $namespace \
--set image.tag="${{ needs.build.outputs.tag }}" \
--set environment.DATABASE_URI="${{ secrets.PRODUCTION_DATABASE_URI }}" \
--set environment.JWT_SALT="${{ secrets.PRODUCTION_JWT_SALT }}" \
--set environment.ACTIVITY_LOGGER_URL="${{ secrets.PRODUCTION_ACTIVITY_LOGGER_URL }}" \
--set environment.ADMIN_MYSQL_USER="${{ secrets.PRODUCTION_ADMIN_MYSQL_USER }}" \
--set environment.ADMIN_MYSQL_PASSWORD="${{ secrets.PRODUCTION_ADMIN_MYSQL_PASSWORD }}" \
--set environment.ADMIN_MYSQL_HOST="${{ secrets.PRODUCTION_ADMIN_MYSQL_HOST }}" \
--set environment.ADMIN_MYSQL_PORT="${{ secrets.PRODUCTION_ADMIN_MYSQL_PORT }}" \
--set environment.ADMIN_PSQL_USER="${{ secrets.PRODUCTION_ADMIN_PSQL_USER }}" \
--set environment.ADMIN_PSQL_PASSWORD="${{ secrets.PRODUCTION_ADMIN_PSQL_PASSWORD }}" \
--set environment.ADMIN_PSQL_HOST="${{ secrets.PRODUCTION_ADMIN_PSQL_HOST }}" \
--set environment.ADMIN_PSQL_PORT="${{ secrets.PRODUCTION_ADMIN_PSQL_PORT }}" \
--set environment.MAIL_PASSWORD="${{ secrets.MAIL_PASSWORD }}" \
--timeout=300s
- name: Monitor Rollout
run: |
kubectl rollout status deployment/database-api --timeout=300s --namespace $namespace