-
Notifications
You must be signed in to change notification settings - Fork 1
108 lines (97 loc) · 5.09 KB
/
cloud-deploy.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
# This workflow deploys docker images on a local kubernetes cluster.
name: Deploy K8s to Cloud
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "assets/**"
- ".github/**"
- "!.github/workflows/build.yml"
- "README.md"
- "CODE_OF_CONDUCT.md"
- "CONTRIBUTING.md"
- "LICENSE"
- "SECURITY.md"
permissions:
id-token: write
contents: read
packages: write
jobs:
local_test:
uses: ./.github/workflows/local-deploy.yml
secrets: inherit
with:
DATABASE_USER: ${{ vars.DATABASE_USER }}
DATABASE_NAME: ${{ vars.DATABASE_NAME }}
RABBITMQ_USER: ${{ vars.RABBITMQ_USER }}
API_TOKEN_EXPIRY_DAYS: ${{ vars.API_TOKEN_EXPIRY_DAYS }}
deploy:
needs: local_test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
create_credentials_file: 'true'
workload_identity_provider: "projects/${{ secrets.GCP_PROJECT_NUM }}/locations/global/workloadIdentityPools/${{ secrets.GCP_WORKLOAD_IDENTITY_POOL }}/providers/github"
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Get GKE Credentials
uses: 'google-github-actions/get-gke-credentials@v1'
with:
cluster_name: 'stocksalot-cluster'
location: 'us-central1'
- name: Delete Existing Configmaps and Secrets
run: kubectl delete configmaps,secrets --all
- name: Create Configmaps and Secrets
run: |
kubectl create configmap db-config \
--from-literal=DATABASE_USER=${{ vars.DATABASE_USER }} \
--from-literal=DATABASE_NAME=${{ vars.DATABASE_NAME }}
kubectl create configmap db-server-config \
--from-literal=DATABASE_USER=${{ vars.DATABASE_USER }} \
--from-literal=DATABASE_NAME=${{ vars.DATABASE_NAME }} \
--from-literal=RABBITMQ_USER=${{ vars.RABBITMQ_USER }} \
--from-literal=API_TOKEN_EXPIRY_DAYS=${{ vars.API_TOKEN_EXPIRY_DAYS }}
kubectl create configmap ingestion-config \
--from-literal=RABBITMQ_USER=${{ vars.RABBITMQ_USER }}
kubectl create configmap init-script-config \
--from-file=initdb.sh=./database/init/initdb.sh
kubectl create configmap rabbitmq-config \
--from-literal=RABBITMQ_DEFAULT_USER=${{ vars.RABBITMQ_USER }}
kubectl create secret generic db-secrets \
--from-literal=POSTGRES_PASSWORD=${{ secrets.DATABASE_PASSWORD }}
kubectl create secret generic db-server-secrets \
--from-literal=DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }} \
--from-literal=RABBITMQ_PASSWORD=${{ secrets.RABBITMQ_PASSWORD }} \
--from-literal=API_TOKEN_SECRET=${{ secrets.API_TOKEN_SECRET }} \
--from-literal=GPT_API_KEY=${{ secrets.GPT_API_KEY }}
kubectl create secret generic ingestion-secrets \
--from-literal=RABBITMQ_PASSWORD=${{ secrets.RABBITMQ_PASSWORD }} \
--from-literal=TWELVEDATA_API_KEY_1=${{ secrets.TWELVEDATA_API_KEY_1 }} \
--from-literal=TWELVEDATA_API_KEY_2=${{ secrets.TWELVEDATA_API_KEY_2 }} \
--from-literal=FINNHUB_API_KEY=${{ secrets.FINNHUB_API_KEY }}
kubectl create secret generic rabbitmq-secrets \
--from-literal=RABBITMQ_DEFAULT_PASS=${{ secrets.RABBITMQ_PASSWORD }}
kubectl create secret docker-registry ghcr \
--docker-server=https://ghcr.io \
--docker-username=${{ github.actor }} \
--docker-password=${{ secrets.GHCR_PAT }} \
--docker-email=${{ github.event.pusher.email }}
echo "${{ secrets.STOCKSALOT_TLS_KEY }}" > stocksalot-tls.key
echo "${{ secrets.STOCKSALOT_TLS_CERT }}" > stocksalot-tls.crt
kubectl create secret tls stocksalot-tls \
--key=stocksalot-tls.key \
--cert=stocksalot-tls.crt
echo "${{ secrets.API_STOCKSALOT_TLS_KEY }}" > api-stocksalot-tls.key
echo "${{ secrets.API_STOCKSALOT_TLS_CERT }}" > api-stocksalot-tls.crt
kubectl create secret tls api-stocksalot-tls \
--key=api-stocksalot-tls.key \
--cert=api-stocksalot-tls.crt
- name: Apply Kubernetes Manifests
run: |
kubectl apply -f k8s | grep -v unchanged
kubectl rollout restart deploy