|
| 1 | +name: Build Container Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: ['main'] |
| 7 | + paths: |
| 8 | + - 'src/**' |
| 9 | + # pull_request: |
| 10 | + # branches: ['main'] |
| 11 | + |
| 12 | +jobs: |
| 13 | + # ------------------------------------------ job 1 |
| 14 | + build-and-publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + outputs: |
| 18 | + newtag: ${{ steps.export_tag.outputs.sha }} |
| 19 | + shorttag: ${{ steps.export_tag.outputs.short }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Export sha as short tag |
| 23 | + id: export_tag |
| 24 | + run: | |
| 25 | + export "SHA=${{ github.sha }}" |
| 26 | + echo $SHA |
| 27 | + echo "${SHA:0:7}" |
| 28 | + export "SHORT=${SHA:0:7}" |
| 29 | + echo "sha=${{github.sha}}" >> $GITHUB_OUTPUT |
| 30 | + echo "short=${SHORT}" >> $GITHUB_OUTPUT |
| 31 | + |
| 32 | + - name: Build, Tag and Push Docker Image to GHCR |
| 33 | + |
| 34 | + |
| 35 | + # ------------------------------------------ job 2 |
| 36 | + update-deployed-image-tag: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: build-and-publish |
| 39 | + steps: |
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@v3 |
| 42 | + with: |
| 43 | + repository: xgeekshq/xgeeks-nestjs-api_deployment |
| 44 | + token: ${{ secrets.IDP_TOKEN_G }} |
| 45 | + |
| 46 | + - name: Install Kustomize |
| 47 | + uses: imranismail/setup-kustomize@v2 |
| 48 | + |
| 49 | + - name: Kustomize deployment image tag |
| 50 | + env: |
| 51 | + NEW_TAG: ${{ needs.build-and-publish.outputs.newtag }} |
| 52 | + SHORT_TAG: ${{ needs.build-and-publish.outputs.shorttag }} |
| 53 | + run: | |
| 54 | + cd k8s/overlays/dev |
| 55 | + echo $NEW_TAG |
| 56 | + echo $SHORT_TAG |
| 57 | + kustomize edit set image ghcr.io/xgeekshq/xgeeks-nestjs-api:${{ env.SHORT_TAG }} |
| 58 | + git config --local user.email "[email protected]" |
| 59 | + git config --local user.name "CD Action" |
| 60 | + git add . |
| 61 | + git commit -m "ci: update 'xgeeks-nestjs-api' image tag to '${{ env.SHORT_TAG }}' " |
| 62 | + git push |
0 commit comments