From 3ca97d9f7164ac158a253354837970177e1d2f4e Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 19 Mar 2021 10:02:01 +0100 Subject: [PATCH] feat(superchain): install both Node 10 and Node 14 (#2718) We want to switch to Node 14 for CDK v2, and so we need Node 14 be present in the Superchain image. At the same time, we want to continue testing v1 against Node 10, so we ALSO need Node 10 present in the image. Use NVM to install both versions in parallel and providing a command to switch between the two. Node 10 is the default, build scripts can switch to Node14 by doing either: ``` $ nvm use 14 $ nvm exec 14 ``` --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- superchain/Dockerfile | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/superchain/Dockerfile b/superchain/Dockerfile index e156799403..1b3cfeb97e 100644 --- a/superchain/Dockerfile +++ b/superchain/Dockerfile @@ -83,16 +83,27 @@ RUN amazon-linux-extras install docker && yum clean all && rm -rf /var/cache/yum VOLUME /var/lib/docker -# Install Node 10+ -RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - \ - && yum -y install nodejs \ - && yum clean all && rm -rf /var/cache/yum \ +# Install Node using NVM (Node Version Manager) so we can have multiple Node versions installed and easily switch +# between them. +ENV NVM_DIR /usr/local/nvm + +RUN mkdir -p $NVM_DIR && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash - \ + && echo 'source "$NVM_DIR/nvm.sh"' >> $HOME/.bash_profile + +# Because we wrote things to .bash_profile, make the default shell a login shell so it gets sourced. +# Also set BASH_ENV to make bash source this EVEN if it's not a login shell (later on when the container +# gets executed) +SHELL [ "/bin/bash", "--login", "-c" ] +ENV BASH_ENV /root/.bash_profile + +# Source NVM into this shell and install Node 10 and 14. First installed version (10) becomes default. +RUN nvm install 10 \ + && nvm install 14 \ && npm set unsafe-perm true -# Install Yarn -RUN curl -sSL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo \ - && yum -y install yarn \ - && yum clean all && rm -rf /var/cache/yum +# Can't install Yarn using yum anymore now that we're using nvm, so install it using NPM +RUN nvm exec 10 npm install -g yarn \ + && nvm exec 14 npm install -g yarn # Install some configuration COPY ssh_config /root/.ssh/config @@ -113,4 +124,4 @@ LABEL org.opencontainers.image.created=${BUILD_TIMESTAMP} org.opencontainers.image.revision=$COMMIT_ID \ org.opencontainers.image.authors="Amazon Web Services (https://aws.amazon.com)" -CMD ["/bin/bash"] +CMD ["/bin/bash", "--login"]