2121 - ' projects/eks-flux/app'
2222
2323jobs :
24- version-calculator :
25- runs-on : ubuntu-latest
26- outputs :
27- new-version : ${{ steps.get-version.outputs.NEW_VERSION }}
28- steps :
29- - name : Get latest version from Docker Hub
30- id : get-version
31- run : |
32- # Get auth token if needed (for private repos)
33- # TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:anvesh35/eks-flux-project-app:pull" | jq -r .token)
34-
35- # Get all tags
36- TAGS=$(curl -s "https://hub.docker.com/v2/repositories/anvesh35/eks-flux-project-app/tags/?page_size=100" | jq -r '.results[].name')
37-
38- # Filter and sort semantic versions
39- LATEST=$(echo "$TAGS" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
40-
41- # Set default if no versions found
42- if [ -z "$LATEST" ]; then
43- LATEST="v0.0.0"
44- fi
45-
46- # Remove 'v' prefix and split version
47- VERSION=${LATEST#v}
48- IFS=. read MAJOR MINOR PATCH <<<"$VERSION"
49-
50- # Determine bump type
51- case "${{ inputs.bump-type || 'minor' }}" in
52- major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;;
53- minor) MINOR=$((MINOR+1)); PATCH=0 ;;
54- patch) PATCH=$((PATCH+1)) ;;
55- esac
56-
57- NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
58- echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
59-
6024 build-push-update :
61- needs : version-calculator
6225 runs-on : ubuntu-latest
6326 steps :
6427 - name : Checkout code (with all branches)
6528 uses : actions/checkout@v3
6629 with :
6730 fetch-depth : 0
6831 ref : feature/eksFluxCDProject
32+
33+ - name : Prepare version
34+ id : prep
35+ run : |
36+ if [[ $GITHUB_REF == refs/tags/* ]]; then
37+ VERSION=${GITHUB_REF#refs/tags/}
38+ BUILD_IMAGE=true
39+ else
40+ VERSION=${GITHUB_SHA::8}
41+ BUILD_IMAGE=true
42+ fi
43+ echo "VERSION=$VERSION" >> $GITHUB_ENV
44+ echo "IMAGE=anvesh35/eks-flux-project-app:$VERSION" >> $GITHUB_ENV
45+ echo "BUILD_IMAGE=$BUILD_IMAGE" >> $GITHUB_ENV
46+
6947
7048 - name : Set up Docker Buildx
7149 uses : docker/setup-buildx-action@v2
8462 push : true
8563 tags : |
8664 anvesh35/eks-flux-project-app:latest
87- anvesh35/eks-flux-project-app:${{ needs.version-calculator.outputs.new-version }}
65+ anvesh35/eks-flux-project-app:${{ env.VERSION }}
8866 platforms : linux/amd64,linux/arm64
8967 build-args : |
9068 VERSION=${{ env.VERSION }}
69+
70+ - name : Update Kubernetes manifests
71+ run : |
72+ # sed -i "s|image: anvesh35/eks-flux-project-app:.*|image: ${{ env.IMAGE }}|" projects/eks-flux/manifests/app1-deployment.yaml
73+ sed -i "s|image:.*|image: anvesh35/eks-flux-project-app:${{ env.VERSION }}|" projects/eks-flux/manifests/app1-deployment.yaml
74+ git config user.name "FluxCDBot CI"
75+ git config user.email "[email protected] " 76+
77+ - name : Commit and push changes
78+ uses : EndBug/add-and-commit@v7
79+ with :
80+ add : |
81+ - projects/eks-flux/manifests/app1-deployment.yaml
82+ message : " Update image to ${{ env.VERSION }}"
83+ signoff : true
84+ push : true
85+ branch : feature/eksFluxCDProject
86+ author_name : " Fluxcdbot CI"
87+ 88+ # token: ${{ secrets.PR_PAT_TOKEN }}
9189
0 commit comments