Skip to content

Commit 12e4fb6

Browse files
Merge pull request #1 from sugesh-cloudops/feature/development
Feature/development
2 parents 7b9630f + a6ba9a3 commit 12e4fb6

File tree

2 files changed

+124
-108
lines changed

2 files changed

+124
-108
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

.github/workflows/kustomize-ci.yaml

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ name: Kustomize CI - Build and Push
33
on:
44
push:
55
branches:
6-
- feature/**
6+
- feature/development
77
- development
88

9+
concurrency:
10+
group: kustomize-update
11+
cancel-in-progress: true
12+
913
jobs:
1014
build-and-push:
1115
name: Build and Push Docker Image
1216
runs-on: ubuntu-latest
1317

18+
outputs:
19+
image-tag: ${{ steps.set-tag.outputs.tag }}
20+
1421
env:
1522
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
1623

@@ -37,41 +44,50 @@ jobs:
3744
username: ${{ secrets.DOCKERHUB_USERNAME }}
3845
password: ${{ secrets.DOCKERHUB_TOKEN }}
3946

40-
- name: Build and Push Docker Image
47+
- name: Set image tag
48+
id: set-tag
4149
run: |
4250
COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
4351
BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
4452
TAG="${BRANCH}-${COMMIT_SHA}"
45-
46-
docker build -t $IMAGE_NAME:$TAG ./app
47-
docker push $IMAGE_NAME:$TAG
53+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
54+
55+
- name: Build and push Docker image
56+
run: |
57+
docker build -t $IMAGE_NAME:${{ steps.set-tag.outputs.tag }} ./app
58+
docker push $IMAGE_NAME:${{ steps.set-tag.outputs.tag }}
4859
4960
update-kustomize:
50-
name: Update Kustomize Overlay
51-
needs: build-and-push
52-
runs-on: ubuntu-latest
61+
name: Update Kustomize Overlay
62+
needs: build-and-push
63+
runs-on: ubuntu-latest
64+
65+
env:
66+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
67+
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
5368

54-
env:
55-
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
56-
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v4
72+
73+
- name: Configure git
74+
run: |
75+
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
76+
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
77+
78+
- name: Update image tag and push to branch
79+
run: |
80+
FILE="kustomize/overlays/dev/patch-deployment-image.yaml"
5781
58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
82+
echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
6183
62-
- name: Update image tag in dev overlay
63-
run: |
64-
FILE="kustomize/overlays/dev/patch-deployment-image.yaml"
84+
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
6585
66-
echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
86+
git checkout -B auto/kustomize-update
87+
git add "$FILE"
88+
git commit -m "Update image tag to $IMAGE_TAG" || echo "No changes to commit"
6789
68-
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
90+
git push origin auto/kustomize-update --force
6991
70-
- name: Commit and push changes
71-
run: |
72-
git config --global user.name ${{ secrets.GIT_USER_EMAIL }}
73-
git config --global user.email ${{ secrets.GIT_USER_NAME }}
7492
75-
git add kustomize/overlays/dev/patch-deployment-image.yaml
76-
git commit -m "Update image tag to $IMAGE_TAG"
77-
git push
93+

0 commit comments

Comments
 (0)