From 64a3537b65301569fa86757c3fd0b545411d3b62 Mon Sep 17 00:00:00 2001 From: usmanmani1122 Date: Fri, 7 Feb 2025 11:27:43 +0500 Subject: [PATCH] exclude node_modules from docker build context --- .../synthetic-chain/src/cli/dockerfileGen.ts | 85 ++++++++++++++++--- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/packages/synthetic-chain/src/cli/dockerfileGen.ts b/packages/synthetic-chain/src/cli/dockerfileGen.ts index e5ac9e77..75887a1f 100755 --- a/packages/synthetic-chain/src/cli/dockerfileGen.ts +++ b/packages/synthetic-chain/src/cli/dockerfileGen.ts @@ -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 @@ -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} @@ -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 @@ -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} `; @@ -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 @@ -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} `; @@ -196,6 +247,18 @@ FROM ${useImage} as latest }, }; +export const createCopyCommand = ( + exclusionList: Array, + ...files: Array +) => + [ + 'COPY', + '--link', + '--chmod=755', + ...exclusionList.map(excluded => `--exclude=${excluded}`), + ...files, + ].join(' '); + export function writeBakefileProposals( allProposals: ProposalInfo[], platforms?: Platform[],