Skip to content

Commit baead02

Browse files
committed
Update image tag handling in CD workflow
1 parent 690cc35 commit baead02

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

.github/workflows/cd.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ jobs:
9898
# Get the commit message of the commit that triggered the workflow
9999
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD)
100100
101+
# Extract just the tagname from inputs.image_tag
102+
IMAGE_TAG=$(echo "${{ inputs.image_tag }}" | cut -d ":" -f 2)
103+
101104
# Check if the app deployment exists
102105
if kubectl get deployments app-release-my-chart-v1 && kubectl get deployments app-release-my-chart-v2; then
103106
# Get the current v1 and v2 image tags from the app deployment in the cluster
@@ -110,19 +113,19 @@ jobs:
110113
# If the commit message starts with [v1], it's an update for v1
111114
if [[ "$COMMIT_MESSAGE" == \[v1\]* ]]; then
112115
echo "Update is for v1. Not setting v2.image.tag."
113-
# 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
114-
helm upgrade --install app-release ./my-chart --set v1.image.tag=${{ inputs.image_tag }},v2.image.tag=$CURRENT_V2_IMAGE_TAG
116+
# Update the app without changing the v2 image but instead change the v1 image to IMAGE_TAG ensure the v2.image.tag is not changed from the values.yaml file
117+
helm upgrade --install app-release ./my-chart --set v1.image.tag=$IMAGE_TAG,v2.image.tag=$CURRENT_V2_IMAGE_TAG
115118
else
116119
# If the commit message does not start with [v1], it's an update for v2
117-
echo "Update is for v2. Setting v2.image.tag to: ${{ inputs.image_tag }}."
118-
# Update the app and change the v2 image to 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
120+
echo "Update is for v2. Setting v2.image.tag to: $IMAGE_TAG."
121+
# Update the app and change the v2 image to IMAGE_TAG
122+
helm upgrade --install app-release ./my-chart --set v2.image.tag=$IMAGE_TAG,v1.image.tag=$CURRENT_V1_IMAGE_TAG
120123
fi
121124
else
122125
# If the app deployment does not exist
123-
echo "App deployment does not exist. Setting v2.image.tag to: ${{ inputs.image_tag }}."
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
125-
helm upgrade --install app-release ./my-chart --set v2.image.tag=${{ inputs.image_tag }}
126+
echo "App deployment does not exist. Setting v2.image.tag to: $IMAGE_TAG."
127+
# Set v2.image.tag to IMAGE_TAG as a new deployment starting point and leave v1.image.tag as the default value in the values.yaml file
128+
helm upgrade --install app-release ./my-chart --set v2.image.tag=$IMAGE_TAG
126129
fi
127130
128131
# Wait for 30 seconds

0 commit comments

Comments
 (0)