diff options
Diffstat (limited to '.github')
| -rw-r--r-- | .github/workflows/hommabot2.yml | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/.github/workflows/hommabot2.yml b/.github/workflows/hommabot2.yml new file mode 100644 index 0000000..ac389b9 --- /dev/null +++ b/.github/workflows/hommabot2.yml @@ -0,0 +1,83 @@ +name: Deploy Hommabot2 to GCP +on: + push: + branches: + - main + +env: + IMAGE: eu.gcr.io/jan-systems/Hommabot2 + GCP_PROJECT: jan-systems + GCR_SERVICE: hommabot + GCR_PORT: 8080 # Not used in service, but GCR requires a port + GCR_PLATFORM: managed + GCR_REGION: europe-north1 + # Env vars (normally) comma separated. Use @ as separator since TELEGRAM_USER_IDS has commas. + GCR_ENV_VARS: "^@^SHEETS_SPREADSHEET_ID=1eKEcFRQBdM2b-pPxnSUEilAKdHnMUNXZljO_I6iqwBw\ + @SHEETS_RANGE=Aikataulu!A4:C999\ + @TELEGRAM_TOKEN=1617681735:AAFr1314RVQt7giW82yh0DYQKqGl4m_B8gM\ + TELEGRAM_WEBHOOK_URL=https://hommabot2.jan.systems/webhook/telegram\ + PG_CONNECTION_URI=postgresql://hommabot_user:${{ secrets.DATABASE_PASSWORD }}@10.24.240.3/hommabot" + +jobs: + website: + name: Build, Push, and Deploy Hommabot + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Build image tag from the commit SHA + - name: Define image tag + run: echo "TAG=$(date +'%Y.%m.%d')_${GITHUB_SHA:0:6}" >> $GITHUB_ENV + + - name: Define full image identifier + run: echo "IMAGE_AND_TAG=${IMAGE}:${TAG}" >> $GITHUB_ENV + + # Define revision suffix + - name: Define revision suffix + run: echo "GCR_REVISION_SUFFIX=$(echo ${TAG} | sed 's/\./-/g' | sed 's/_/-/g')" >> $GITHUB_ENV + + # Setup gcloud CLI + - name: Set up gcloud CLI + uses: google-github-actions/setup-gcloud@v0.2.0 + with: + service_account_key: ${{ secrets.GCP_SA_KEY }} + project_id: ${{ env.GCP_PROJECT }} + export_default_credentials: true + + # Configure Docker to use the gcloud command-line tool as a credential + # helper for authentication + - name: Configure Docker authentication + run: gcloud --quiet auth configure-docker + + # In this step, this action saves a list of existing images, + # the cache is created without them in the post run. + # It also restores the cache if it exists. + - name: Restore Docker cache + uses: satackey/action-docker-layer-caching@v0.0.11 + # Ignore the failure of a step and avoid terminating the job. + continue-on-error: true + with: + key: hommabot-docker-cache-{hash} + restore-keys: | + hommabot-docker-cache- + + # Build the Docker image + - name: Build image + run: docker build -t ${IMAGE_AND_TAG} . + + # Push the Docker image to Google Container Registry + - name: Push image to registry + run: docker push ${IMAGE_AND_TAG} + + # Deploy to Google Cloud Run + - name: Deploy to Cloud Run + run: |- + gcloud run deploy ${GCR_SERVICE} \ + --region=${GCR_REGION} \ + --platform=${GCR_PLATFORM} \ + --port=${GCR_PORT} \ + --revision-suffix=${GCR_REVISION_SUFFIX} \ + --set-env-vars=${GCR_ENV_VARS} \ + --image=${IMAGE_AND_TAG} |
