Skip to content

Commit

Permalink
feat(synthetic-chain): Propagate environment variable SLOGFILE into c…
Browse files Browse the repository at this point in the history
…ontainers (merge #191)
  • Loading branch information
gibson042 authored Nov 11, 2024
2 parents d55bfe0 + 41d8d15 commit 1be4ba3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
11 changes: 9 additions & 2 deletions packages/synthetic-chain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> - 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 <name>] - 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
```
Expand Down
9 changes: 7 additions & 2 deletions packages/synthetic-chain/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> - 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 <name>] - 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
`;
Expand Down
23 changes: 21 additions & 2 deletions packages/synthetic-chain/src/cli/run.ts
Original file line number Diff line number Diff line change
@@ -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' });
};

Expand All @@ -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' });
};

0 comments on commit 1be4ba3

Please sign in to comment.