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

implement appending #52

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 24 additions & 10 deletions packages/synthetic-chain/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { parseArgs } from 'node:util';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { buildProposalSubmissions, buildTestImages } from './src/cli/build.js';
import { refreshDockerfile } from './src/cli/dockerfileGen.js';
import { writeDockerfile } from './src/cli/dockerfileGen.js';
import { matchOneProposal, readProposals } from './src/cli/proposals.js';
import { debugTestImage, runTestImages } from './src/cli/run.js';

// TODO change the tag to 'main' after multi-platform support https://github.com/Agoric/agoric-3-proposals/pull/32
const baseImage = 'pr-32-linux_arm64_v8';
mhofman marked this conversation as resolved.
Show resolved Hide resolved
mhofman marked this conversation as resolved.
Show resolved Hide resolved

const { positionals, values } = parseArgs({
options: {
match: { short: 'm', type: 'string' },
Expand All @@ -28,20 +31,31 @@ const [cmd] = positionals;

// TODO consider a lib like Commander for auto-gen help
const usage = `USAGE:
build
amend [<tag>] - build on top of an existing image (defaults to latest from a3p)

build - build from the beginning

test [--debug]
test [--debug] - run the tests of the proposals
`;

const buildImages = () => {
execSync(
// XXX very brittle
'cp -r node_modules/@agoric/synthetic-chain/upgrade-test-scripts .',
);
buildProposalSubmissions(proposals);
buildTestImages(proposals, values.dry);
};

switch (cmd) {
case 'amend':
const fromTag = positionals[1] || baseImage;
writeDockerfile(allProposals, fromTag);
buildImages();
break;
case 'build':
execSync(
// XXX very brittle
'cp -r node_modules/@agoric/synthetic-chain/upgrade-test-scripts .',
);
refreshDockerfile(allProposals);
buildProposalSubmissions(proposals);
buildTestImages(proposals, values.dry);
writeDockerfile(allProposals);
buildImages();
break;
case 'test':
if (values.debug) {
Expand Down
25 changes: 13 additions & 12 deletions packages/synthetic-chain/src/cli/dockerfileGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import type {
ProposalInfo,
SoftwareUpgradeProposal,
} from './proposals.js';
import { readProposals } from './proposals.js';

const agZeroUpgrade = 'agoric-upgrade-7-2';

// TODO change the tag to 'main' after multi-platform support https://github.com/Agoric/agoric-3-proposals/pull/32
const baseImage = 'ghcr.io/agoric/agoric-3-proposals:pr-32-linux_arm64_v8';

/**
* Templates for Dockerfile stages
Expand All @@ -24,6 +18,7 @@ const stage = {
* @param to
*/
START(proposalName: string, to: string) {
const agZeroUpgrade = 'agoric-upgrade-7-2';
return `
## START
# on ${agZeroUpgrade}, with upgrade to ${to}
Expand All @@ -40,15 +35,16 @@ RUN /usr/src/upgrade-test-scripts/start_ag0.sh
`;
},
/**
* Resume from latest production state
* Resume from state of an existing image
* @param fromTag
* @param proposalName
* @param to
*/
RESUME(proposalName: string, to: string) {
RESUME(fromTag: string, proposalName: string, to: string) {
return `
## RESUME
# on a3p base, with upgrade to ${to}
FROM ${baseImage} as prepare-${proposalName}
FROM ghcr.io/agoric/agoric-3-proposals:${fromTag} as prepare-${proposalName}
mhofman marked this conversation as resolved.
Show resolved Hide resolved
`;
},

Expand Down Expand Up @@ -209,7 +205,10 @@ ENTRYPOINT ./start_agd.sh
},
};

export function refreshDockerfile(allProposals: ProposalInfo[]) {
export function writeDockerfile(
allProposals: ProposalInfo[],
fromTag?: string,
) {
// Each stage tests something about the left argument and prepare an upgrade to the right side (by passing the proposal and halting the chain.)
// The upgrade doesn't happen until the next stage begins executing.
const blocks: string[] = [];
Expand All @@ -227,9 +226,11 @@ export function refreshDockerfile(allProposals: ProposalInfo[]) {
// handle the first proposal specially
if (previousProposal) {
blocks.push(stage.PREPARE(proposal, previousProposal));
} else if (fromTag) {
blocks.push(
stage.RESUME(fromTag, proposal.proposalName, proposal.planName),
);
} else {
// TODO for external use, provide a way to stack upgrades onto an existing chain
// blocks.push(stage.RESUME(proposal.proposalName, proposal.planName));
blocks.push(stage.START(proposal.proposalName, proposal.planName));
}
blocks.push(stage.EXECUTE(proposal));
Expand Down