Skip to content

Commit 024a26d

Browse files
committed
feat(infra): migrate to standalone keyfunder package with ExternalSecrets
1 parent d5cc001 commit 024a26d

13 files changed

Lines changed: 299 additions & 1344 deletions

File tree

typescript/infra/config/docker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const DockerImageRepos = {
22
AGENT: 'gcr.io/abacus-labs-dev/hyperlane-agent',
33
MONOREPO: 'gcr.io/abacus-labs-dev/hyperlane-monorepo',
4+
KEYFUNDER: 'gcr.io/abacus-labs-dev/hyperlane-keyfunder',
45
WARP_MONITOR: 'gcr.io/abacus-labs-dev/hyperlane-warp-monitor',
56
REBALANCER: 'gcr.io/abacus-labs-dev/hyperlane-rebalancer',
67
} as const;

typescript/infra/config/environments/mainnet3/funding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const keyFunderConfig: KeyFunderConfig<
3636
typeof mainnet3SupportedChainNames
3737
> = {
3838
docker: {
39-
repo: DockerImageRepos.MONOREPO,
39+
repo: DockerImageRepos.KEYFUNDER,
4040
tag: mainnetDockerTags.keyFunder,
4141
},
4242
// We're currently using the same deployer/key funder key as mainnet2.

typescript/infra/config/environments/testnet4/funding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const keyFunderConfig: KeyFunderConfig<
1010
typeof testnet4SupportedChainNames
1111
> = {
1212
docker: {
13-
repo: DockerImageRepos.MONOREPO,
13+
repo: DockerImageRepos.KEYFUNDER,
1414
tag: testnetDockerTags.keyFunder,
1515
},
1616
// We're currently using the same deployer key as testnet2.

typescript/infra/helm/key-funder/templates/addresses-external-secret.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: key-funder-config
5+
labels:
6+
{{- include "hyperlane.labels" . | nindent 4 }}
7+
data:
8+
keyfunder.yaml: |
9+
{{ .Values.hyperlane.keyfunderConfig | indent 4 }}

typescript/infra/helm/key-funder/templates/cron-job.yaml

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
jobTemplate:
1111
spec:
1212
backoffLimit: 0
13-
activeDeadlineSeconds: 14400 # 60 * 60 * 4 seconds = 4 hours
13+
activeDeadlineSeconds: 14400
1414
template:
1515
metadata:
1616
labels:
@@ -21,52 +21,29 @@ spec:
2121
- name: key-funder
2222
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
2323
imagePullPolicy: IfNotPresent
24-
command:
25-
- pnpm
26-
- exec
27-
- tsx
28-
- ./typescript/infra/scripts/funding/fund-keys-from-deployer.ts
29-
- -e
30-
- {{ .Values.hyperlane.runEnv }}
31-
- --context
32-
- {{ .Values.hyperlane.contextFundingFrom }}
33-
{{- range $context, $roles := .Values.hyperlane.contextsAndRolesToFund }}
34-
- --contexts-and-roles
35-
- {{ $context }}={{ join "," $roles }}
36-
{{- end }}
37-
{{- range $chain, $balance := .Values.hyperlane.desiredBalancePerChain }}
38-
- --desired-balance-per-chain
39-
- {{ $chain }}={{ $balance }}
40-
{{- end }}
41-
{{- range $chain, $balance := .Values.hyperlane.desiredKathyBalancePerChain }}
42-
- --desired-kathy-balance-per-chain
43-
- {{ $chain }}={{ $balance }}
44-
{{- end }}
45-
{{- range $chain, $balance := .Values.hyperlane.desiredRebalancerBalancePerChain }}
46-
- --desired-rebalancer-balance-per-chain
47-
- {{ $chain }}={{ $balance }}
48-
{{- end }}
49-
{{- range $chain, $balance := .Values.hyperlane.igpClaimThresholdPerChain }}
50-
- --igp-claim-threshold-per-chain
51-
- {{ $chain }}={{ $balance }}
52-
{{- end }}
53-
{{- if .Values.hyperlane.chainsToSkip }}
54-
- --chain-skip-override
55-
{{- range $index, $chain := .Values.hyperlane.chainsToSkip }}
56-
- {{ $chain }}
57-
{{- end }}
58-
{{- end }}
5924
env:
60-
- name: PROMETHEUS_PUSH_GATEWAY
61-
value: {{ .Values.infra.prometheusPushGateway }}
25+
- name: LOG_FORMAT
26+
value: json
27+
- name: LOG_LEVEL
28+
value: info
29+
- name: KEYFUNDER_CONFIG_FILE
30+
value: /config/keyfunder.yaml
31+
{{- if .Values.hyperlane.registryUri }}
32+
- name: REGISTRY_URI
33+
value: {{ .Values.hyperlane.registryUri }}
34+
{{- end }}
35+
{{- if .Values.hyperlane.skipIgpClaim }}
36+
- name: SKIP_IGP_CLAIM
37+
value: "true"
38+
{{- end }}
6239
envFrom:
6340
- secretRef:
6441
name: key-funder-env-var-secret
6542
volumeMounts:
66-
- name: key-funder-addresses-secret
67-
mountPath: /addresses-secret
43+
- name: config
44+
mountPath: /config
45+
readOnly: true
6846
volumes:
69-
- name: key-funder-addresses-secret
70-
secret:
71-
secretName: key-funder-addresses-secret
72-
defaultMode: 0400
47+
- name: config
48+
configMap:
49+
name: key-funder-config

typescript/infra/helm/key-funder/templates/env-var-external-secret.yaml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ spec:
99
name: {{ include "hyperlane.cluster-secret-store.name" . }}
1010
kind: ClusterSecretStore
1111
refreshInterval: "1h"
12-
# The secret that will be created
1312
target:
1413
name: key-funder-env-var-secret
1514
template:
@@ -20,24 +19,14 @@ spec:
2019
annotations:
2120
update-on-redeploy: "{{ now }}"
2221
data:
23-
GCP_SECRET_OVERRIDES_ENABLED: "true"
24-
GCP_SECRET_OVERRIDE_HYPERLANE_{{ .Values.hyperlane.runEnv | upper }}_KEY_DEPLOYER: {{ print "'{{ .deployer_key | toString }}'" }}
25-
{{/*
26-
* For each network, create an environment variable with the RPC endpoint.
27-
* The templating of external-secrets will use the data section below to know how
28-
* to replace the correct value in the created secret.
29-
*/}}
22+
HYP_KEY: {{ print "'{{ $json := .funder_key | fromJson }}{{ $json.privateKey }}'" }}
3023
{{- range .Values.hyperlane.chains }}
31-
GCP_SECRET_OVERRIDE_{{ $.Values.hyperlane.runEnv | upper }}_RPC_ENDPOINTS_{{ . | upper }}: {{ printf "'{{ .%s_rpcs | toString }}'" . }}
24+
RPC_URL_{{ . | upper | replace "-" "_" }}: {{ printf "'{{ index (.%s_rpcs | fromJson) 0 }}'" . }}
3225
{{- end }}
3326
data:
34-
- secretKey: deployer_key
27+
- secretKey: funder_key
3528
remoteRef:
3629
key: {{ printf "hyperlane-%s-key-deployer" .Values.hyperlane.runEnv }}
37-
{{/*
38-
* For each network, load the secret in GCP secret manager with the form: environment-rpc-endpoint-network,
39-
* and associate it with the secret key networkname_rpc.
40-
*/}}
4130
{{- range .Values.hyperlane.chains }}
4231
- secretKey: {{ printf "%s_rpcs" . }}
4332
remoteRef:

typescript/infra/helm/key-funder/values.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
image:
2-
repository: gcr.io/hyperlane-labs-dev/hyperlane-monorepo
3-
tag:
2+
repository: gcr.io/abacus-labs-dev/hyperlane-keyfunder
3+
tag: latest
44
hyperlane:
5-
runEnv: testnet2
6-
# Used for fetching secrets
5+
runEnv: testnet4
76
chains: []
87
chainsToSkip: []
9-
contextFundingFrom: hyperlane
10-
# key = context, value = array of roles to fund
11-
contextsAndRolesToFund:
12-
hyperlane:
13-
- relayer
8+
registryUri: ''
9+
keyfunderConfig: ''
10+
skipIgpClaim: false
1411
cronjob:
15-
schedule: '*/10 * * * *' # Every 10 minutes
12+
schedule: '*/10 * * * *'
1613
successfulJobsHistoryLimit: 6
1714
failedJobsHistoryLimit: 10
1815
externalSecrets:

typescript/infra/scripts/funding/deploy-key-funder.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
import { confirm, input } from '@inquirer/prompts';
12
import chalk from 'chalk';
3+
import { readFileSync } from 'fs';
4+
import { join } from 'path';
25

36
import { Contexts } from '../../config/contexts.js';
47
import { KeyFunderHelmManager } from '../../src/funding/key-funder.js';
5-
import { checkMonorepoImageExists } from '../../src/utils/gcloud.js';
8+
import { validateRegistryCommit } from '../../src/utils/git.js';
69
import { HelmCommand } from '../../src/utils/helm.js';
10+
import { getMonorepoRoot } from '../../src/utils/utils.js';
711
import { assertCorrectKubeContext } from '../agent-utils.js';
812
import { getConfigsBasedOnArgs } from '../core-utils.js';
913

14+
function readRegistryRc(): string {
15+
const registryRcPath = join(getMonorepoRoot(), '.registryrc');
16+
return readFileSync(registryRcPath, 'utf-8').trim();
17+
}
18+
1019
async function main() {
1120
const { agentConfig, envConfig, environment } = await getConfigsBasedOnArgs();
1221
if (agentConfig.context != Contexts.Hyperlane)
@@ -16,23 +25,32 @@ async function main() {
1625

1726
await assertCorrectKubeContext(envConfig);
1827

19-
if (envConfig.keyFunderConfig?.docker.tag) {
20-
const exists = await checkMonorepoImageExists(
21-
envConfig.keyFunderConfig.docker.tag,
22-
);
23-
if (!exists) {
24-
console.log(
25-
chalk.red(
26-
`Attempted to deploy key funder with image tag ${chalk.bold(
27-
envConfig.keyFunderConfig.docker.tag,
28-
)}, but it has not been published to GCR.`,
29-
),
30-
);
31-
process.exit(1);
32-
}
28+
const defaultRegistryCommit = readRegistryRc();
29+
console.log(
30+
chalk.gray(
31+
`Using registry commit from .registryrc: ${defaultRegistryCommit}`,
32+
),
33+
);
34+
35+
const shouldOverride = await confirm({
36+
message: 'Do you want to override the registry version?',
37+
default: false,
38+
});
39+
40+
let registryCommit = defaultRegistryCommit;
41+
if (shouldOverride) {
42+
registryCommit = await input({
43+
message:
44+
'Enter the registry version to use (can be a commit, branch or tag):',
45+
});
3346
}
3447

35-
const manager = KeyFunderHelmManager.forEnvironment(environment);
48+
await validateRegistryCommit(registryCommit);
49+
50+
const manager = KeyFunderHelmManager.forEnvironment(
51+
environment,
52+
registryCommit,
53+
);
3654
await manager.runHelmCommand(HelmCommand.InstallOrUpgrade);
3755
}
3856

0 commit comments

Comments
 (0)