1- name : Kustomize CI - Build and Push
2-
3- on :
4- push :
5- branches :
6- - feature/development
7- - development
8-
9- concurrency :
10- group : kustomize-update
11- cancel-in-progress : true
12-
13- jobs :
14- build-and-push :
15- name : Build and Push Docker Image
16- runs-on : ubuntu-latest
17-
18- outputs :
19- image-tag : ${{ steps.set-tag.outputs.tag }}
20-
21- env :
22- IMAGE_NAME : ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
23-
24- steps :
25- - name : Checkout code
26- uses : actions/checkout@v4
27-
28- - name : Set up JDK 17
29- uses : actions/setup-java@v4
30- with :
31- distribution : ' temurin'
32- java-version : ' 17'
33-
34- - name : Build Spring Boot App
35- working-directory : ./app
36- run : ./mvnw clean package -DskipTests
37-
38- - name : Set up Docker Buildx
39- uses : docker/setup-buildx-action@v3
40-
41- - name : Log in to DockerHub
42- uses : docker/login-action@v3
43- with :
44- username : ${{ secrets.DOCKERHUB_USERNAME }}
45- password : ${{ secrets.DOCKERHUB_TOKEN }}
46-
47- - name : Set image tag
48- id : set-tag
49- run : |
50- COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
51- BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
52- TAG="${BRANCH}-${COMMIT_SHA}"
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 }}
59-
60- update-kustomize :
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 }}
68-
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"
81-
82- echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
83-
84- sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
85-
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"
89-
90- git push origin auto/kustomize-update --force
1+ # name: Kustomize CI - Build and Push
2+
3+ # on:
4+ # push:
5+ # branches:
6+ # - feature/development
7+ # - development
8+
9+ # concurrency:
10+ # group: kustomize-update
11+ # cancel-in-progress: true
12+
13+ # jobs:
14+ # build-and-push:
15+ # name: Build and Push Docker Image
16+ # runs-on: ubuntu-latest
17+
18+ # outputs:
19+ # image-tag: ${{ steps.set-tag.outputs.tag }}
20+
21+ # env:
22+ # IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
23+
24+ # steps:
25+ # - name: Checkout code
26+ # uses: actions/checkout@v4
27+
28+ # - name: Set up JDK 17
29+ # uses: actions/setup-java@v4
30+ # with:
31+ # distribution: 'temurin'
32+ # java-version: '17'
33+
34+ # - name: Build Spring Boot App
35+ # working-directory: ./app
36+ # run: ./mvnw clean package -DskipTests
37+
38+ # - name: Set up Docker Buildx
39+ # uses: docker/setup-buildx-action@v3
40+
41+ # - name: Log in to DockerHub
42+ # uses: docker/login-action@v3
43+ # with:
44+ # username: ${{ secrets.DOCKERHUB_USERNAME }}
45+ # password: ${{ secrets.DOCKERHUB_TOKEN }}
46+
47+ # - name: Set image tag
48+ # id: set-tag
49+ # run: |
50+ # COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
51+ # BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
52+ # TAG="${BRANCH}-${COMMIT_SHA}"
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 }}
59+
60+ # update-kustomize:
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 }}
68+
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"
81+
82+ # echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
83+
84+ # sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
85+
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"
89+
90+ # git push origin auto/kustomize-update --force
9191
9292
9393
0 commit comments