From 66f3878061655204d1f69523872e96d250a5fbdc Mon Sep 17 00:00:00 2001 From: Shawn Sorichetti Date: Sat, 4 May 2024 22:04:51 -0400 Subject: [PATCH] GitHub Action to update manifests When a pull request changes, or merges, checkout the metacpan-k8s repository and set the image tag used for the deployment of the web app. Manifests updates during pull request creation or changes ensures that the process continues to work. When the change lands on the trunk branch of the repository is the update sent to the metacpan-k8s repository. The GitHub Application for metacpan is able to bypass the pull request and commit to main, in the metacpan-k8s repository setting. --- .github/workflows/set-image.yaml | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/set-image.yaml diff --git a/.github/workflows/set-image.yaml b/.github/workflows/set-image.yaml new file mode 100644 index 00000000000..e509d41ab78 --- /dev/null +++ b/.github/workflows/set-image.yaml @@ -0,0 +1,49 @@ +name: Update Image with Kustomize +on: + pull_request: + types: + - opened + - reopened + - synchronize + push: + branches: + - master + +jobs: + update-image: + runs-on: ubuntu-latest + + steps: + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Set up Kustomize + uses: imranismail/setup-kustomize@v2 + - name: Checkout Application repository + uses: actions/checkout@v4 + with: + path: app + - name: Checkout Manifests repository + uses: actions/checkout@v4 + with: + repository: metacpan/metacpan-k8s + path: manifests + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + - name: Setup Manifests repository + working-directory: ./manifests + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: Update Image Tag + working-directory: ./manifests/apps/web/environments/prod + run: | + kustomize edit set image "${{ github.repository }}:latest" "${{ github.repository }}:${{ github.sha }}" + git add kustomization.yaml + git commit -m "Update image to ${{ github.sha }}" + - name: Push manifests + if: github.ref == 'refs/heads/master' + working-directory: ./manifests + run: git push origin main