Skip to content

Commit 690cc35

Browse files
committed
Update deployment configuration and values.yaml
1 parent e625fe2 commit 690cc35

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

.github/workflows/cd.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,37 @@ jobs:
9696
- name: Deploy to Kubernetes [PRODUCTION ENVIRONMENT]
9797
run: |
9898
# Get the commit message of the commit that triggered the workflow
99-
COMMIT_MESSAGE=$(git log --format=%B -n 1 ${{ github.event.after }})
100-
99+
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD)
100+
101101
# Check if the app deployment exists
102-
if kubectl get deployments app-release; then
102+
if kubectl get deployments app-release-my-chart-v1 && kubectl get deployments app-release-my-chart-v2; then
103+
# Get the current v1 and v2 image tags from the app deployment in the cluster
104+
CURRENT_V1_IMAGE_TAG=$(kubectl get pods -l app=spring-app -o json | jq -r '.items[] | select(.metadata.name | contains("v1")) | .spec.containers[0].image' | cut -d ":" -f 2 | head -n 1)
105+
CURRENT_V2_IMAGE_TAG=$(kubectl get pods -l app=spring-app -o json | jq -r '.items[] | select(.metadata.name | contains("v2")) | .spec.containers[0].image' | cut -d ":" -f 2 | head -n 1)
106+
107+
echo "Current v1 image tag: $CURRENT_V1_IMAGE_TAG"
108+
echo "Current v2 image tag: $CURRENT_V2_IMAGE_TAG"
109+
103110
# If the commit message starts with [v1], it's an update for v1
104111
if [[ "$COMMIT_MESSAGE" == \[v1\]* ]]; then
105112
echo "Update is for v1. Not setting v2.image.tag."
106-
# Fetch the current v2 image tag from the running pods - this is to ensure the v2.image.tag is not changed from the values.yaml file
107-
CURRENT_V2_IMAGE_TAG=$(kubectl get pods -l app=spring-app -o jsonpath="{.items[0].spec.containers[0].image}" | cut -d ":" -f 2)
108113
# Update the app without changing the v2 image but instead change the v1 image to inputs.image_tag ensure the v2.image.tag is not changed from the values.yaml file
109114
helm upgrade --install app-release ./my-chart --set v1.image.tag=${{ inputs.image_tag }},v2.image.tag=$CURRENT_V2_IMAGE_TAG
110-
111115
else
112116
# If the commit message does not start with [v1], it's an update for v2
113117
echo "Update is for v2. Setting v2.image.tag to: ${{ inputs.image_tag }}."
114118
# Update the app and change the v2 image to inputs.image_tag
115-
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }}
119+
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }},v1.image.tag=$CURRENT_V1_IMAGE_TAG
116120
fi
117121
else
118122
# If the app deployment does not exist
119123
echo "App deployment does not exist. Setting v2.image.tag to: ${{ inputs.image_tag }}."
120-
# Set v2.image.tag to inputs.image_tag regardless of the commit message
124+
# Set v2.image.tag to inputs.image_tag as a new deployment starting point and leave v1.image.tag as the default value in the values.yaml file
121125
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }}
122126
fi
123-
127+
124128
# Wait for 30 seconds
125129
sleep 30
126-
130+
127131
# Get the status of the deployments
128132
kubectl get deployments

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ target/
33
nohup.out
44
.vscode/
55
split_tests.sh
6-
*.db
6+
*.db
7+
test_deployment.sh

my-chart/values.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ v1:
1212
tag: "196"
1313
resources:
1414
limits:
15-
cpu: "0.5"
16-
memory: 256Mi
15+
cpu: "1"
16+
memory: 512Mi
1717
requests:
18-
cpu: 125m
19-
memory: 64Mi
18+
cpu: 250m
19+
memory: 128Mi
2020
v2:
2121
replicas: 4
2222
springAppContainer:
@@ -31,11 +31,11 @@ v2:
3131
tag: "197"
3232
resources:
3333
limits:
34-
cpu: "0.5"
35-
memory: 256Mi
34+
cpu: "1"
35+
memory: 512Mi
3636
requests:
37-
cpu: 125m
38-
memory: 64Mi
37+
cpu: 250m
38+
memory: 128Mi
3939
kubernetesClusterDomain: cluster.local
4040
postgresConfig:
4141
POSTGRES_DB: postgresdb

0 commit comments

Comments
 (0)