From 611ba12b6861c7856fc3b4d2a6be237a7c7a9f00 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Thu, 17 Oct 2024 15:56:30 +0200 Subject: [PATCH] ci(release): implement web deploy to gcp refs #345 --- .github/actions/gcp-deploy/action.yml | 35 +++++++++++++++ .github/workflows/deploy-web-to-gcp.yml | 59 +++++++++++++++++++++++++ .gitignore | 3 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .github/actions/gcp-deploy/action.yml create mode 100644 .github/workflows/deploy-web-to-gcp.yml diff --git a/.github/actions/gcp-deploy/action.yml b/.github/actions/gcp-deploy/action.yml new file mode 100644 index 000000000..6eaf3da86 --- /dev/null +++ b/.github/actions/gcp-deploy/action.yml @@ -0,0 +1,35 @@ +name: Update GCP VM instance container image + +inputs: + instance-name: + description: 'VM instance name' + required: true + image: + description: 'Docker image tag' + required: true + zone: + description: 'GCP zone' + required: true + credentials_json: + description: 'Service account credentials JSON' + required: true + + +runs: + using: "composite" + steps: + - name: 'Authenticate with Google Cloud' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{ inputs.credentials_json }} + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v2' + with: + version: '>= 363.0.0' + + - name: Update image + shell: bash + run: | + gcloud compute instances update-container ${{ inputs.instance-name }} \ + --container-image=${{ inputs.image }} --zone ${{ inputs.zone }}; diff --git a/.github/workflows/deploy-web-to-gcp.yml b/.github/workflows/deploy-web-to-gcp.yml new file mode 100644 index 000000000..97470a364 --- /dev/null +++ b/.github/workflows/deploy-web-to-gcp.yml @@ -0,0 +1,59 @@ +name: Deploy Console Web to GCP + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy' + required: true + type: string + +concurrency: + group: ${{ github.workflow }} + +jobs: + deploy: + name: Define Variables + runs-on: ubuntu-latest + + steps: + - name: Define variables + id: vars + run: | + tag="${{ github.event.inputs.tag }}" + + if [[ ! "$tag" =~ ^console-web/v[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)?$ ]]; then + echo "Invalid tag. Expected console-web/v* or console-web/v*-beta.*" + exit 1 + fi + + version="${tag#*/v}" + + instance_name="" + + if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$ ]]; then + instance_name="${{ vars.BETA_WEB_INSTANCE_NAME }}" + elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + instance_name="${{ vars.PROD_WEB_INSTANCE_NAME }}" + fi + + image="${{ vars.WEB_REGISTRY }}:$version" + + echo "instance-name=${instance_name}" + echo "image=${image}" + + echo "instance-name=${instance_name}" >> "$GITHUB_OUTPUT" + echo "image=${image}" >> "$GITHUB_OUTPUT" + + - name: Checkout repository + if: steps.vars.outputs.instance-name != '' && steps.vars.outputs.image != '' + uses: actions/checkout@v4 + + - name: Deploy + if: steps.vars.outputs.instance-name != '' && steps.vars.outputs.image != '' + uses: ./.github/actions/gcp-deploy + with: + instance-name: ${{ steps.vars.outputs.instance-name }} + image: ${{ steps.vars.outputs.image }} + credentials_json: ${{ secrets.GCP_SA_KEY }} + zone: ${{ vars.GCP_ZONE }} diff --git a/.gitignore b/.gitignore index 754382d11..8828f07c0 100644 --- a/.gitignore +++ b/.gitignore @@ -81,4 +81,5 @@ apps/stats-web/.env # Data Folder data testdata -test-results \ No newline at end of file +test-results +.github/test-data \ No newline at end of file