aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2021-04-18 20:29:44 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2021-04-18 20:29:44 +0300
commit7266137b9f00554f82f31c500c832446a2752fbd (patch)
tree30d8d907b43e476a4fb7db6fc03a02e6c8508a4b
parentcf2e3c99ded0f48bd565858aedc7f10a0d932a61 (diff)
Add workflow
-rw-r--r--.github/workflows/hommabot2.yml83
-rw-r--r--src/index.ts4
-rw-r--r--src/sheets.ts3
3 files changed, 89 insertions, 1 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}
diff --git a/src/index.ts b/src/index.ts
index 4edfc2f..3f0c7ef 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,7 @@
import { App } from "@tinyhttp/app";
import { logger } from "@tinyhttp/logger";
import config from "./config";
+import { broadcast } from "./sheets";
import { bot } from "./tg";
const app = new App({
@@ -20,7 +21,8 @@ app
.get("/", async (_, res) => {
res.send({ service: "hommabot2 API" });
})
- .post("/scheduler/trigger", (_req, res) => {
+ .post("/scheduler/trigger", async (_req, res) => {
+ await broadcast();
res.send({ scheduler: "trigger" });
});
diff --git a/src/sheets.ts b/src/sheets.ts
new file mode 100644
index 0000000..a03e349
--- /dev/null
+++ b/src/sheets.ts
@@ -0,0 +1,3 @@
+export const broadcast = async (): Promise<void> => {
+ // TODO
+};