Skip to content

Commit 86d7c64

Browse files
committed
mitch/tmnt-168-create-test-network-scenariosyml
1 parent 8416064 commit 86d7c64

File tree

8 files changed

+91
-117
lines changed

8 files changed

+91
-117
lines changed

.github/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.secrets
1+
.secrets
2+
.act-tool-cache

.github/local_workflow.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ args=("$@")
3232

3333
SA_KEY_JSON=$(cat "$GOOGLE_APPLICATION_CREDENTIALS")
3434

35+
mkdir -p $REPO_ROOT/.github/.act-tool-cache
36+
3537
act workflow_dispatch -j $workflow_name \
38+
--env RUNNER_TOOL_CACHE=/work/toolcache \
3639
-s GITHUB_TOKEN="$(gh auth token)" \
3740
-s GCP_SA_KEY="$SA_KEY_JSON" \
3841
-s KUBECONFIG_B64="$(cat $HOME/.kube/config | base64 -w0)" \
39-
--container-options "--user $(id -u):$(id -g)" \
42+
--container-options "-v $REPO_ROOT/.github/.act-tool-cache:/work/toolcache --user $(id -u):$(id -g)" \
4043
--bind \
4144
--directory $REPO_ROOT "${args[@]}"

.github/workflows/deploy-eth-devnet.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
beacon_url: ${{ steps.get-eth-devnet-results.outputs.beacon_url }}
150150
chain_id: ${{ steps.get-eth-devnet-results.outputs.chain_id }}
151151
env:
152+
# HOME: "/home/mitch"
152153
TF_STATE_BUCKET: aztec-terraform
153154
REGION: us-west1-a
154155
# Common Terraform variables as environment variables
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
cluster:
5+
description: The cluster to deploy to, e.g. aztec-gke-private or kind
6+
required: true
7+
type: string
8+
namespace:
9+
description: The namespace to deploy to
10+
required: true
11+
type: string
12+
ref:
13+
description: The ref to checkout
14+
required: true
15+
type: string
16+
17+
jobs:
18+
test_network_scenarios:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Test network scenarios
22+
run: |
23+
echo "Testing network scenarios"
24+
25+
- name: Check if directory exists
26+
id: check_dir
27+
shell: bash
28+
run: |
29+
if [ -d ".git" ]; then
30+
echo "exists=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "exists=false" >> $GITHUB_OUTPUT
33+
fi
34+
35+
- name: Checkout code
36+
if: ${{ steps.check_dir.outputs.exists != 'true' }}
37+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
38+
with:
39+
ref: ${{ inputs.ref }}
40+
41+
- name: Build
42+
shell: bash
43+
run: |
44+
./bootstrap.sh

spartan/terraform/deploy-aztec-infra/main.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,4 @@ resource "google_compute_address" "rpc_ingress" {
188188
provider = google
189189
name = "${var.NAMESPACE}-${var.RELEASE_PREFIX}-rpc-ingress"
190190
address_type = "EXTERNAL"
191-
192-
193191
}

spartan/terraform/deploy-aztec-infra/values/rpc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node:
1515
startCmd:
1616
- --node
1717
- --archiver
18+
- --pxe

yarn-project/end-to-end/src/spartan/smoke.test.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createLogger } from '@aztec/foundation/log';
55
import type { ChildProcess } from 'child_process';
66
import { foundry } from 'viem/chains';
77

8-
import { isK8sConfig, setupEnvironment, startPortForward } from './utils.js';
8+
import { setupEnvironment, startPortForwardForPXE } from './utils.js';
99

1010
const config = setupEnvironment(process.env);
1111

@@ -15,19 +15,12 @@ describe('smoke test', () => {
1515
let pxe: PXE;
1616
const forwardProcesses: ChildProcess[] = [];
1717
beforeAll(async () => {
18-
let PXE_URL: string;
19-
if (isK8sConfig(config)) {
20-
const { process, port } = await startPortForward({
21-
resource: `svc/${config.INSTANCE_NAME}-aztec-network-pxe`,
22-
namespace: config.NAMESPACE,
23-
containerPort: config.CONTAINER_PXE_PORT,
24-
});
25-
forwardProcesses.push(process);
26-
PXE_URL = `http://127.0.0.1:${port}`;
27-
} else {
28-
PXE_URL = config.PXE_URL;
29-
}
30-
pxe = await createCompatibleClient(PXE_URL, debugLogger);
18+
debugLogger.info('Starting port forward for PXE');
19+
const { process, port } = await startPortForwardForPXE(config.NAMESPACE);
20+
forwardProcesses.push(process);
21+
const pxeUrl = `http://127.0.0.1:${port}`;
22+
23+
pxe = await createCompatibleClient(pxeUrl, debugLogger);
3124
});
3225

3326
afterAll(() => {

yarn-project/end-to-end/src/spartan/utils.ts

Lines changed: 32 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,34 @@ import { createLogger, sleep } from '@aztec/aztec.js';
22
import type { RollupCheatCodes } from '@aztec/aztec/testing';
33
import type { Logger } from '@aztec/foundation/log';
44
import { makeBackoff, retry } from '@aztec/foundation/retry';
5-
import type { SequencerConfig } from '@aztec/sequencer-client';
6-
import { createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client';
5+
import { type AztecNodeAdminConfig, createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client';
76

87
import { ChildProcess, exec, execSync, spawn } from 'child_process';
98
import path from 'path';
109
import { promisify } from 'util';
1110
import { z } from 'zod';
1211

13-
import { AlertChecker, type AlertConfig } from '../quality_of_service/alert_checker.js';
12+
export const PXE_SERVICE_NAME = 'services/aztec-infra-rpc-aztec-node';
1413

1514
const execAsync = promisify(exec);
1615

1716
const logger = createLogger('e2e:k8s-utils');
1817

19-
const ethereumHostsSchema = z.string().refine(
20-
str =>
21-
str.split(',').every(url => {
22-
try {
23-
new URL(url.trim());
24-
return true;
25-
} catch {
26-
return false;
27-
}
28-
}),
29-
'ETHEREUM_HOSTS must be a comma-separated list of valid URLs',
30-
);
31-
32-
const k8sLocalConfigSchema = z.object({
33-
ETHEREUM_SLOT_DURATION: z.coerce.number().min(1, 'ETHEREUM_SLOT_DURATION env variable must be set'),
34-
AZTEC_SLOT_DURATION: z.coerce.number().min(1, 'AZTEC_SLOT_DURATION env variable must be set'),
35-
AZTEC_EPOCH_DURATION: z.coerce.number().min(1, 'AZTEC_EPOCH_DURATION env variable must be set'),
36-
AZTEC_PROOF_SUBMISSION_WINDOW: z.coerce.number().min(1, 'AZTEC_PROOF_SUBMISSION_WINDOW env variable must be set'),
37-
AZTEC_REAL_PROOFS: z.string().default('false'),
38-
INSTANCE_NAME: z.string().min(1, 'INSTANCE_NAME env variable must be set'),
18+
const testConfigSchema = z.object({
3919
NAMESPACE: z.string().min(1, 'NAMESPACE env variable must be set'),
40-
CONTAINER_NODE_PORT: z.coerce.number().default(8080),
41-
CONTAINER_NODE_ADMIN_PORT: z.coerce.number().default(8880),
42-
CONTAINER_SEQUENCER_PORT: z.coerce.number().default(8080),
43-
CONTAINER_PROVER_NODE_PORT: z.coerce.number().default(8080),
44-
CONTAINER_PXE_PORT: z.coerce.number().default(8080),
45-
CONTAINER_ETHEREUM_PORT: z.coerce.number().default(8545),
46-
CONTAINER_METRICS_PORT: z.coerce.number().default(80),
47-
GRAFANA_PASSWORD: z.string().optional(),
48-
METRICS_API_PATH: z.string().default('/api/datasources/proxy/uid/spartan-metrics-prometheus/api/v1'),
49-
SPARTAN_DIR: z.string().min(1, 'SPARTAN_DIR env variable must be set'),
50-
ETHEREUM_HOSTS: ethereumHostsSchema.optional(),
5120
L1_ACCOUNT_MNEMONIC: z.string().default('test test test test test test test test test test test junk'),
52-
SEPOLIA_RUN: z.string().default('false'),
53-
K8S: z.literal('local'),
54-
});
55-
56-
const k8sGCloudConfigSchema = k8sLocalConfigSchema.extend({
57-
K8S: z.literal('gcloud'),
58-
CLUSTER_NAME: z.string().min(1, 'CLUSTER_NAME env variable must be set'),
59-
REGION: z.string().min(1, 'REGION env variable must be set'),
60-
PROJECT_ID: z.string().min(1, 'PROJECT_ID env variable must be set'),
21+
K8S_CLUSTER: z.string().min(1, 'K8S_CLUSTER env variable must be set'),
22+
REGION: z.string().optional(),
23+
PROJECT_ID: z.string().optional(),
6124
});
6225

63-
const directConfigSchema = z.object({
64-
PXE_URL: z.string().url('PXE_URL must be a valid URL'),
65-
NODE_URL: z.string().url('NODE_URL must be a valid URL'),
66-
NODE_ADMIN_URL: z.string().url('NODE_ADMIN_URL must be a valid URL'),
67-
ETHEREUM_HOSTS: ethereumHostsSchema,
68-
K8S: z.literal('false'),
69-
});
26+
export type TestConfig = z.infer<typeof testConfigSchema>;
7027

71-
const envSchema = z.discriminatedUnion('K8S', [k8sLocalConfigSchema, k8sGCloudConfigSchema, directConfigSchema]);
72-
73-
export type K8sLocalConfig = z.infer<typeof k8sLocalConfigSchema>;
74-
export type K8sGCloudConfig = z.infer<typeof k8sGCloudConfigSchema>;
75-
export type DirectConfig = z.infer<typeof directConfigSchema>;
76-
export type EnvConfig = z.infer<typeof envSchema>;
77-
78-
export function isK8sConfig(config: EnvConfig): config is K8sLocalConfig | K8sGCloudConfig {
79-
return config.K8S === 'local' || config.K8S === 'gcloud';
80-
}
28+
export function setupEnvironment(env: unknown): TestConfig {
29+
const config = testConfigSchema.parse(env);
8130

82-
export function isGCloudConfig(config: EnvConfig): config is K8sGCloudConfig {
83-
return config.K8S === 'gcloud';
84-
}
85-
86-
export function setupEnvironment(env: unknown): EnvConfig {
87-
const config = envSchema.parse(env);
88-
if (isGCloudConfig(config)) {
89-
const command = `gcloud container clusters get-credentials ${config.CLUSTER_NAME} --region=${config.REGION} --project=${config.PROJECT_ID}`;
31+
if (config.K8S_CLUSTER !== 'kind') {
32+
const command = `gcloud container clusters get-credentials ${config.K8S_CLUSTER} --region=${config.REGION} --project=${config.PROJECT_ID}`;
9033
execSync(command);
9134
}
9235
return config;
@@ -212,6 +155,14 @@ export async function startPortForward({
212155
return { process, port };
213156
}
214157

158+
export async function startPortForwardForPXE(namespace: string) {
159+
return startPortForward({
160+
resource: PXE_SERVICE_NAME,
161+
namespace,
162+
containerPort: 8080,
163+
});
164+
}
165+
215166
export async function deleteResourceByName({
216167
resource,
217168
namespace,
@@ -550,25 +501,7 @@ export async function enableValidatorDynamicBootNode(
550501
logger.info(`Validator dynamic boot node enabled`);
551502
}
552503

553-
export async function runAlertCheck(config: EnvConfig, alerts: AlertConfig[], logger: Logger) {
554-
if (isK8sConfig(config)) {
555-
const { process, port } = await startPortForward({
556-
resource: `svc/metrics-grafana`,
557-
namespace: 'metrics',
558-
containerPort: config.CONTAINER_METRICS_PORT,
559-
});
560-
const alertChecker = new AlertChecker(logger, {
561-
grafanaEndpoint: `http://localhost:${port}${config.METRICS_API_PATH}`,
562-
grafanaCredentials: `admin:${config.GRAFANA_PASSWORD}`,
563-
});
564-
await alertChecker.runAlertCheck(alerts);
565-
process.kill();
566-
} else {
567-
logger.info('Not running alert check in non-k8s environment');
568-
}
569-
}
570-
571-
export async function updateSequencerConfig(url: string, config: Partial<SequencerConfig>) {
504+
export async function updateSequencerConfig(url: string, config: Partial<AztecNodeAdminConfig>) {
572505
const node = createAztecNodeAdminClient(url);
573506
// Retry incase the port forward is not ready yet
574507
await retry(() => node.setConfig(config), 'Update sequencer config', makeBackoff([1, 3, 6]), logger);
@@ -583,7 +516,7 @@ export async function getSequencers(namespace: string) {
583516
async function updateK8sSequencersConfig(args: {
584517
containerPort: number;
585518
namespace: string;
586-
config: Partial<SequencerConfig>;
519+
config: Partial<AztecNodeAdminConfig>;
587520
}) {
588521
const { containerPort, namespace, config } = args;
589522
const sequencers = await getSequencers(namespace);
@@ -600,17 +533,17 @@ async function updateK8sSequencersConfig(args: {
600533
}
601534
}
602535

603-
export async function updateSequencersConfig(env: EnvConfig, config: Partial<SequencerConfig>) {
604-
if (isK8sConfig(env)) {
605-
await updateK8sSequencersConfig({
606-
containerPort: env.CONTAINER_NODE_ADMIN_PORT,
607-
namespace: env.NAMESPACE,
608-
config,
609-
});
610-
} else {
611-
await updateSequencerConfig(env.NODE_ADMIN_URL, config);
612-
}
613-
}
536+
// export async function updateSequencersConfig(env: EnvConfig, config: Partial<AztecNodeAdminConfig>) {
537+
// if (isK8sConfig(env)) {
538+
// await updateK8sSequencersConfig({
539+
// containerPort: env.CONTAINER_NODE_ADMIN_PORT,
540+
// namespace: env.NAMESPACE,
541+
// config,
542+
// });
543+
// } else {
544+
// await updateSequencerConfig(env.NODE_ADMIN_URL, config);
545+
// }
546+
// }
614547

615548
/**
616549
* Rolls the Aztec pods in the given namespace.

0 commit comments

Comments
 (0)