-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (69 loc) · 2.69 KB
/
chat-microservice-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
name: Deploy Chat Microservices changes
on:
push:
branches:
- main
paths:
- 'chat-microservice/**'
env:
GKE_CLUSTER: chat1-405416-gke
GKE_ZONE: us-central1
IMAGE: charlyjazz/chat-microservice
K8_DIR: chat-microservice/k8s
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Check out the repo
uses: actions/checkout@v4
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
- name: 'Use gcloud CLI'
run: 'gcloud info'
- name: setup-gke-gcloud-auth-plugin
uses: simenandre/setup-gke-gcloud-auth-plugin@v1.1.2
- uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: chat-microservice/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Update Deployment Image
run: |
sed -i 's|${{env.IMAGE}}:latest|${{env.IMAGE}}:${{github.ref_name}}|' ${{env.K8_DIR}}/chat-microservice-deployment.yaml
- name: Deploy to GKE
run: |
kubectl apply -f ${{env.K8_DIR}}/chat-db-volume-persistentvolumeclaim.yaml
kubectl apply -f ${{env.K8_DIR}}/cassandra-deployment.yaml
kubectl apply -f ${{env.K8_DIR}}/cassandra-service.yaml
kubectl apply -f ${{env.K8_DIR}}/chat-microservice-config.yaml
echo "Apply the deployment and capture the output"
DEPLOYMENT_OUTPUT=$(kubectl apply -f ${{env.K8_DIR}}/chat-microservice-deployment.yaml)
echo "Check if the output contains 'unchanged'"
if echo "$DEPLOYMENT_OUTPUT" | grep -q 'unchanged'; then
echo "Deployment unchanged. Restarting to pick up possible new Docker image..."
kubectl rollout restart deployment/chat-microservice
fi
kubectl apply -f ${{env.K8_DIR}}/chat-microservice-service.yaml