-
Notifications
You must be signed in to change notification settings - Fork 1
210 lines (171 loc) · 6.39 KB
/
users-service-deployment.yaml
File metadata and controls
210 lines (171 loc) · 6.39 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
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
name: Pipeline For Users Service Deployment
on:
push:
branches: [main, Init-users-microservice]
env:
KUBE_NAMESPACE: users-service
RELEASE_NAME: team-divops-users-service
HELM_CHART_PATH: ./helm/divops/users-service
IMAGE_REPOSITORY: ghcr.io/aet-devops25/team-divops-users-service
AWS_REGION: us-east-1
jobs:
# TODO: lint java
# linting:
# name: Code Linting
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Setup Biome
# uses: biomejs/setup-biome@v2
# with:
# version: latest
# - name: Run Biome
# working-directory: ./new_server
# run: biome ci .
# TODO: testing java
# testing:
# name: Testing
# runs-on: ubuntu-latest
# needs: linting
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# - name: Setup Node.js
# uses: actions/setup-node@v3
# with:
# node-version: 20 # or your required version
# - name: Install dependencies
# run: npm ci
# working-directory: ./client # if your React app is in /client
# - name: Run tests
# run: npm test
# working-directory: ./client
build-and-push-users-service:
name: Build and Push Users Service Image
runs-on: ubuntu-latest
# TODO: after enabling testing
# needs: testing
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.set-tag.outputs.image_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set IMAGE_TAG to short SHA
id: set-tag
run: echo "IMAGE_TAG=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
- name: Build users service Docker image with both tags
run: docker build -f ./new_server/users/Dockerfile.prod -t ${{ env.IMAGE_REPOSITORY }}:latest -t ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-tag.outputs.image_tag }} ./new_server/users
- name: Push latest tag
run: docker push ${{ env.IMAGE_REPOSITORY }}:latest
- name: Push SHA tag
run: docker push ${{ env.IMAGE_REPOSITORY }}:${{ steps.set-tag.outputs.image_tag }}
deploy-helm:
name: Deploy Helm Chart
runs-on: ubuntu-latest
needs: build-and-push-users-service
env:
IMAGE_TAG: ${{ needs.build-and-push-users-service.outputs.IMAGE_TAG }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Create .kube directory
run: mkdir -p $HOME/.kube
- name: Configure kubeconfig
run: echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
# Deploy DB
- name: Add Bitnami Helm repo
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
- name: Deploy PostgreSQL with Helm
run: |
helm upgrade --install users-service-db bitnami/postgresql \
--namespace users-service --create-namespace \
-f ./.k8s/users-service-db-values.yaml
# Deploy App
- name: Deploy Helm Chart with SHA tag
run: helm upgrade --install $RELEASE_NAME $HELM_CHART_PATH --namespace $KUBE_NAMESPACE --set usersService.image.repository=$IMAGE_REPOSITORY --set usersService.image.tag=$IMAGE_TAG --force --wait
# deploy-aws:
# name: Deploy To AWS EC2
# needs: build-and-push-client-app
# runs-on: ubuntu-latest
# if: ${{ vars.RUN_AWS_DEPLOYMENT == 'true' }}
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
# AWS_REGION: us-east-1
# TF_LOG: ""
# steps:
# - name: Checkout repo
# uses: actions/checkout@v4
# - name: Cache Terraform files
# uses: actions/cache@v3
# with:
# path: |
# ./terraform/terraform.tfstate
# ./terraform/terraform.tfstate.backup
# ./terraform/.terraform
# key: terraform-state-${{ hashFiles('terraform/**/*.tf') }}
# restore-keys: terraform-state-
# - name: Setup Terraform
# uses: hashicorp/setup-terraform@v2
# with:
# terraform_version: 1.5.6
# terraform_wrapper: false
# - name: Terraform Init
# working-directory: ./terraform
# run: terraform init
# - name: Terraform Validate
# working-directory: ./terraform
# run: terraform validate
# - name: Terraform Plan
# working-directory: ./terraform
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: us-east-1
# run: terraform plan -out=tfplan
# - name: Terraform Apply
# working-directory: ./terraform
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# run: terraform apply -auto-approve tfplan
# - name: Output EC2 public IP
# working-directory: ./terraform
# id: ec2-ip
# run: |
# EC2_IP=$(terraform output -raw ec2_public_ip)
# echo "ec2_ip=$EC2_IP" >> $GITHUB_OUTPUT
# - name: Show EC2 Public IP
# run: echo "EC2 Public IP is ${{ steps.ec2-ip.outputs.ec2_ip }}"
# - name: Setup Ansible and run playbook
# working-directory: ./ansible
# run: |
# sudo apt-get update && sudo apt-get install -y ansible
# mkdir -p ~/.ssh
# echo "${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
# chmod 600 ~/.ssh/id_rsa
# ssh-keyscan -H ${{ steps.ec2-ip.outputs.ec2_ip }} >> ~/.ssh/known_hosts
# echo "[ec2]" > inventory.ini
# echo "${{ steps.ec2-ip.outputs.ec2_ip }}" >> inventory.ini
# ansible-playbook -i inventory.ini playbook.yml --private-key ~/.ssh/id_rsa -u ubuntu -b -v