Skip to content

Commit

Permalink
exclude node_modules from docker build context
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanmani1122 committed Feb 7, 2025
1 parent 6d41781 commit 64a3537
Showing 1 changed file with 74 additions and 11 deletions.
85 changes: 74 additions & 11 deletions packages/synthetic-chain/src/cli/dockerfileGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ ENV UPGRADE_TO=${to}
RUN echo '. /usr/src/upgrade-test-scripts/env_setup.sh' >> ~/.bashrc
# copy scripts
COPY --link --chmod=755 ./upgrade-test-scripts/env_setup.sh ./upgrade-test-scripts/run_prepare_zero.sh /usr/src/upgrade-test-scripts/
${createCopyCommand(
[],
'./upgrade-test-scripts/env_setup.sh',
'./upgrade-test-scripts/run_prepare_zero.sh',
'/usr/src/upgrade-test-scripts/',
)}
SHELL ["/bin/bash", "-c"]
# this is the only layer that starts ag0
RUN /usr/src/upgrade-test-scripts/run_prepare_zero.sh
Expand Down Expand Up @@ -75,8 +80,18 @@ ENV \
UPGRADE_INFO=${JSON.stringify(encodeUpgradeInfo(upgradeInfo))} \
SKIP_PROPOSAL_VALIDATION=${skipProposalValidation}
COPY --exclude=test --exclude=test.sh --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/
${createCopyCommand(
['node_modules', 'test', 'test.sh'],
`./proposals/${path}`,
`/usr/src/proposals/${path}`,
)}
${createCopyCommand(
[],
'./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"]
RUN ./run_prepare.sh ${path}
Expand All @@ -100,8 +115,19 @@ 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 --exclude=test --exclude=test.sh --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
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/
${createCopyCommand(
['node_modules', 'test', 'test.sh'],
`./proposals/${path}`,
`/usr/src/proposals/${path}`,
)}
${createCopyCommand(
[],
'./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}
COPY --link --from=prepare-${proposalName} /root/.agoric /root/.agoric
Expand All @@ -122,15 +148,27 @@ RUN ./run_execute.sh ${planName}
# EVAL ${proposalName}
FROM use-${lastProposal.proposalName} as eval-${proposalName}
COPY --exclude=test --exclude=test.sh --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
${createCopyCommand(
['node_modules', 'test', 'test.sh'],
`./proposals/${path}`,
`/usr/src/proposals/${path}`,
)}
WORKDIR /usr/src/upgrade-test-scripts
# First stage of this proposal so install its deps.
COPY --link ./upgrade-test-scripts/install_deps.sh /usr/src/upgrade-test-scripts/
${createCopyCommand(
[],
'./upgrade-test-scripts/install_deps.sh',
'/usr/src/upgrade-test-scripts/',
)}
RUN --mount=type=cache,target=/root/.yarn ./install_deps.sh ${path}
COPY --link --chmod=755 ./upgrade-test-scripts/*eval* /usr/src/upgrade-test-scripts/
${createCopyCommand(
[],
'./upgrade-test-scripts/*eval*',
'/usr/src/upgrade-test-scripts/',
)}
SHELL ["/bin/bash", "-c"]
RUN ./run_eval.sh ${path}
`;
Expand All @@ -149,7 +187,12 @@ FROM ${previousStage}-${proposalName} as use-${proposalName}
WORKDIR /usr/src/upgrade-test-scripts
COPY --link --chmod=755 ./upgrade-test-scripts/run_use.sh ./upgrade-test-scripts/start_agd.sh /usr/src/upgrade-test-scripts/
${createCopyCommand(
[],
'./upgrade-test-scripts/run_use.sh',
'./upgrade-test-scripts/start_agd.sh',
'/usr/src/upgrade-test-scripts/',
)}
SHELL ["/bin/bash", "-c"]
RUN ./run_use.sh ${path}
ENTRYPOINT ./start_agd.sh
Expand All @@ -171,11 +214,19 @@ FROM use-${proposalName} as test-${proposalName}
# Previous stages copied excluding test files (see COPY above). It would be good
# to copy only missing files, but there may be none. Fortunately, copying extra
# does not invalidate other images because nothing depends on this layer.
COPY --link --chmod=755 ./proposals/${path} /usr/src/proposals/${path}
${createCopyCommand(
['node_modules'],
`./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/
${createCopyCommand(
[],
'./upgrade-test-scripts/run_test.sh',
'/usr/src/upgrade-test-scripts/',
)}
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ./run_test.sh ${path}
`;
Expand All @@ -196,6 +247,18 @@ FROM ${useImage} as latest
},
};

export const createCopyCommand = (
exclusionList: Array<string>,
...files: Array<string>
) =>
[
'COPY',
'--link',
'--chmod=755',
...exclusionList.map(excluded => `--exclude=${excluded}`),
...files,
].join(' ');

export function writeBakefileProposals(
allProposals: ProposalInfo[],
platforms?: Platform[],
Expand Down

0 comments on commit 64a3537

Please sign in to comment.