Skip to content

Commit

Permalink
build: DRY out yarn install script
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 7, 2023
1 parent 257cab1 commit 5104238
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
36 changes: 12 additions & 24 deletions makeDockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`;
Expand All @@ -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}
`;
Expand All @@ -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}
`;
Expand Down
26 changes: 26 additions & 0 deletions upgrade-test-scripts/install_deps.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5104238

Please sign in to comment.