Skip to content

Commit

Permalink
Simplified blockscout deployments (#7737)
Browse files Browse the repository at this point in the history
### Description

Simplifies Blockscout deployments by adding two parameters to the `upgrade` command:
 - `--tag=%commit_hash%` - defines the commit hash to be deployed
 - `--suffix=%db_suffix%` - optional Blockscout instance suffix, default is taken from the corresponding .env file
 
Examples:
```
./bin/celotooljs.sh deploy upgrade blockscout -e alfajores --tag 0362f9f4d1d4842f27adb634d628f969f53c046d --suffix 3 --verbose --helmdryrun
```

### Other changes

- Removes the unused `BLOCKSCOUT_WEB_REPLICAS` env variable as the number of replicas is defined in the values file now
- Adds timestamp to the deploy history message for better tracking

### Tested

Tested on Alfajores.

### Backwards compatibility

All other commands like `destroy`, `initial`, and `migrate` are backwards compatible. The `upgrade` command is intentionally backwards incompatible to avoid situations when old tags from .env files get deployed.
  • Loading branch information
Valentin Rodygin authored Apr 22, 2021
1 parent 1108411 commit 3b4ba04
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 34 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ TESTNET_PROJECT_NAME="celo-testnet"

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="5f546f4e479fc51817fa324149002ce70478389a"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DB_SUFFIX=

# Blockscout related cronjobs
Expand Down
3 changes: 1 addition & 2 deletions .env.alfajores
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ AZURE_KOMENCI_WESTEU_AZURE_TENANT_ID=7cb7628a-e37c-4afb-8332-2029e418980e
AZURE_KOMENCI_WESTEU_AZURE_REGION_NAME=weu

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="69579f6408c405733b6d4d9960d636e12fc4f048"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DOCKER_IMAGE_TAG="0362f9f4d1d4842f27adb634d628f969f53c046d"
# Assign a new value everytime you redeploy blockscout. Or else the deployment will fail due to the
# existing database.
BLOCKSCOUT_DB_SUFFIX="2"
Expand Down
3 changes: 1 addition & 2 deletions .env.baklava
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ CLUSTER_DOMAIN_NAME="celo-testnet"
TESTNET_PROJECT_NAME="celo-testnet-production"

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="69579f6408c405733b6d4d9960d636e12fc4f048"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DOCKER_IMAGE_TAG="0362f9f4d1d4842f27adb634d628f969f53c046d"
BLOCKSCOUT_DB_SUFFIX=2
BLOCKSCOUT_SUBNETWORK_NAME="Baklava"
BLOCKSCOUT_METADATA_CRAWLER_IMAGE_REPOSITORY="gcr.io/celo-testnet/celo-monorepo"
Expand Down
1 change: 0 additions & 1 deletion .env.oracledev
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ VM_BASED=false

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="ad86714d629c01272e0651dec1fb6a968c3cec71"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DB_SUFFIX="-2"

# ---- Geth ----
Expand Down
3 changes: 1 addition & 2 deletions .env.rc1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ AZURE_KOMENCI_SEA_AZURE_TENANT_ID=7cb7628a-e37c-4afb-8332-2029e418980e
AZURE_KOMENCI_SEA_AZURE_REGION_NAME=sea

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="69579f6408c405733b6d4d9960d636e12fc4f048"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DOCKER_IMAGE_TAG="0362f9f4d1d4842f27adb634d628f969f53c046d"
BLOCKSCOUT_DB_SUFFIX=3
BLOCKSCOUT_SUBNETWORK_NAME="Celo"
BLOCKSCOUT_METADATA_CRAWLER_IMAGE_REPOSITORY="gcr.io/celo-testnet/celo-monorepo"
Expand Down
6 changes: 4 additions & 2 deletions packages/celotool/src/cmds/deploy/destroy/blockscout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DestroyArgv } from 'src/cmds/deploy/destroy'
import { getInstanceName, getReleaseName, removeHelmRelease } from 'src/lib/blockscout'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { execCmdWithExitOnFailure } from 'src/lib/cmd-utils'
import { envVar, fetchEnvOrFallback } from 'src/lib/env-utils'
import { deleteCloudSQLInstance, exitIfCelotoolHelmDryRun } from 'src/lib/helm_deploy'
import { outputIncludes } from 'src/lib/utils'

Expand All @@ -14,8 +15,9 @@ export const handler = async (argv: DestroyArgv) => {
exitIfCelotoolHelmDryRun()
await switchToClusterFromEnv(argv.celoEnv)

const instanceName = getInstanceName(argv.celoEnv)
const helmReleaseName = getReleaseName(argv.celoEnv)
const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const instanceName = getInstanceName(argv.celoEnv, dbSuffix)
const helmReleaseName = getReleaseName(argv.celoEnv, dbSuffix)

// Delete replica before deleting the master
await deleteCloudSQLInstance(instanceName + '-replica')
Expand Down
9 changes: 7 additions & 2 deletions packages/celotool/src/cmds/deploy/initial/blockscout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
installHelmChart,
} from 'src/lib/blockscout'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { envVar, fetchEnv, fetchEnvOrFallback } from 'src/lib/env-utils'
import {
createAndUploadCloudSQLSecretIfNotExists,
createCloudSQLInstance,
Expand All @@ -20,8 +21,11 @@ export const command = 'blockscout'
export const describe = 'deploy the blockscout package'

export const handler = async (argv: InitialArgv) => {
const instanceName = getInstanceName(argv.celoEnv)
const helmReleaseName = getReleaseName(argv.celoEnv)
const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const imageTag = fetchEnv(envVar.BLOCKSCOUT_DOCKER_IMAGE_TAG)

const instanceName = getInstanceName(argv.celoEnv, dbSuffix)
const helmReleaseName = getReleaseName(argv.celoEnv, dbSuffix)
await switchToClusterFromEnv(argv.celoEnv)
let blockscoutCredentials: string[] = [
'dummyUser',
Expand All @@ -48,6 +52,7 @@ export const handler = async (argv: InitialArgv) => {
await installHelmChart(
argv.celoEnv,
helmReleaseName,
imageTag,
blockscoutCredentials[0],
blockscoutCredentials[1],
blockscoutCredentials[2]
Expand Down
8 changes: 5 additions & 3 deletions packages/celotool/src/cmds/deploy/migrate/blockscout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getInstanceName, getReleaseName, installHelmChart } from 'src/lib/blockscout'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { envVar, fetchEnvOrFallback } from 'src/lib/env-utils'
import { envVar, fetchEnv, fetchEnvOrFallback } from 'src/lib/env-utils'
import { retrieveCloudSQLConnectionInfo } from 'src/lib/helm_deploy'
import { UpgradeArgv } from '../../deploy/upgrade'

Expand All @@ -18,8 +18,9 @@ export const handler = async (argv: TestnetArgv) => {
await switchToClusterFromEnv(argv.celoEnv)

const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const instanceName = getInstanceName(argv.celoEnv)
const helmReleaseName = getReleaseName(argv.celoEnv)
const imageTag = fetchEnv(envVar.BLOCKSCOUT_DOCKER_IMAGE_TAG)
const instanceName = getInstanceName(argv.celoEnv, dbSuffix)
const helmReleaseName = getReleaseName(argv.celoEnv, dbSuffix)

const [
blockscoutDBUsername,
Expand All @@ -31,6 +32,7 @@ export const handler = async (argv: TestnetArgv) => {
await installHelmChart(
argv.celoEnv,
helmReleaseName,
imageTag,
blockscoutDBUsername,
blockscoutDBPassword,
blockscoutDBConnectionName
Expand Down
4 changes: 3 additions & 1 deletion packages/celotool/src/cmds/deploy/switch/blockscout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SwitchArgv } from 'src/cmds/deploy/switch'
import { getReleaseName, switchIngressService } from 'src/lib/blockscout'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { envVar, fetchEnvOrFallback } from 'src/lib/env-utils'
import yargs from 'yargs'

export const command = 'blockscout'
Expand All @@ -13,6 +14,7 @@ export const builder = (argv: yargs.Argv) => {
export const handler = async (argv: SwitchArgv) => {
await switchToClusterFromEnv(argv.celoEnv)

const helmReleaseName = getReleaseName(argv.celoEnv)
const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const helmReleaseName = getReleaseName(argv.celoEnv, dbSuffix)
await switchIngressService(argv.celoEnv, helmReleaseName)
}
12 changes: 12 additions & 0 deletions packages/celotool/src/cmds/deploy/upgrade/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type AllArgv = UpgradeArgv & {
reset: boolean
useExistingGenesis: boolean
skipFaucetting: boolean
tag: string
suffix: string
}

export const builder = (argv: yargs.Argv) => {
Expand All @@ -35,6 +37,16 @@ export const builder = (argv: yargs.Argv) => {
default: false,
type: 'boolean',
})
.option('tag', {
type: 'string',
description: 'Docker image tag to deploy',
default: '',
})
.option('suffix', {
type: 'string',
description: 'Instance suffix',
default: '',
})
}

export const handler = async (argv: AllArgv) => {
Expand Down
37 changes: 27 additions & 10 deletions packages/celotool/src/cmds/deploy/upgrade/blockscout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,38 @@ export const command = 'blockscout'
export const describe = 'upgrade an existing deploy of the blockscout package'

export const builder = (argv: yargs.Argv) => {
return argv.option('reset', {
type: 'boolean',
description:
'when enabled, deletes the database and redeploys the helm chart. keeps the instance.',
default: false,
})
return argv
.option('reset', {
type: 'boolean',
description:
'when enabled, deletes the database and redeploys the helm chart. keeps the instance.',
default: false,
})
.option('tag', {
type: 'string',
description: 'Docker image tag to deploy',
})
.option('suffix', {
type: 'string',
description: 'Instance suffix',
default: '',
})
.demandOption(['tag'])
}

type BlockscoutUpgradeArgv = UpgradeArgv & { reset: boolean }
type BlockscoutUpgradeArgv = UpgradeArgv & {
reset: boolean
tag: string
suffix: string
}

export const handler = async (argv: BlockscoutUpgradeArgv) => {
await switchToClusterFromEnv(argv.celoEnv)

const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const instanceName = getInstanceName(argv.celoEnv)
const helmReleaseName = getReleaseName(argv.celoEnv)
const dbSuffix = argv.suffix || fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
const imageTag = argv.tag
const instanceName = getInstanceName(argv.celoEnv, dbSuffix)
const helmReleaseName = getReleaseName(argv.celoEnv, dbSuffix)

const [
blockscoutDBUsername,
Expand Down Expand Up @@ -73,6 +89,7 @@ export const handler = async (argv: BlockscoutUpgradeArgv) => {
await upgradeHelmChart(
argv.celoEnv,
helmReleaseName,
imageTag,
blockscoutDBUsername,
blockscoutDBPassword,
blockscoutDBConnectionName
Expand Down
15 changes: 9 additions & 6 deletions packages/celotool/src/lib/blockscout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ import { getInternalTxNodeLoadBalancerIP } from './vm-testnet-utils'

const helmChartPath = '../helm-charts/blockscout'

export function getInstanceName(celoEnv: string) {
const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
export function getInstanceName(celoEnv: string, dbSuffix: string) {
return `${celoEnv}${dbSuffix}`
}

export function getReleaseName(celoEnv: string) {
const dbSuffix = fetchEnvOrFallback(envVar.BLOCKSCOUT_DB_SUFFIX, '')
export function getReleaseName(celoEnv: string, dbSuffix: string) {
return `${celoEnv}-blockscout${dbSuffix}`
}

export async function installHelmChart(
celoEnv: string,
releaseName: string,
imageTag: string,
blockscoutDBUsername: string,
blockscoutDBPassword: string,
blockscoutDBConnectionName: string
Expand All @@ -35,6 +34,7 @@ export async function installHelmChart(
helmChartPath,
await helmParameters(
celoEnv,
imageTag,
blockscoutDBUsername,
blockscoutDBPassword,
blockscoutDBConnectionName
Expand All @@ -51,13 +51,15 @@ export async function removeHelmRelease(helmReleaseName: string, celoEnv: string
export async function upgradeHelmChart(
celoEnv: string,
helmReleaseName: string,
imageTag: string,
blockscoutDBUsername: string,
blockscoutDBPassword: string,
blockscoutDBConnectionName: string
) {
console.info(`Upgrading helm release ${helmReleaseName}`)
const params = await helmParameters(
celoEnv,
imageTag,
blockscoutDBUsername,
blockscoutDBPassword,
blockscoutDBConnectionName
Expand All @@ -75,6 +77,7 @@ export async function upgradeHelmChart(

async function helmParameters(
celoEnv: string,
imageTag: string,
blockscoutDBUsername: string,
blockscoutDBPassword: string,
blockscoutDBConnectionName: string
Expand All @@ -88,13 +91,13 @@ async function helmParameters(
const params = [
`--set domain.name=${fetchEnv(envVar.CLUSTER_DOMAIN_NAME)}`,
`--set blockscout.deployment.account="${currentGcloudAccount}"`,
`--set blockscout.deployment.timestamp="${new Date().toISOString()}"`,
`--set blockscout.image.repository=${fetchEnv(envVar.BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY)}`,
`--set blockscout.image.tag=${fetchEnv(envVar.BLOCKSCOUT_DOCKER_IMAGE_TAG)}`,
`--set blockscout.image.tag=${imageTag}`,
`--set blockscout.db.username=${blockscoutDBUsername}`,
`--set blockscout.db.password=${blockscoutDBPassword}`,
`--set blockscout.db.connection_name=${blockscoutDBConnectionName.trim()}`,
`--set blockscout.db.drop=${fetchEnvOrFallback(envVar.BLOCKSCOUT_DROP_DB, 'false')}`,
`--set blockscout.replicas=${fetchEnv(envVar.BLOCKSCOUT_WEB_REPLICAS)}`,
`--set blockscout.subnetwork="${fetchEnvOrFallback(
envVar.BLOCKSCOUT_SUBNETWORK_NAME,
celoEnv
Expand Down
1 change: 0 additions & 1 deletion packages/celotool/src/lib/env-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export enum envVar {
BLOCKSCOUT_METADATA_CRAWLER_SCHEDULE = 'BLOCKSCOUT_METADATA_CRAWLER_SCHEDULE',
BLOCKSCOUT_SEGMENT_KEY = 'BLOCKSCOUT_SEGMENT_KEY',
BLOCKSCOUT_SUBNETWORK_NAME = 'BLOCKSCOUT_SUBNETWORK_NAME',
BLOCKSCOUT_WEB_REPLICAS = 'BLOCKSCOUT_WEB_REPLICAS',
CELOCLI_STANDALONE_IMAGE_REPOSITORY = 'CELOCLI_STANDALONE_IMAGE_REPOSITORY',
CELOCLI_STANDALONE_IMAGE_TAG = 'CELOCLI_STANDALONE_IMAGE_TAG',
CELOSTATS_BANNED_ADDRESSES = 'CELOSTATS_BANNED_ADDRESSES',
Expand Down
2 changes: 1 addition & 1 deletion packages/helm-charts/blockscout/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ heritage: {{ .Release.Service }}
Defines common annotations across all blockscout components.
*/ -}}
{{- define "celo.blockscout.annotations" -}}
kubernetes.io/change-cause: Deployed {{ .Values.blockscout.image.tag }} by {{ .Values.blockscout.deployment.account }}
kubernetes.io/change-cause: Deployed {{ .Values.blockscout.image.tag }} by {{ .Values.blockscout.deployment.account }} on {{ .Values.blockscout.deployment.timestamp }}
{{- end -}}

{{- /*
Expand Down

0 comments on commit 3b4ba04

Please sign in to comment.