diff --git a/.github/actions/promote_vercel_deployment/action.yml b/.github/actions/promote_vercel_deployment/action.yml index 95df628fcf..beb19e486a 100644 --- a/.github/actions/promote_vercel_deployment/action.yml +++ b/.github/actions/promote_vercel_deployment/action.yml @@ -1,6 +1,6 @@ name: Promote Vercel Deployment description: Promotes the Vercel production deployment whose commit SHA matches - the active ENSIndexer image in the given Railway environment. Ensures exact + the active ENSIndexer image in the given ENSNode environment. Ensures exact version matching between the active ENSNode and the Vercel project. inputs: @@ -16,12 +16,8 @@ inputs: description: "Vercel API token" required: true - railway_token: - description: "Railway API token" - required: true - - railway_environment_id: - description: "Railway environment ID containing the active ENSIndexer image" + ensnode_environment: + description: "ENSNode environment to target (green, blue, or yellow)" required: true runs: @@ -33,6 +29,5 @@ runs: VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }} VERCEL_TEAM_SLUG: ${{ inputs.vercel_team_slug }} VERCEL_TOKEN: ${{ inputs.vercel_token }} - RAILWAY_TOKEN: ${{ inputs.railway_token }} - RAILWAY_ENVIRONMENT_ID: ${{ inputs.railway_environment_id }} + ENSNODE_ENVIRONMENT: ${{ inputs.ensnode_environment }} run: ${{ github.action_path }}/promote_vercel_deployment.sh diff --git a/.github/actions/promote_vercel_deployment/promote_vercel_deployment.sh b/.github/actions/promote_vercel_deployment/promote_vercel_deployment.sh index 002e4635cf..3a73032540 100755 --- a/.github/actions/promote_vercel_deployment/promote_vercel_deployment.sh +++ b/.github/actions/promote_vercel_deployment/promote_vercel_deployment.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Identifies the commit sha of the ENSIndexer image deployed to the active Railway environment +# Identifies the commit sha of the ENSIndexer image deployed to the active ENSNode environment # and promotes the Vercel deployment with that sha to production for the given Vercel project. # Ensures exact version matching between the active ENSNode and the production Vercel deployment. @@ -21,45 +21,44 @@ if [ -z "${VERCEL_TOKEN:-}" ]; then exit 1 fi -if [ -z "${RAILWAY_TOKEN:-}" ]; then - echo "Error: RAILWAY_TOKEN is not set or is empty" +if [ -z "${ENSNODE_ENVIRONMENT:-}" ]; then + echo "Error: ENSNODE_ENVIRONMENT is not set or is empty" exit 1 fi -if [ -z "${RAILWAY_ENVIRONMENT_ID:-}" ]; then - echo "Error: RAILWAY_ENVIRONMENT_ID is not set or is empty" - exit 1 -fi +case "$ENSNODE_ENVIRONMENT" in + green|blue|yellow) + ;; + *) + echo "Error: ENSNODE_ENVIRONMENT must be one of: green, blue, yellow (got: $ENSNODE_ENVIRONMENT)" + exit 1 + ;; +esac -echo "Targeting Railway Environment: $RAILWAY_ENVIRONMENT_ID" +echo "Targeting ENSNode Environment: $ENSNODE_ENVIRONMENT" echo "Targeting Vercel Project: $VERCEL_PROJECT_ID" -# first, get deployed ENSIndexer image from Railway Environment -RAILWAY_SERVICES_OUTPUT=$(curl \ - --request POST \ +# first, get the deployed ENSNode version from the ENSApi indexing-status endpoint +INDEXING_STATUS_URL="https://api.alpha.${ENSNODE_ENVIRONMENT}.ensnode.io/api/indexing-status" +ENSNODE_VERSION=$(curl \ --silent \ --show-error \ - --url https://backboard.railway.app/graphql/v2 \ - --header "Authorization: Bearer $RAILWAY_TOKEN" \ - --header 'Content-Type: application/json' \ - --data "{\"query\": \"{ environment(id: \\\"$RAILWAY_ENVIRONMENT_ID\\\") { serviceInstances { edges { node { source { image } } } } } }\"}") - -if [ $? -ne 0 ]; then - echo "Error: curl command failed. Output:" - echo "$RAILWAY_SERVICES_OUTPUT" - exit 1 -fi + --fail \ + --url "$INDEXING_STATUS_URL" | \ + jq -r '.stackInfo.ensIndexer.versionInfo.ensIndexer') -# get the first ensindexer image -ENSINDEXER_IMAGE=$(echo "$RAILWAY_SERVICES_OUTPUT" | jq -r '.data.environment.serviceInstances.edges[].node.source.image | select(type == "string" and startswith("ghcr.io/namehash/ensnode/ensindexer"))' | head -n1) +echo "Found ENSNode version: $ENSNODE_VERSION" -echo "Found ENSIndexer image: $ENSINDEXER_IMAGE" - -if [ -z "$ENSINDEXER_IMAGE" ]; then - echo "Error: Could not find ENSIndexer image for the environment." +if [ -z "$ENSNODE_VERSION" ] || [ "$ENSNODE_VERSION" = "null" ]; then + echo "Error: Could not resolve ENSNode version from $INDEXING_STATUS_URL" exit 1 fi +# the version is the image tag for the deployed ENSNode images +ENSINDEXER_IMAGE="ghcr.io/namehash/ensnode/ensindexer:${ENSNODE_VERSION}" + +echo "Using ENSIndexer image: $ENSINDEXER_IMAGE" + # get commit sha from labels of the docker image ENSINDEXER_COMMIT_SHA=$(skopeo inspect docker://$ENSINDEXER_IMAGE --override-arch amd64 --override-os linux | jq -r '.Labels."org.opencontainers.image.revision"') diff --git a/.github/workflows/deploy_switch_ensdb_playground_environment.yml b/.github/workflows/deploy_switch_ensdb_playground_environment.yml new file mode 100644 index 0000000000..95e2fdc7b1 --- /dev/null +++ b/.github/workflows/deploy_switch_ensdb_playground_environment.yml @@ -0,0 +1,60 @@ +name: "Deploy: Switch ENSDb Playground Environment" + +permissions: + contents: read + +on: + workflow_dispatch: + inputs: + target: + description: "New ENSDb Playground environment" + required: true + type: choice + options: + - green + - blue + +jobs: + switch-environment: + # NOTE: this needs to run on GH runner because of some obscure skopeo permissions thing + runs-on: ubuntu-latest + name: Switch Environment to ${{ inputs.target }} + env: + TARGET_ENVIRONMENT: ${{ inputs.target }} + REDIS_URL: ${{ secrets.TRAEFIK_REDIS_URL }} + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 1 + + - name: Calculate env variables + run: | + case "$TARGET_ENVIRONMENT" in + "green") + echo "SLACK_TITLE=:large_green_circle: ENSDb Playground GREEN Environment Activated" >> "$GITHUB_ENV" + ;; + "blue") + echo "SLACK_TITLE=:large_blue_circle: ENSDb Playground BLUE Environment Activated" >> "$GITHUB_ENV" + ;; + *) + echo "SLACK_TITLE=:large_red_circle: Unrecognized ENSDb Playground Environment Activated" >> "$GITHUB_ENV" + exit 1 + ;; + esac + + - name: Switch Traefik Routing + run: | + sudo apt update + sudo apt install -y redis-tools + + # ENSDB PLAYGROUND + redis-cli -u $REDIS_URL SET traefik/http/routers/ensdb-playground-router/service "${TARGET_ENVIRONMENT}-ensdb-playground" + + - name: Send Slack Notification + uses: ./.github/actions/send_slack_notification + with: + slack_webhook: ${{ secrets.SLACK_WEBHOOK_URL }} + slack_title: ${{ env.SLACK_TITLE }} + slack_message: "✅ Switch ENSDb Playground environment completed" diff --git a/.github/workflows/deploy_switch_ensnode_environment.yml b/.github/workflows/deploy_switch_ensnode_environment.yml index b6fc485903..9e5721c9d7 100644 --- a/.github/workflows/deploy_switch_ensnode_environment.yml +++ b/.github/workflows/deploy_switch_ensnode_environment.yml @@ -7,12 +7,13 @@ on: workflow_dispatch: inputs: target: - description: "New main environment (green or blue)" + description: "New main environment" required: true type: choice options: - green - blue + - yellow jobs: switch-environment: @@ -23,7 +24,6 @@ jobs: TARGET_ENVIRONMENT: ${{ inputs.target }} REDIS_URL: ${{ secrets.TRAEFIK_REDIS_URL }} VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} steps: - name: Checkout repository @@ -35,15 +35,18 @@ jobs: run: | case "$TARGET_ENVIRONMENT" in "green") - echo "SLACK_TITLE=:large_green_circle: GREEN Environment Activated" >> "$GITHUB_ENV" - echo "RAILWAY_ENVIRONMENT_ID=${{ secrets.GREEN_RAILWAY_ENVIRONMENT_ID }}" >> $GITHUB_ENV + echo "SLACK_TITLE=:large_green_circle: ENSNode GREEN Environment Activated" >> "$GITHUB_ENV" ;; "blue") - echo "SLACK_TITLE=:large_blue_circle: BLUE Environment Activated" >> "$GITHUB_ENV" - echo "RAILWAY_ENVIRONMENT_ID=${{ secrets.BLUE_RAILWAY_ENVIRONMENT_ID }}" >> $GITHUB_ENV + echo "SLACK_TITLE=:large_blue_circle: ENSNode BLUE Environment Activated" >> "$GITHUB_ENV" + ;; + "yellow") + echo "SLACK_TITLE=:large_yellow_circle: ENSNode YELLOW Environment Activated" >> "$GITHUB_ENV" ;; *) - echo "SLACK_TITLE=:large_red_circle: Unrecognized Environment Activated" >> "$GITHUB_ENV" + echo "SLACK_TITLE=:large_red_circle: Unrecognized ENSNode Environment Activated" >> "$GITHUB_ENV" + exit 1 + ;; esac - name: Switch Traefik Routing @@ -86,9 +89,6 @@ jobs: redis-cli -u $REDIS_URL SET traefik/http/routers/lb-header-sepolia-api-router/service "${TARGET_ENVIRONMENT}-sepolia-api" redis-cli -u $REDIS_URL SET traefik/http/routers/lb-header-sepolia-indexer-router/service "${TARGET_ENVIRONMENT}-sepolia-indexer" - # ENSDB PLAYGROUND - redis-cli -u $REDIS_URL SET traefik/http/routers/ensdb-playground-router/service "${TARGET_ENVIRONMENT}-ensdb-playground" - # ENSRAINBOW redis-cli -u $REDIS_URL SET traefik/http/routers/ensrainbow-api-router/service "${TARGET_ENVIRONMENT}-ensrainbow-api" @@ -101,8 +101,7 @@ jobs: vercel_team_slug: namehash vercel_project_id: prj_nKcHTO12hq9kcgascQMq4xokRhwp vercel_token: ${{ secrets.VERCEL_TOKEN }} - railway_token: ${{ secrets.RAILWAY_TOKEN }} - railway_environment_id: ${{ env.RAILWAY_ENVIRONMENT_ID }} + ensnode_environment: ${{ inputs.target }} - name: Promote Example App Vercel Deployment uses: ./.github/actions/promote_vercel_deployment @@ -110,8 +109,7 @@ jobs: vercel_team_slug: namehash vercel_project_id: prj_Ux80vjjNyDfXMNvPEQo4zlx6Eq6D vercel_token: ${{ secrets.VERCEL_TOKEN }} - railway_token: ${{ secrets.RAILWAY_TOKEN }} - railway_environment_id: ${{ env.RAILWAY_ENVIRONMENT_ID }} + ensnode_environment: ${{ inputs.target }} - name: Send Slack Notification uses: ./.github/actions/send_slack_notification