Skip to content

Commit a6ba9a3

Browse files
Refactor GitHub Actions workflow for Helm CI: Update Docker image tag and Helm values.yaml
1 parent 4505d27 commit a6ba9a3

File tree

1 file changed

+82
-82
lines changed

1 file changed

+82
-82
lines changed

.github/workflows/helm-ci.yaml

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
# name: Helm CI - Build and Update Values.yaml
2-
3-
# on:
4-
# push:
5-
# branches:
6-
# - main
7-
8-
# jobs:
9-
# build-and-push:
10-
# name: Build and Push Docker Image
11-
# runs-on: ubuntu-latest
12-
13-
# outputs:
14-
# image-tag: ${{ steps.meta.outputs.image-tag }}
15-
16-
# env:
17-
# IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
18-
19-
# steps:
20-
# - name: Checkout code
21-
# uses: actions/checkout@v4
22-
23-
# - name: Set up JDK 17
24-
# uses: actions/setup-java@v4
25-
# with:
26-
# distribution: 'temurin'
27-
# java-version: '17'
28-
29-
# - name: Build Spring Boot App
30-
# working-directory: ./app
31-
# run: ./mvnw clean package -DskipTests
32-
33-
# - name: Set up Docker Buildx
34-
# uses: docker/setup-buildx-action@v3
35-
36-
# - name: Login to DockerHub
37-
# uses: docker/login-action@v3
38-
# with:
39-
# username: ${{ secrets.DOCKERHUB_USERNAME }}
40-
# password: ${{ secrets.DOCKERHUB_TOKEN }}
41-
42-
# - name: Build and Push Docker Image
43-
# id: meta
44-
# run: |
45-
# COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
46-
# IMAGE_TAG="main-${COMMIT_SHA}"
47-
48-
# echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
49-
# echo "::set-output name=image-tag::$IMAGE_TAG"
50-
51-
# docker build -t $IMAGE_NAME:$IMAGE_TAG ./app
52-
# docker push $IMAGE_NAME:$IMAGE_TAG
53-
54-
# update-helm-values:
55-
# name: Update Helm Values
56-
# needs: build-and-push
57-
# runs-on: ubuntu-latest
58-
59-
# env:
60-
# IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
61-
# IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
62-
63-
# steps:
64-
# - name: Checkout code
65-
# uses: actions/checkout@v4
66-
67-
# - name: Update image.tag in values.yaml
68-
# run: |
69-
# FILE="helm/springboot-postgres-prod/values.yaml"
70-
# echo "Updating $FILE with image tag $IMAGE_TAG"
71-
72-
# # Replace the image tag line
73-
# sed -i.bak -E "s|tag:.*|tag: \"$IMAGE_TAG\"|" "$FILE"
74-
75-
# - name: Commit and Push changes
76-
# run: |
77-
# git config --global user.name "github-actions"
78-
# git config --global user.email "github-actions@github.com"
79-
80-
# git add helm/springboot-postgres-prod/values.yaml
81-
# git commit -m "Update Helm image tag to $IMAGE_TAG"
82-
# git push
1+
name: Helm CI - Build and Push
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
name: Build and Push Docker Image
11+
runs-on: ubuntu-latest
12+
13+
outputs:
14+
image-tag: ${{ steps.set-tag.outputs.tag }}
15+
16+
env:
17+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v4
25+
with:
26+
distribution: 'temurin'
27+
java-version: '17'
28+
29+
- name: Build Spring Boot App
30+
working-directory: ./app
31+
run: ./mvnw clean package -DskipTests
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Log in to DockerHub
37+
uses: docker/login-action@v3
38+
with:
39+
username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
- name: Set Image Tag
43+
id: set-tag
44+
run: |
45+
COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
46+
TAG="main-${COMMIT_SHA}"
47+
echo "tag=$TAG" >> $GITHUB_OUTPUT
48+
49+
- name: Build and Push Docker Image
50+
run: |
51+
docker build -t $IMAGE_NAME:${{ steps.set-tag.outputs.tag }} ./app
52+
docker push $IMAGE_NAME:${{ steps.set-tag.outputs.tag }}
53+
54+
update-values:
55+
name: Update Helm values.yaml
56+
needs: build-and-push
57+
runs-on: ubuntu-latest
58+
59+
env:
60+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
61+
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
62+
FILE: helm/springboot-postgres-prod/values.yaml
63+
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
68+
- name: Configure Git
69+
run: |
70+
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
71+
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
72+
73+
- name: Update values.yaml
74+
run: |
75+
echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
76+
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
77+
78+
git add "$FILE"
79+
git commit -m "Update image tag to $IMAGE_TAG in Helm values.yaml"
80+
81+
git pull origin auto/helm-update --rebase || true
82+
git push origin HEAD:auto/helm-update-prod --force-with-lease

0 commit comments

Comments
 (0)