blob: 5abdca2b341976db6e3cbcdc4d71c81cca94a322 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
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
CLOUDSQL_INSTANCES: jan-systems:europe-north1:pg1
VPC_CONNECTOR: connector1
# 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_BOT_TOKEN=1617681735:AAFr1314RVQt7giW82yh0DYQKqGl4m_B8gM\
&TELEGRAM_WEBHOOK_URL=https://hommabot.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} \
--set-cloudsql-instances=${CLOUDSQL_INSTANCES} \
--vpc-connector=${VPC_CONNECTOR}
|