|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +env: |
| 8 | + DOCKER_IMAGE: moabdelazem/gitops-app |
| 9 | + MANIFESTS_REPO: moabdelazem/gitops-sample-app-manifests |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set build metadata |
| 20 | + id: meta |
| 21 | + run: | |
| 22 | + echo "VERSION=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT |
| 23 | + echo "GIT_COMMIT=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT |
| 24 | + echo "BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT |
| 25 | +
|
| 26 | + - name: Login to Docker Hub |
| 27 | + uses: docker/login-action@v3 |
| 28 | + with: |
| 29 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 30 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Build and push |
| 33 | + uses: docker/build-push-action@v6 |
| 34 | + with: |
| 35 | + context: . |
| 36 | + push: true |
| 37 | + build-args: | |
| 38 | + VERSION=${{ steps.meta.outputs.VERSION }} |
| 39 | + GIT_COMMIT=${{ steps.meta.outputs.GIT_COMMIT }} |
| 40 | + BUILD_TIME=${{ steps.meta.outputs.BUILD_TIME }} |
| 41 | + tags: | |
| 42 | + ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.VERSION }} |
| 43 | + ${{ env.DOCKER_IMAGE }}:latest |
| 44 | +
|
| 45 | + update-manifests: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: build-and-push |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Checkout manifests repo |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + repository: ${{ env.MANIFESTS_REPO }} |
| 54 | + token: ${{ secrets.MANIFESTS_PAT }} |
| 55 | + |
| 56 | + - name: Update dev overlay image tag |
| 57 | + run: | |
| 58 | + cd overlays/dev |
| 59 | + sed -i "s|newTag:.*|newTag: ${GITHUB_SHA::7}|" kustomization.yaml |
| 60 | +
|
| 61 | + - name: Commit and push |
| 62 | + run: | |
| 63 | + git config user.name "github-actions" |
| 64 | + git config user.email "github-actions@github.com" |
| 65 | + git add . |
| 66 | + git commit -m "chore: update dev image to ${GITHUB_SHA::7}" |
| 67 | + git push |
0 commit comments