# syntax=docker/dockerfile:1.4 # # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. # # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you may not use this file except in compliance with the License. # # You may obtain a copy of the License at # # # # http://www.apache.org/licenses/LICENSE-2.0 # # # # Unless required by applicable law or agreed to in writing, software # # distributed under the License is distributed on an "AS IS" BASIS, # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # # limitations under the License. # # *NOTE* we have to limit our number of layers heres because in presubmits there # # is no overlay fs and we will run out of space quickly ################# BUILDER ###################### ARG BASE_IMAGE=unused ARG BUILDER_IMAGE=unused ARG BUILT_BUILDER_IMAGE=unused ARG MINIMAL_BASE_BUILDER_IMAGE=unused ARG VERSIONED_VARIANT ARG COMPILER_VERSION=${VERSIONED_VARIANT} ARG IS_COMPILER=false ################# DOWNLOAD ON GLIBC ###################### # Download in the minimal base builder image to allow sharing result across compiler # and runtime images. We also build the cache into the runtime image # which includes the cache data for this layer and along with COPY --link # this also us to ensure this layer is always reusable across the runtime + compiler # builds without relying on the buildkitd local cache FROM ${MINIMAL_BASE_BUILDER_IMAGE} as nodejs-download ARG OUTPUT_DEBUG_LOG ARG COMPILER_FULL_VERSION # Copy scripts in every variant since we do not rebuild the base # every time these scripts change. This ensures whenever a variant is # built it has the latest scripts in the builder COPY scripts/ /usr/bin # modeled from https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html RUN export OUTPUT_DEBUG_LOG=${OUTPUT_DEBUG_LOG} && \ # Since this "layer" is used for each of the compiler variants, base/yum/gcc, we are creating a new-newroot which will be extracted # and copied specifically into the final image NODE_NEWROOT_COMPILER=/node-compiler && \ BUILD_DEPS="gzip tar" && \ NEWROOT=/ clean_install $BUILD_DEPS && \ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash && \ source ~/.nvm/nvm.sh && \ nvm install $COMPILER_FULL_VERSION && \ set -x && \ mkdir -p $NODE_NEWROOT_COMPILER/usr/share/node $NODE_NEWROOT_COMPILER/usr/{bin,lib,include} && mv ~/.nvm/versions/node/*/LICENSE $NODE_NEWROOT_COMPILER/usr/share/node && \ mv ~/.nvm/versions/node/*/include/node $NODE_NEWROOT_COMPILER/usr/include && \ mv ~/.nvm/versions/node/*/bin/* $NODE_NEWROOT_COMPILER/usr/bin && \ mv ~/.nvm/versions/node/*/lib/node_modules $NODE_NEWROOT_COMPILER/usr/lib/node_modules && \ rm -rf ~/.nvm && \ yum erase -y $BUILD_DEPS && \ NEWROOT=/ cleanup "nodejs-download" ################# COPIED LAYER ###################### FROM ${BUILDER_IMAGE} as nodejs-compiler-true COPY --link --from=nodejs-download /node-compiler /newroot FROM nodejs-compiler-true as nodejs-compiler-false # Copy scripts in every variant since we do not rebuild the base # every time these scripts change. This ensures whenever a variant is # built it has the latest scripts in the builder COPY scripts/ /usr/bin RUN set -x && \ find $NEWROOT/usr/lib/node_modules -delete && \ rm -rf $NEWROOT/usr/include/node $NEWROOT/usr/bin/{corepack,npm,npx} && \ # this already exists in the compiler images and there is a conflict # between the coreutils and coreutils-single packages # easiest thing to do is only install coreutils in runtime image # where we know it doesnt already exist if_al2023 install_binary /usr/bin/coreutils && \ cleanup "nodejs-runtime" ################# BASE WITH YUM PACKAGES ###################### # Install the base packages needed for node from yum # this layer is is not cached to ensure latest yum packages are installed FROM nodejs-compiler-${IS_COMPILER} as builder-nodejs-base ARG OUTPUT_DEBUG_LOG ARG COMPILER_VERSION # Copy scripts in every variant since we do not rebuild the base # every time these scripts change. This ensures whenever a variant is # built it has the latest scripts in the builder COPY scripts/ /usr/bin RUN set -x && \ install_binary /usr/bin/env && \ if [[ ! "$(chroot $NEWROOT node --version)" = v$COMPILER_VERSION* ]]; then echo "Unexpected version of node!" && exit 1; fi && \ cleanup "nodejs-base" FROM builder-nodejs-base as builder ################# FINAL ###################### FROM ${BUILT_BUILDER_IMAGE} as built FROM ${BASE_IMAGE} as final COPY --from=built /newroot /