From 5104238ab9008f853d9ef6fd395495cb47b7be33 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 7 Nov 2023 11:03:40 -0800 Subject: [PATCH] build: DRY out yarn install script --- makeDockerfile.ts | 36 ++++++++++------------------ upgrade-test-scripts/install_deps.sh | 26 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 24 deletions(-) create mode 100755 upgrade-test-scripts/install_deps.sh diff --git a/makeDockerfile.ts b/makeDockerfile.ts index 04e6a512..0b6e61ea 100755 --- a/makeDockerfile.ts +++ b/makeDockerfile.ts @@ -93,17 +93,13 @@ FROM use-${lastProposal.proposalName} as eval-${proposalName} COPY --link --chmod=755 ./proposals/${proposalIdentifier}:${proposalName} /usr/src/proposals/${proposalIdentifier}:${proposalName} +WORKDIR /usr/src/upgrade-test-scripts + # install using global cache -RUN --mount=type=cache,target=/root/.yarn \ - cd /usr/src/upgrade-test-scripts/lib/ \ - && corepack enable \ - && yarn --version \ - && yarn install \ - && cd /usr/src/proposals/${proposalIdentifier}:${proposalName} \ - && test -n "yarn.lock" && yarn install --immutable +COPY --link ./upgrade-test-scripts/install_deps.sh /usr/src/upgrade-test-scripts/ +RUN --mount=type=cache,target=/root/.yarn ./install_deps.sh ${proposalIdentifier}:${proposalName} COPY --link --chmod=755 ./upgrade-test-scripts/run_eval.sh /usr/src/upgrade-test-scripts/run_eval.sh -WORKDIR /usr/src/upgrade-test-scripts SHELL ["/bin/bash", "-c"] RUN ./run_eval.sh ${proposalIdentifier}:${proposalName} `; @@ -122,20 +118,16 @@ FROM ${previousStage}-${proposalName} as use-${proposalName} COPY --link --chmod=755 ./proposals/${proposalIdentifier}:${proposalName} /usr/src/proposals/${proposalIdentifier}:${proposalName} +WORKDIR /usr/src/upgrade-test-scripts + # XXX for 'lib' dir for JS modules COPY --link ./upgrade-test-scripts/lib /usr/src/upgrade-test-scripts/lib # TODO remove network dependencies in stages # install using global cache -RUN --mount=type=cache,target=/root/.yarn \ - cd /usr/src/upgrade-test-scripts/lib/ \ - && corepack enable \ - && yarn --version \ - && yarn install \ - && cd /usr/src/proposals/${proposalIdentifier}:${proposalName} \ - && test -n "yarn.lock" && yarn install --immutable +COPY --link ./upgrade-test-scripts/install_deps.sh /usr/src/upgrade-test-scripts/ +RUN --mount=type=cache,target=/root/.yarn ./install_deps.sh ${proposalIdentifier}:${proposalName} COPY --link --chmod=755 ./upgrade-test-scripts/run_use.sh /usr/src/upgrade-test-scripts/run_use.sh -WORKDIR /usr/src/upgrade-test-scripts SHELL ["/bin/bash", "-c"] RUN ./run_use.sh ${proposalIdentifier}:${proposalName} `; @@ -153,17 +145,13 @@ RUN ./run_use.sh ${proposalIdentifier}:${proposalName} # TEST ${proposalName} FROM use-${proposalName} as test-${proposalName} +WORKDIR /usr/src/upgrade-test-scripts + # install using global cache -RUN --mount=type=cache,target=/root/.yarn \ - cd /usr/src/upgrade-test-scripts/lib/ \ - && corepack enable \ - && yarn --version \ - && yarn install \ - && cd /usr/src/proposals/${proposalIdentifier}:${proposalName} \ - && test -n "yarn.lock" && yarn install --immutable +COPY --link ./upgrade-test-scripts/install_deps.sh /usr/src/upgrade-test-scripts/ +RUN --mount=type=cache,target=/root/.yarn ./install_deps.sh ${proposalIdentifier}:${proposalName} COPY --link --chmod=755 ./upgrade-test-scripts/run_test.sh /usr/src/upgrade-test-scripts/run_test.sh -WORKDIR /usr/src/upgrade-test-scripts SHELL ["/bin/bash", "-c"] ENTRYPOINT ./run_test.sh ${proposalIdentifier}:${proposalName} `; diff --git a/upgrade-test-scripts/install_deps.sh b/upgrade-test-scripts/install_deps.sh new file mode 100755 index 00000000..f6ac8632 --- /dev/null +++ b/upgrade-test-scripts/install_deps.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +PROPOSAL_PATH=$1 + +# The base image is Node 16.9, which supports Corepack. +# Yarn v4 requires Node 18+ but so far it's working with 16.19. +export YARN_IGNORE_NODE=1 + +corepack enable +yarn --version + +# Run where this script is +cd "$(dirname "$(realpath -- "$0")")" + +pushd ./lib/ +yarn install +popd + +# TODO consider yarn workspaces to install all in one command +if [ -n "$PROPOSAL_PATH" ]; then + cd "../proposals/$PROPOSAL_PATH" + # install only if the proposal has a yarn.lock + test -n "yarn.lock" && yarn install --immutable +fi