From 1564a57f9b28ead39f6e9c3b293dffb3107b01a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Wed, 7 Aug 2024 21:54:41 +0200 Subject: [PATCH] ci: deploy to staging mainnet API app (#601) With new script deployment to DO app will be decided based on the URL that api.snapshot.box currently points to. We use 3dns.box's authoritative nameserver to get latest records. If it's currently pointing to APP_1 we will deploy to APP_2, if it's currently pointing to APP_2 we will deploy to APP_1. --- .github/workflows/deploy.yml | 2 +- scripts/deploy-api-prod.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 scripts/deploy-api-prod.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b7db1208a..f1457d42c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,7 +23,7 @@ jobs: with: token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - name: Deploy if files have changed - run: ./scripts/deploy-changed.sh apps/api ${{ vars.DIGITALOCEAN_APP_ID }} + run: ./scripts/deploy-api-prod.sh deploy_api_testnet: name: Deploy API to testnet diff --git a/scripts/deploy-api-prod.sh b/scripts/deploy-api-prod.sh new file mode 100755 index 000000000..7640c7246 --- /dev/null +++ b/scripts/deploy-api-prod.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -euo pipefail + +NAME_SERVER="ns1.3dns.box" +PRODUCTION_DOMAIN="api.snapshot.box" +APP_DOMAIN_1="sx-api-starknet-mainnet-dfghg.ondigitalocean.app." +APP_DOMAIN_2="sx-api-mainnet-2-fmlg8.ondigitalocean.app" +APP_ID_1="c4eba570-abea-4ab3-8941-d968db6cad36" +APP_ID_2="9282b162-7280-43b9-b429-9f53810003bc" + +CURRENT_DOMAIN=$(dig -t CNAME +short "$PRODUCTION_DOMAIN" @"$NAME_SERVER") + +CURRENT_STAGING_APP_ID="" +if [ "$CURRENT_DOMAIN" = "$APP_DOMAIN_1" ]; then + CURRENT_STAGING_APP_ID=$APP_ID_2 +elif [ "$CURRENT_DOMAIN" = "$APP_DOMAIN_2" ]; then + CURRENT_STAGING_APP_ID=$APP_ID_1 +else + echo "Unknown domain: $CURRENT_DOMAIN" + exit -1 +fi + +echo "Starting deployment to staging app: $CURRENT_STAGING_APP_ID" + +./scripts/deploy-changed.sh apps/api "$CURRENT_STAGING_APP_ID"