Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(synthetic-chain): Propagate environment variable SLOGFILE into containers #191

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });
};
Loading