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

copy 'test' dir only in TEST stage #213

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ All proposals then have two additional stages:
- `USE` Perform actions to update the chain state, to persist through the chain history. E.g. adding a vault that will be tested again in the future.
- `TEST` Test the chain state and perform new actions that should not be part of history. E.g. adding a contract that never was on Mainnet.

The `TEST` stage does not RUN as part of the build. It only defines the ENTRYPOINT and CI runs them all.
The `TEST` stage does not RUN as part of the build. It only copies "test*" files into the image and defines the ENTRYPOINT. CI runs those entrypoints to execute the tests.

The `USE` stage is built into images that are pushed to the image repository. These can be used by release branches to source a particular state of the synthetic chain.

Expand Down
16 changes: 12 additions & 4 deletions packages/synthetic-chain/src/cli/dockerfileGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
type SoftwareUpgradePackage,
} from './proposals.js';

// We need this unstable syntax for the `COPY --exclude` feature.
const syntaxPragma = '# syntax=docker/dockerfile:1.7-labs';

/**
* Templates for Dockerfile stages
*/
Expand Down Expand Up @@ -72,7 +75,7 @@ ENV \
UPGRADE_INFO=${JSON.stringify(encodeUpgradeInfo(upgradeInfo))} \
SKIP_PROPOSAL_VALIDATION=${skipProposalValidation}

COPY --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
COPY --exclude=test* --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
COPY --link --chmod=755 ./upgrade-test-scripts/env_setup.sh ./upgrade-test-scripts/run_prepare.sh ./upgrade-test-scripts/start_to_to.sh /usr/src/upgrade-test-scripts/
WORKDIR /usr/src/upgrade-test-scripts
SHELL ["/bin/bash", "-c"]
Expand All @@ -97,7 +100,7 @@ FROM ghcr.io/agoric/agoric-sdk:${sdkImageTag} as execute-${proposalName}
WORKDIR /usr/src/upgrade-test-scripts

# base is a fresh sdk image so set up the proposal and its dependencies
COPY --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
COPY --exclude=test* --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this. in agoric-3-proposals/proposals/*, we generally don't have test code segregated into test/ directories. Will this change catch files named test.sh and foo-test.js? Are we expecting to make test/ subdirectories in most proposals?

Copy link
Member Author

@turadg turadg Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we generally don't have test code segregated into test/ directories

True. To gain the benefits of this change those proposals will have to do the segregation. But it's moot for proposals in this repo as we don't iterate on those tests. The value is in agoric-sdk/a3p-integration/proposals.

Will this change catch files named test.sh and foo-test.js?

Good question. This glob gets test.sh but not foo-test.js. I expected Ava tests (in which 'test' does not lead the filename) to go in a test folder. We could glob more but have to be careful. *test* would exclude files that aren't necessarily for testing, like greatest.

If we want to be really safe we could --exclude=test --exclude=test.*. Oh, and --exclude=*.test.* should be safe and cover Ava test files (assuming the Ava default glob).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the Crabble build uses Ava to execute its eval. That's not a good design but is an example of a "test*" that is needed before test stage.

I'm trying now with the multiple globs.

COPY --link --chmod=755 ./upgrade-test-scripts/env_setup.sh ./upgrade-test-scripts/run_execute.sh ./upgrade-test-scripts/start_to_to.sh ./upgrade-test-scripts/install_deps.sh /usr/src/upgrade-test-scripts/
RUN --mount=type=cache,target=/root/.yarn ./install_deps.sh ${path}

Expand All @@ -119,7 +122,7 @@ RUN ./run_execute.sh ${planName}
# EVAL ${proposalName}
FROM use-${lastProposal.proposalName} as eval-${proposalName}

COPY --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
COPY --exclude=test* --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}

WORKDIR /usr/src/upgrade-test-scripts

Expand Down Expand Up @@ -165,6 +168,11 @@ ENTRYPOINT ./start_agd.sh
# TEST ${proposalName}
FROM use-${proposalName} as test-${proposalName}

# Everything besides test* was copied by previous stages but
# we don't copy just test* because there may be no matches. Copying extra
# does not invalidate any more than test* because nothing depends on this layer.
COPY --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}

WORKDIR /usr/src/upgrade-test-scripts

COPY --link --chmod=755 ./upgrade-test-scripts/run_test.sh /usr/src/upgrade-test-scripts/
Expand Down Expand Up @@ -211,7 +219,7 @@ export function writeDockerfile(
) {
// 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[] = ['# syntax=docker/dockerfile:1.4'];
const blocks: string[] = [syntaxPragma];

let previousProposal: ProposalInfo | null = null;

Expand Down
Loading