From 0ea45e5ec6f0c9c79deea53c8201b6d22ff9a768 Mon Sep 17 00:00:00 2001 From: Eric Rosas Date: Wed, 20 Sep 2023 16:27:33 -0600 Subject: [PATCH] Added workflows for int EPO-8491 Added workflows for int --- .github/workflows/main-pull-request.yaml | 99 ++++++++++++++++++++++++ .github/workflows/main-push.yaml | 53 +++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 .github/workflows/main-pull-request.yaml create mode 100644 .github/workflows/main-push.yaml diff --git a/.github/workflows/main-pull-request.yaml b/.github/workflows/main-pull-request.yaml new file mode 100644 index 00000000..ea2c1e06 --- /dev/null +++ b/.github/workflows/main-pull-request.yaml @@ -0,0 +1,99 @@ +name: 'PR preview to Int' + +on: + pull_request: + types: + - 'opened' + - 'synchronize' + - 'reopened' + - 'closed' + branches: + - 'main' + +jobs: + build-push-deploy: + name: 'Build and Deploy PR preview to Integration' + runs-on: ubuntu-latest + if: ${{ github.event.action != 'closed'}} + + # Checkout the repository to the GitHub Actions runner + steps: + - name: Checkout + uses: actions/checkout@v2 + + # gcloud CLI setup + - name: Login to GCP + uses: google-github-actions/setup-gcloud@v0 + with: + service_account_key: ${{ secrets.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Build Container Image + run: |- + docker build \ + -t "gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }}" \ + --build-arg NEXT_PUBLIC_API_URL=https://investigations-api-dot-edc-int-6c5e.uc.r.appspot.com/api \ + --build-arg EDC_LOGGER_API_URL=https://us-central1-skyviewer.cloudfunctions.net/edc-logger \ + --build-arg CLOUD_ENV=DEV \ + --build-arg NEXT_PUBLIC_BASE_URL=https://investigations-client-dot-edc-int-6c5e.uc.r.appspot.com \ + --build-arg NEXT_PUBLIC_GOOGLE_APP_ID=688095955960-t0fpaj4ec3gh5vsr9lhg8govapk2oeo9.apps.googleusercontent.com \ + . + - name: Configure Docker Auth + run: gcloud --quiet auth configure-docker + + - name: Push Container Image to GCR + run: docker push gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }} + + - name: Get app.yaml + run: gcloud secrets versions access latest --secret=investigations-client-appyaml > app.yaml + + - name: Format version name + id: version_name + run: echo "version_name=$(echo \"${{ github.head_ref }}\" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Deploy branch-tagged version to App Engine + run: |- + gcloud app deploy app.yaml \ + --image-url=gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }} \ + --version=${{ env.version_name }} \ + --no-promote \ + --project=edc-int-6c5e + + - name: Get the version URL + id: get_version + run: echo "version_url=$(gcloud app versions list --uri --service=investigations-client --filter=version.id:${{ env.version_name }})" >> $GITHUB_ENV + + - name: Post the URL to the PR + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + A preview of this PR will be available at ${{ env.version_url }} until the request is closed. + reactions: '+1' + + cleanup: + name: 'Cleanup PR Preview' + runs-on: ubuntu-latest + if: ${{ github.event.action == 'closed'}} + + # Checkout the repository to the GitHub Actions runner + steps: + - name: Checkout + uses: actions/checkout@v2 + + # gcloud CLI setup + - name: Login to GCP + uses: google-github-actions/setup-gcloud@v0 + with: + service_account_key: ${{ secrets.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Format version name + id: version_name + run: echo "version_name=$(echo \"${{ github.head_ref }}\" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + # Destruct! + - name: Destroy version + run: gcloud app versions delete ${{ env.version_name }} --service=investigations-client diff --git a/.github/workflows/main-push.yaml b/.github/workflows/main-push.yaml new file mode 100644 index 00000000..8c89e33e --- /dev/null +++ b/.github/workflows/main-push.yaml @@ -0,0 +1,53 @@ +name: 'Deploy to Int' + +on: + push: + branches: + - 'main' + +jobs: + build-push-deploy: + name: 'Build and Deploy to Integration' + runs-on: ubuntu-latest + + # Checkout the repository to the GitHub Actions runner + steps: + - name: Checkout + uses: actions/checkout@v2 + + # gcloud CLI setup + - name: Login to GCP + uses: google-github-actions/setup-gcloud@v0 + with: + service_account_key: ${{ secrets.SKYVIEWER_INT_SERVICE_ACCOUNT }} + project_id: edc-int-6c5e + export_default_credentials: true + + - name: Build Container Image + run: |- + docker build \ + -t "gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }}" \ + --build-arg NEXT_PUBLIC_API_URL=https://investigations-api-dot-edc-int-6c5e.uc.r.appspot.com/api \ + --build-arg EDC_LOGGER_API_URL=https://us-central1-skyviewer.cloudfunctions.net/edc-logger \ + --build-arg CLOUD_ENV=DEV \ + --build-arg NEXT_PUBLIC_BASE_URL=https://investigations-client-dot-edc-int-6c5e.uc.r.appspot.com \ + --build-arg NEXT_PUBLIC_GOOGLE_APP_ID=688095955960-t0fpaj4ec3gh5vsr9lhg8govapk2oeo9.apps.googleusercontent.com \ + --build-arg NEXT_PUBLIC_CONTACT_FORM_POST_URL= \ + --build-arg NEXT_PUBLIC_PLAUSIBLE_DOMAIN= \ + . + - name: Configure Docker Auth + run: gcloud --quiet auth configure-docker + + - name: Push Container Image to GCR + run: docker push gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }} + + - name: Get app.yaml + run: gcloud secrets versions access latest --secret=investigations-client-appyaml > app.yaml + + - name: Deploy to App Engine + run: |- + gcloud app deploy app.yaml \ + --quiet \ + --image-url=gcr.io/edc-int-6c5e/investigations-client:${{ github.sha }} \ + --promote \ + --project=edc-int-6c5e