-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (144 loc) · 4.83 KB
/
ci-cd.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
name: ci-cd
on: push
jobs:
# test:
# environment: development
# runs-on: ubuntu-22.04
# container: tyknkd/spark:3.3.2-scala2.13-jdk17-gradle8.7-jammy
# env:
# NEWS_API_KEY: ${{ secrets.NEWS_API_KEY }}
# OS_ENV: container
# PGPASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# POSTGRES_DB: collector_db
# POSTGRES_HOST: db
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# POSTGRES_USER: postgresuser
# RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }}
# RABBITMQ_DEFAULT_USER: rabbituser
# services:
# db:
# image: postgres:16.2
# env:
# POSTGRES_DB: ${{ env.POSTGRES_DB }}
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# POSTGRES_USER: ${{ env.POSTGRES_USER }}
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# ports:
# - 5432:5432
# mq:
# image: rabbitmq:3.13-management
# env:
# RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }}
# RABBITMQ_DEFAULT_USER: ${{ env.RABBITMQ_DEFAULT_USER }}
# ports:
# - 5672:5672
# - 15692:15692
# options: >-
# --health-cmd "rabbitmq-diagnostics check_port_connectivity"
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# steps:
# - name: Install PostgreSQL client
# run: |
# apt update
# apt install -y postgresql-client
#
# - name: Check out repository
# uses: actions/checkout@v4
#
# - name: Initialize databases
# shell: bash
# run: |
# source .env
# chmod +x ./docker-databases/docker-entrypoint-initdb.d/init-additional-db.sh
# ./docker-databases/docker-entrypoint-initdb.d/init-additional-db.sh
#
# - name: Run tests
# shell: bash
# run: |
# source .env
# gradle test
#
# publish:
# needs: test
# if: github.ref == 'refs/heads/main'
# environment: production
# runs-on: ubuntu-22.04
# steps:
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_TOKEN }}
#
# - name: Check out repository
# uses: actions/checkout@v4
#
# - name: Build and push Docker images
# shell: bash
# run: docker compose build --push data-collector data-analyzer web-server
deploy:
# needs: publish
# if: github.ref == 'refs/heads/main'
environment: production
runs-on: ubuntu-22.04
env:
GKE_CLUSTER: news-analyzer-cluster
GKE_ZONE: us-west4-c
DEPLOYMENT_NAME: news-analyzer
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GKE_SA_KEY }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT_ID }}
install_components: kubectl, gke-gcloud-auth-plugin
# - name: Set up GKE credentials
# uses: google-github-actions/get-gke-credentials@v2
# with:
# cluster_name: ${{ env.GKE_CLUSTER }}
# location: ${{ env.GKE_ZONE }}
# credentials: ${{ secrets.GKE_SA_KEY }}
- name: Update Kubernetes secrets
run: |
kubectl create secret generic postgres-password-secret \
--from-literal=postgres-password=${{ secrets.POSTGRES_PASSWORD }} \
--save-config \
--dry-run=client \
-o yaml | kubectl apply -f
kubectl create secret generic mq-password-secret \
--from-literal=mq-password=${{ secrets.RABBITMQ_DEFAULT_PASS }} \
--save-config \
--dry-run=client \
-o yaml | kubectl apply -f
kubectl create secret generic grafana-password-secret \
--from-literal=grafana-password=${{ secrets.GRAFANA_PASSWORD }} \
--save-config \
--dry-run=client \
-o yaml | kubectl apply -f
kubectl create secret generic news-api-key-secret \
--from-literal=news-api-key=${{ secrets.NEWS_API_KEY }} \
--save-config \
--dry-run=client \
-o yaml | kubectl apply -f
- name: Install Helm
run: curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Deploy to GKE
run: |
helm upgrade $DEPLOYMENT_NAME deployment/ \
--install
--wait
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl get services -o wide