|
| 1 | +name: Build, Push, and Deploy to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "dockerAlternative" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + DOCKER_BUILDKIT: 1 |
| 11 | + |
| 12 | + IMAGE_NAME: ghcr.io/aulasoftwarelibre/landingSalmorejoTech2026 |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-push: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event_name == 'push' && github.repository == 'aulasoftwarelibre/landingSalmorejoTech2026' |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + outputs: |
| 22 | + sha_short: ${{ steps.vars.outputs.sha_short }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Get short commit SHA |
| 29 | + id: vars |
| 30 | + run: echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT |
| 31 | + |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v1 |
| 34 | + |
| 35 | + - name: Login to GitHub Container Registry |
| 36 | + uses: docker/login-action@v3 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ github.actor }} |
| 40 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Build and push |
| 43 | + uses: docker/build-push-action@v5 |
| 44 | + with: |
| 45 | + context: . |
| 46 | + file: ./Dockerfile |
| 47 | + push: true |
| 48 | + target: landingSalmorejoTech2026 |
| 49 | + tags: | |
| 50 | + ${{ env.IMAGE_NAME }}:latest |
| 51 | + ${{ env.IMAGE_NAME }}:main |
| 52 | + ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }} |
| 53 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 54 | + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max |
| 55 | + |
| 56 | + update-manifest: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: build-and-push |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Checkout config repository (aulasoftwarelibre/charts) |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + repository: aulasoftwarelibre/charts |
| 65 | + path: charts |
| 66 | + token: ${{ secrets.CHARTS_REPO_PAT }} |
| 67 | + |
| 68 | + - name: Update image tag in frontend-deployment.yaml |
| 69 | + run: | |
| 70 | + sed -i 's|image: ${{ env.IMAGE_NAME }}:.*|image: ${{ env.IMAGE_NAME }}:${{ needs.build-and-push.outputs.sha_short }}|g' charts/landingSalmorejoTech2026/frontend-deployment.yaml |
| 71 | +
|
| 72 | + - name: Commit and push changes |
| 73 | + run: | |
| 74 | + cd charts |
| 75 | + git config --global user.name "github-actions[bot]" |
| 76 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 77 | + git add . |
| 78 | +
|
| 79 | + if ! git diff --staged --quiet; then |
| 80 | + git commit -m "ci: Update frontend image (landingSalmorejoTech2026) to ${{ needs.build-and-push.outputs.sha_short }}" |
| 81 | + git push |
| 82 | + else |
| 83 | + echo "No changes to commit. El YAML ya estaba actualizado." |
| 84 | + fi |
0 commit comments