From 7afb14afa7a082df7e8d6863c5eff6a9afd5f557 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 1 Nov 2024 19:07:29 -0400 Subject: [PATCH 1/2] feat(synthetic-chain): Propagate environment variable SLOGFILE into containers cf. https://docs.docker.com/reference/cli/docker/container/run/#env --- packages/synthetic-chain/src/cli/run.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/synthetic-chain/src/cli/run.ts b/packages/synthetic-chain/src/cli/run.ts index fb2bc284..6cd4fc78 100755 --- a/packages/synthetic-chain/src/cli/run.ts +++ b/packages/synthetic-chain/src/cli/run.ts @@ -1,11 +1,29 @@ import { execSync } from 'node:child_process'; +import { realpathSync } from 'node:fs'; import { ProposalInfo, imageNameForProposal } from './proposals.js'; +/** + * Used to propagate a SLOGFILE environment variable into Docker containers. + * Any file identified by such a variable will be created if it does not already + * exist. + * + * @param {typeof process.env} env environment variables + * @returns {string[]} docker run options + */ +const propagateSlogfile = env => { + const { SLOGFILE } = env; + if (!SLOGFILE) return []; + + execSync('touch "$SLOGFILE"'); + return ['-e', 'SLOGFILE', '-v', `"$SLOGFILE:${realpathSync(SLOGFILE)}"`]; +}; + export const runTestImage = (proposal: ProposalInfo) => { console.log(`Running test image for proposal ${proposal.proposalName}`); const { name } = imageNameForProposal(proposal, 'test'); + const slogOpts = propagateSlogfile(process.env); // 'rm' to remove the container when it exits - const cmd = `docker run --rm ${name}`; + const cmd = `docker run ${slogOpts.join(' ')} --rm ${name}`; execSync(cmd, { stdio: 'inherit' }); }; @@ -28,7 +46,8 @@ export const debugTestImage = (proposal: ProposalInfo) => { `, ); + const slogOpts = propagateSlogfile(process.env); // start the chain with ports mapped - const cmd = `docker run --publish 26657:26657 --publish 1317:1317 --publish 9090:9090 --interactive --tty --entrypoint /usr/src/upgrade-test-scripts/start_agd.sh ${name}`; + const cmd = `docker run ${slogOpts.join(' ')} --publish 26657:26657 --publish 1317:1317 --publish 9090:9090 --interactive --tty --entrypoint /usr/src/upgrade-test-scripts/start_agd.sh ${name}`; execSync(cmd, { stdio: 'inherit' }); }; From 41d8d155674901f1e95f7ece955991463f3a5c48 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Sat, 9 Nov 2024 22:53:04 -0500 Subject: [PATCH 2/2] chore(synthetic-chain): Update usage documentation --- packages/synthetic-chain/README.md | 11 +++++++++-- packages/synthetic-chain/src/cli/cli.ts | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/synthetic-chain/README.md b/packages/synthetic-chain/README.md index f9880974..91cba68e 100644 --- a/packages/synthetic-chain/README.md +++ b/packages/synthetic-chain/README.md @@ -5,10 +5,17 @@ Utilities to build a synthetic chain and test running proposals atop it. The cha ## Usage ``` +prepare-build - generate Docker build configs + build - build the synthetic-chain "use" images + [--dry] - print the config without building images -test [--debug] - build the "test" images and run them -test -m - target a particular proposal by substring match +test - build the "test" images and run them + respecting any SLOGFILE environment variable + https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#slogfile + [-m ] - target a particular proposal by substring match + [--debug] - run containers with interactive TTY and port mapping + [--dry] - print the config without building images doctor - diagnostics and quick fixes ``` diff --git a/packages/synthetic-chain/src/cli/cli.ts b/packages/synthetic-chain/src/cli/cli.ts index 31c54e5b..f8cf983c 100755 --- a/packages/synthetic-chain/src/cli/cli.ts +++ b/packages/synthetic-chain/src/cli/cli.ts @@ -42,9 +42,14 @@ const USAGE = `USAGE: prepare-build - generate Docker build configs build - build the synthetic-chain "use" images + [--dry] - print the config without building images -test [--debug] - build the "test" images and run them -test -m - target a particular proposal by substring match +test - build the "test" images and run them + respecting any SLOGFILE environment variable + https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#slogfile + [-m ] - target a particular proposal by substring match + [--debug] - run containers with interactive TTY and port mapping + [--dry] - print the config without building images doctor - diagnostics and quick fixes `;