-
Notifications
You must be signed in to change notification settings - Fork 7
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: proposal pre/post test steps #210
Changes from 23 commits
2660fec
8e3f3e4
df80864
0554920
5d4e465
2c94fef
a689ecc
61371f5
9f24947
3d6780c
5b4c029
608e2da
0ee2a77
7ad7d92
f55ef1f
8b22861
b89fe4f
6d5c227
f121f67
679a083
f983826
36a2a20
5d54940
ef3d10b
963e59f
1a137a4
12c5042
ac2c07b
b34bdb6
73a9c4b
9d67bc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
import { execSync } from 'node:child_process'; | ||
import { realpathSync } from 'node:fs'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { existsSync, realpathSync } from 'node:fs'; | ||
import { resolve as resolvePath } from 'node:path'; | ||
import { ProposalInfo, imageNameForProposal } from './proposals.js'; | ||
|
||
const createMessageFile = () => { | ||
const messageFileName = `${new Date().getTime()}.tmp`; | ||
const messageFilePath = `/tmp/${messageFileName}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure adding a dependency of |
||
spawnSync('touch', [messageFilePath]); | ||
return [messageFileName, messageFilePath]; | ||
}; | ||
|
||
const executeHostScriptIfPresent = ( | ||
proposal: ProposalInfo, | ||
scriptName: string, | ||
) => { | ||
const scriptPath = `${resolvePath('.')}/proposals/${proposal.path}/host/${scriptName}`; | ||
if (existsSync(scriptPath)) { | ||
console.log( | ||
`Running script ${scriptName} for proposal ${proposal.proposalName}`, | ||
); | ||
spawnSync(scriptPath, { env: process.env, stdio: 'inherit' }); | ||
} | ||
}; | ||
|
||
/** | ||
* 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 | ||
|
@@ -14,20 +35,50 @@ const propagateSlogfile = env => { | |
const { SLOGFILE } = env; | ||
if (!SLOGFILE) return []; | ||
|
||
execSync('touch "$SLOGFILE"'); | ||
return ['-e', 'SLOGFILE', '-v', `"$SLOGFILE:${realpathSync(SLOGFILE)}"`]; | ||
spawnSync('touch', [SLOGFILE]); | ||
|
||
return [ | ||
'--env', | ||
`SLOGFILE=${SLOGFILE}`, | ||
'--volume', | ||
`${SLOGFILE}:${realpathSync(SLOGFILE)}`, | ||
]; | ||
}; | ||
|
||
export const runTestImage = (proposal: ProposalInfo) => { | ||
const [messageFileName, messageFilePath] = createMessageFile(); | ||
|
||
const containerFilePath = `/root/${messageFileName}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we would have the message file in the container use a static name (not even related to the proposal name) to avoid having to plumb an extra env. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Container file doesn't necessarily need to use the proposal name in it's path, but we still need to pass the host file path to the host start script so that the follower can mount that file in it's container There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right but the code above will make the container file name dynamic, without any way for the container script to figure out what that name is. Or am I missing something? |
||
process.env.MESSAGE_FILE_PATH = messageFilePath; | ||
|
||
executeHostScriptIfPresent(proposal, 'before-test-run.sh'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be preferable to plumb the You can either spread the current env, or use inheritance ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
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 ${slogOpts.join(' ')} --rm ${name}`; | ||
execSync(cmd, { stdio: 'inherit' }); | ||
spawnSync( | ||
'docker', | ||
[ | ||
'run', | ||
'--env', | ||
`MESSAGE_FILE_PATH=${containerFilePath}`, | ||
'--mount', | ||
`source=${messageFilePath},target=${containerFilePath},type=bind`, | ||
'--network', | ||
'host', | ||
'--rm', | ||
...propagateSlogfile(process.env), | ||
name, | ||
], | ||
{ stdio: 'inherit' }, | ||
); | ||
|
||
spawnSync('rm', ['--force', messageFilePath]); | ||
|
||
executeHostScriptIfPresent(proposal, 'after-test-run.sh'); | ||
}; | ||
|
||
export const debugTestImage = (proposal: ProposalInfo) => { | ||
executeHostScriptIfPresent(proposal, 'before-test-run.sh'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, we don't expect tests run in debug mode to have a message file? Is there not a risk that host scripts would expect a message file and break if not available? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid point |
||
const { name } = imageNameForProposal(proposal, 'test'); | ||
console.log( | ||
` | ||
|
@@ -46,8 +97,25 @@ export const debugTestImage = (proposal: ProposalInfo) => { | |
`, | ||
); | ||
|
||
const slogOpts = propagateSlogfile(process.env); | ||
// start the chain with ports mapped | ||
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' }); | ||
spawnSync( | ||
'docker', | ||
[ | ||
'run', | ||
'--entrypoint', | ||
'/usr/src/upgrade-test-scripts/start_agd.sh', | ||
'--interactive', | ||
'--publish', | ||
'1317:1317', | ||
'--publish', | ||
'9090:9090', | ||
'--publish', | ||
'26657:26657', | ||
'--tty', | ||
...propagateSlogfile(process.env), | ||
name, | ||
], | ||
{ stdio: 'inherit' }, | ||
); | ||
executeHostScriptIfPresent(proposal, 'after-test-run.sh'); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be more explicit about what the
host
folder is for. There has been some confusion: Agoric/agoric-sdk#10947 (comment)While you're at it a change like this would help,
This is not blocking feedback. If something is delayed by this PR the docs improvements can come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added