| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| name: Build And Deploy Playground Backend Application |
| |
| on: |
| push: |
| tags: ['v*'] |
| branches: ['master', 'release-*'] |
| pull_request: |
| paths: ['playground/backend/**'] |
| branches: ['playground-staging'] |
| workflow_dispatch: |
| # This allows a subsequently queued workflow run to interrupt previous runs |
| concurrency: |
| group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' |
| cancel-in-progress: true |
| |
| jobs: |
| build_playground_backend_docker_image: |
| name: Build Playground Backend App |
| runs-on: [self-hosted, ubuntu-20.04] |
| env: |
| GO_VERSION: 1.19.3 |
| BEAM_VERSION: 2.40.0 |
| TERRAFORM_VERSION: 1.0.9 |
| STAND_SUFFIX: '' |
| DATASTORE_EMULATOR_HOST: 127.0.0.1:8888 |
| steps: |
| - name: Check out the repo |
| uses: actions/checkout@v3 |
| - name: Set up Java |
| uses: actions/setup-java@v3.8.0 |
| with: |
| distribution: 'zulu' |
| java-version: '8' |
| - uses: actions/setup-go@v3 |
| with: |
| go-version: '${{ env.GO_VERSION }}' |
| - name: Install dependencies |
| run: sudo apt update && sudo apt install libsnmp-dev -y |
| - name: Remove default github maven configuration |
| # This step is a workaround to avoid a decryption issue |
| run: rm ~/.m2/settings.xml |
| - name: Install sbt for running SCIO tests |
| run: | |
| echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list &&\ |
| echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list &&\ |
| curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add |
| sudo apt-get update && sudo apt-get install -y sbt |
| - name: Set up Cloud SDK and its components |
| uses: google-github-actions/setup-gcloud@v0 |
| with: |
| install_components: 'beta,cloud-datastore-emulator' |
| version: '389.0.0' |
| |
| - name: Run PreCommit |
| run: ./gradlew playground:backend:precommit |
| - uses: hashicorp/setup-terraform@v1 |
| with: |
| terraform_version: ${{ env.TERRAFORM_VERSION }} |
| if: startsWith(github.ref, 'refs/tags/') |
| - name: Set Docker Tag |
| run: echo "DOCKERTAG=${GITHUB_SHA}" >> $GITHUB_ENV |
| - name: Set Docker Tag If Github Tag was trigger |
| run: echo "DOCKERTAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| if: startsWith(github.ref, 'refs/tags/') |
| - name: Setup GCP account |
| run: | |
| echo "${{ secrets.GCP_PLAYGROUND_SA_KEY }}" | base64 -d > /tmp/gcp_access.json |
| if: startsWith(github.ref, 'refs/tags/') |
| - name: Login to Docker Registry |
| run: cat /tmp/gcp_access.json | docker login -u _json_key --password-stdin https://${{ secrets.PLAYGROUND_REGISTRY_NAME }} |
| if: startsWith(github.ref, 'refs/tags/') |
| - name: Deploy Backend Applications |
| env: |
| GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp_access.json |
| run: ./gradlew playground:terraform:deployBackend -Pdocker-tag=${{env.DOCKERTAG}} -Pproject_id=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }} -Pproject_environment='beta' -Pdocker-repository-root='${{ secrets.PLAYGROUND_REGISTRY_NAME}}/${{ secrets.GCP_PLAYGROUND_PROJECT_ID }}/playground-repository' |
| if: startsWith(github.ref, 'refs/tags/') |
| - name: DB Index creation |
| run: | |
| gcloud auth activate-service-account --project=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }} --key-file=/tmp/gcp_access.json |
| gcloud app deploy playground/index.yaml --project=${{ secrets.GCP_PLAYGROUND_PROJECT_ID }} |
| if: startsWith(github.ref, 'refs/tags/') |
| env: |
| GOOGLE_APPLICATION_CREDENTIALS: /tmp/gcp_access.json |