Skip to content

Commit

Permalink
feat(superchain): install both Node 10 and Node 14 (#2718)
Browse files Browse the repository at this point in the history
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 <command>
```



---

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
  • Loading branch information
rix0rrr authored Mar 19, 2021
1 parent ccac1bd commit 3ca97d9
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions superchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

0 comments on commit 3ca97d9

Please sign in to comment.