-
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 18 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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||||
import chalk from 'chalk'; | ||||||||
import assert from 'node:assert'; | ||||||||
import { execSync } from 'node:child_process'; | ||||||||
import { existsSync } from 'node:fs'; | ||||||||
import path from 'node:path'; | ||||||||
import { parseArgs } from 'node:util'; | ||||||||
import { | ||||||||
|
@@ -63,6 +64,8 @@ Until https://github.com/docker/roadmap/issues/371, attempting it will error as | |||||||
Instead use a builder that supports multiplatform such as depot.dev. | ||||||||
`; | ||||||||
|
||||||||
const fileExists = (name: string) => existsSync(name); | ||||||||
|
||||||||
/** | ||||||||
* Put into places files that building depends upon. | ||||||||
*/ | ||||||||
|
@@ -117,7 +120,20 @@ switch (cmd) { | |||||||
console.log(chalk.cyan.bold(`Testing ${proposal.proposalName}`)); | ||||||||
const image = imageNameForProposal(proposal, 'test'); | ||||||||
bakeTarget(image.target, values.dry); | ||||||||
|
||||||||
const proposalHostScriptsDirectoryPath = `${root}/proposals/${proposal.path}/host`; | ||||||||
|
||||||||
const afterHookScriptPath = `${proposalHostScriptsDirectoryPath}/after-test-run.sh`; | ||||||||
const beforeHookScriptPath = `${proposalHostScriptsDirectoryPath}/before-test-run.sh`; | ||||||||
|
||||||||
fileExists(beforeHookScriptPath) && | ||||||||
execSync(beforeHookScriptPath, { stdio: 'inherit' }); | ||||||||
|
||||||||
runTestImage(proposal); | ||||||||
|
||||||||
fileExists(afterHookScriptPath) && | ||||||||
execSync(afterHookScriptPath, { stdio: 'inherit' }); | ||||||||
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. consider having a helper,
Suggested change
Then the above three consts don't need to be defined and when someone searched 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. Please add running the hooks in case we're in 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 |
||||||||
|
||||||||
// delete the image to reclaim disk space. The next build | ||||||||
// will use the build cache. | ||||||||
execSync('docker system df', { stdio: 'inherit' }); | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import { execSync } from 'node:child_process'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { realpathSync } from 'node:fs'; | ||
import { ProposalInfo, imageNameForProposal } from './proposals.js'; | ||
|
||
const propagateMessageFilePath = (env: typeof process.env) => { | ||
const fileName = 'message-file-path.tmp'; | ||
const { HOME } = env; | ||
usmanmani1122 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const containerFilePath = `/root/${fileName}`; | ||
const filePath = `${HOME}/${fileName}`; | ||
|
||
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'm feeling uncomfortable with synthetic-chain hardcoding such a file, especially into the host's home dir. Furthermore I believe this will fail when multiple test containers run concurrently. Let's use a dynamically generated temp file, and set it in an environment variable available in the host hook scripts (I assume this is where it's needed). The container path can remain static. 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 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 don't believe this was addressed. I do not want us to write anything on the host's
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 will move the file to 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. BTW I have made the change (message file is in 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. My concern was 2 fold:
I agree that correctly cleaning up after the test would mitigate both the concerns, but in general I prefer to respect the semantics of the file system. |
||
spawnSync('touch', [filePath]); | ||
|
||
return [ | ||
'--env', | ||
`MESSAGE_FILE_PATH=${containerFilePath}`, | ||
'--mount', | ||
`source=${filePath},target=${containerFilePath},type=bind`, | ||
]; | ||
}; | ||
|
||
/** | ||
* 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,17 +31,32 @@ 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) => { | ||
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', | ||
'--network', | ||
'host', | ||
'--rm', | ||
...propagateSlogfile(process.env), | ||
...propagateMessageFilePath(process.env), | ||
name, | ||
], | ||
{ stdio: 'inherit' }, | ||
); | ||
}; | ||
|
||
export const debugTestImage = (proposal: ProposalInfo) => { | ||
|
@@ -46,8 +78,24 @@ 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', | ||
'26657:26657', | ||
'--publish', | ||
'1317:1317', | ||
'--publish', | ||
'9090:9090', | ||
'--tty', | ||
...propagateSlogfile(process.env), | ||
name, | ||
], | ||
{ stdio: 'inherit' }, | ||
); | ||
}; |
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