From ed8576decc79a29eb9aa989aeec7a47515044dcb Mon Sep 17 00:00:00 2001 From: Chaoneng Quan Date: Thu, 26 Dec 2024 16:04:08 -0800 Subject: [PATCH 1/2] feat: Ensure micromamba meets minimum required version during build --- .gitignore | 1 + template/v2/Dockerfile | 14 ++++++++++++++ template/v3/Dockerfile | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/.gitignore b/.gitignore index 120ee635..88a2a622 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ .idea .DS_Store +.vscode \ No newline at end of file diff --git a/template/v2/Dockerfile b/template/v2/Dockerfile index b596638a..caab28ab 100644 --- a/template/v2/Dockerfile +++ b/template/v2/Dockerfile @@ -17,13 +17,27 @@ ARG NB_GID=100 # https://www.openssl.org/source/ ARG FIPS_VALIDATED_SSL=3.0.8 +ARG MIN_REQUIRED_MICROMAMBA_VERSION=1.5.11 ENV SAGEMAKER_LOGGING_DIR="/var/log/sagemaker/" ENV STUDIO_LOGGING_DIR="/var/log/studio/" ENV EDITOR="nano" ENV IMAGE_VERSION=$IMAGE_VERSION +ENV MIN_REQUIRED_MICROMAMBA_VERSION=${MIN_REQUIRED_MICROMAMBA_VERSION} USER root + +# Compare the current micromamba version with the minimum required version, and only upgrade if strictly lower to avoid downgrades. +RUN CURRENT_MICROMAMBA_VERSION=$(micromamba --version) && \ + LOWEST_MICROMAMBA_VERSION=$(printf '%s\n%s' "$MIN_REQUIRED_MICROMAMBA_VERSION" "$CURRENT_MICROMAMBA_VERSION" | sort -V | head -n 1) && \ + if [ "$LOWEST_MICROMAMBA_VERSION" = "$CURRENT_MICROMAMBA_VERSION" ] && [ "$CURRENT_MICROMAMBA_VERSION" != "$MIN_REQUIRED_MICROMAMBA_VERSION" ]; then \ + echo "Upgrading micromamba from $CURRENT_MICROMAMBA_VERSION to $MIN_REQUIRED_MICROMAMBA_VERSION..." && \ + micromamba self-update -c conda-forge --version "$MIN_REQUIRED_MICROMAMBA_VERSION"; \ + else \ + echo "Micromamba is already $MIN_REQUIRED_MICROMAMBA_VERSION or higher (current: $CURRENT_MICROMAMBA_VERSION). No update needed."; \ + fi + + RUN usermod "--login=${NB_USER}" "--home=/home/${NB_USER}" --move-home "-u ${NB_UID}" "${MAMBA_USER}" && \ groupmod "--new-name=${NB_USER}" --non-unique "-g ${NB_GID}" "${MAMBA_USER}" && \ # Update the expected value of MAMBA_USER for the diff --git a/template/v3/Dockerfile b/template/v3/Dockerfile index 26881dc8..4cfb9e30 100644 --- a/template/v3/Dockerfile +++ b/template/v3/Dockerfile @@ -15,12 +15,26 @@ ARG NB_GID=100 # https://www.openssl.org/source/ ARG FIPS_VALIDATED_SSL=3.0.8 +ARG MIN_REQUIRED_MICROMAMBA_VERSION=1.5.11 ENV SAGEMAKER_LOGGING_DIR="/var/log/sagemaker/" ENV STUDIO_LOGGING_DIR="/var/log/studio/" ENV EDITOR="nano" +ENV MIN_REQUIRED_MICROMAMBA_VERSION=${MIN_REQUIRED_MICROMAMBA_VERSION} USER root + +# Compare the current micromamba version with the minimum required version, and only upgrade if strictly lower to avoid downgrades. +RUN CURRENT_MICROMAMBA_VERSION=$(micromamba --version) && \ + LOWEST_MICROMAMBA_VERSION=$(printf '%s\n%s' "$MIN_REQUIRED_MICROMAMBA_VERSION" "$CURRENT_MICROMAMBA_VERSION" | sort -V | head -n 1) && \ + if [ "$LOWEST_MICROMAMBA_VERSION" = "$CURRENT_MICROMAMBA_VERSION" ] && [ "$CURRENT_MICROMAMBA_VERSION" != "$MIN_REQUIRED_MICROMAMBA_VERSION" ]; then \ + echo "Upgrading micromamba from $CURRENT_MICROMAMBA_VERSION to $MIN_REQUIRED_MICROMAMBA_VERSION..." && \ + micromamba self-update -c conda-forge --version "$MIN_REQUIRED_MICROMAMBA_VERSION"; \ + else \ + echo "Micromamba is already $MIN_REQUIRED_MICROMAMBA_VERSION or higher (current: $CURRENT_MICROMAMBA_VERSION). No update needed."; \ + fi + + RUN usermod "--login=${NB_USER}" "--home=/home/${NB_USER}" --move-home "-u ${NB_UID}" "${MAMBA_USER}" && \ groupmod "--new-name=${NB_USER}" --non-unique "-g ${NB_GID}" "${MAMBA_USER}" && \ # Update the expected value of MAMBA_USER for the From 816d4d9ba5b4d1a930a0b26e1ae3fb3b3887f851 Mon Sep 17 00:00:00 2001 From: Chaoneng Quan Date: Fri, 27 Dec 2024 12:58:32 -0800 Subject: [PATCH 2/2] feat: upgrade micromamba to the latest patch version within the pinned minor version range (1.5.*) --- template/v0/Dockerfile | 11 +++++++++++ template/v1/Dockerfile | 11 +++++++++++ template/v2/Dockerfile | 16 +++++++--------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/template/v0/Dockerfile b/template/v0/Dockerfile index 8c89eb81..614268d4 100644 --- a/template/v0/Dockerfile +++ b/template/v0/Dockerfile @@ -18,8 +18,19 @@ ENV SAGEMAKER_LOGGING_DIR="/var/log/sagemaker/" ENV STUDIO_LOGGING_DIR="/var/log/studio/" ENV EDITOR="nano" ENV IMAGE_VERSION=$IMAGE_VERSION +ENV PINNED_MICROMAMBA_MINOR_VERSION="1.5.*" USER root +# Upgrade micromamba to the latest patch version in the pinned minor version range, if applicable +RUN CURRENT_MICROMAMBA_VERSION=$(micromamba --version) && \ + echo "Current micromamba version: $CURRENT_MICROMAMBA_VERSION" && \ + if [[ "$CURRENT_MICROMAMBA_VERSION" == $PINNED_MICROMAMBA_MINOR_VERSION ]]; then \ + echo "Upgrading micromamba to the latest $PINNED_MICROMAMBA_MINOR_VERSION version..." && \ + micromamba self-update -c conda-forge --version "$PINNED_MICROMAMBA_MINOR_VERSION"; \ + else \ + echo "Micromamba is already at version $CURRENT_MICROMAMBA_VERSION (outside $PINNED_MICROMAMBA_MINOR_VERSION). No upgrade performed."; \ + fi + RUN usermod "--login=${NB_USER}" "--home=/home/${NB_USER}" --move-home "-u ${NB_UID}" "${MAMBA_USER}" && \ groupmod "--new-name=${NB_USER}" --non-unique "-g ${NB_GID}" "${MAMBA_USER}" && \ # Update the expected value of MAMBA_USER for the diff --git a/template/v1/Dockerfile b/template/v1/Dockerfile index 2178e544..86ec6bee 100644 --- a/template/v1/Dockerfile +++ b/template/v1/Dockerfile @@ -21,8 +21,19 @@ ENV SAGEMAKER_LOGGING_DIR="/var/log/sagemaker/" ENV STUDIO_LOGGING_DIR="/var/log/studio/" ENV EDITOR="nano" ENV IMAGE_VERSION=$IMAGE_VERSION +ENV PINNED_MICROMAMBA_MINOR_VERSION="1.5.*" USER root +# Upgrade micromamba to the latest patch version in the pinned minor version range, if applicable +RUN CURRENT_MICROMAMBA_VERSION=$(micromamba --version) && \ + echo "Current micromamba version: $CURRENT_MICROMAMBA_VERSION" && \ + if [[ "$CURRENT_MICROMAMBA_VERSION" == $PINNED_MICROMAMBA_MINOR_VERSION ]]; then \ + echo "Upgrading micromamba to the latest $PINNED_MICROMAMBA_MINOR_VERSION version..." && \ + micromamba self-update -c conda-forge --version "$PINNED_MICROMAMBA_MINOR_VERSION"; \ + else \ + echo "Micromamba is already at version $CURRENT_MICROMAMBA_VERSION (outside $PINNED_MICROMAMBA_MINOR_VERSION). No upgrade performed."; \ + fi + RUN usermod "--login=${NB_USER}" "--home=/home/${NB_USER}" --move-home "-u ${NB_UID}" "${MAMBA_USER}" && \ groupmod "--new-name=${NB_USER}" --non-unique "-g ${NB_GID}" "${MAMBA_USER}" && \ # Update the expected value of MAMBA_USER for the diff --git a/template/v2/Dockerfile b/template/v2/Dockerfile index caab28ab..38322750 100644 --- a/template/v2/Dockerfile +++ b/template/v2/Dockerfile @@ -23,21 +23,19 @@ ENV SAGEMAKER_LOGGING_DIR="/var/log/sagemaker/" ENV STUDIO_LOGGING_DIR="/var/log/studio/" ENV EDITOR="nano" ENV IMAGE_VERSION=$IMAGE_VERSION -ENV MIN_REQUIRED_MICROMAMBA_VERSION=${MIN_REQUIRED_MICROMAMBA_VERSION} +ENV PINNED_MICROMAMBA_MINOR_VERSION="1.5.*" USER root - -# Compare the current micromamba version with the minimum required version, and only upgrade if strictly lower to avoid downgrades. +# Upgrade micromamba to the latest patch version in the pinned minor version range, if applicable RUN CURRENT_MICROMAMBA_VERSION=$(micromamba --version) && \ - LOWEST_MICROMAMBA_VERSION=$(printf '%s\n%s' "$MIN_REQUIRED_MICROMAMBA_VERSION" "$CURRENT_MICROMAMBA_VERSION" | sort -V | head -n 1) && \ - if [ "$LOWEST_MICROMAMBA_VERSION" = "$CURRENT_MICROMAMBA_VERSION" ] && [ "$CURRENT_MICROMAMBA_VERSION" != "$MIN_REQUIRED_MICROMAMBA_VERSION" ]; then \ - echo "Upgrading micromamba from $CURRENT_MICROMAMBA_VERSION to $MIN_REQUIRED_MICROMAMBA_VERSION..." && \ - micromamba self-update -c conda-forge --version "$MIN_REQUIRED_MICROMAMBA_VERSION"; \ + echo "Current micromamba version: $CURRENT_MICROMAMBA_VERSION" && \ + if [[ "$CURRENT_MICROMAMBA_VERSION" == $PINNED_MICROMAMBA_MINOR_VERSION ]]; then \ + echo "Upgrading micromamba to the latest $PINNED_MICROMAMBA_MINOR_VERSION version..." && \ + micromamba self-update -c conda-forge --version "$PINNED_MICROMAMBA_MINOR_VERSION"; \ else \ - echo "Micromamba is already $MIN_REQUIRED_MICROMAMBA_VERSION or higher (current: $CURRENT_MICROMAMBA_VERSION). No update needed."; \ + echo "Micromamba is already at version $CURRENT_MICROMAMBA_VERSION (outside $PINNED_MICROMAMBA_MINOR_VERSION). No upgrade performed."; \ fi - RUN usermod "--login=${NB_USER}" "--home=/home/${NB_USER}" --move-home "-u ${NB_UID}" "${MAMBA_USER}" && \ groupmod "--new-name=${NB_USER}" --non-unique "-g ${NB_GID}" "${MAMBA_USER}" && \ # Update the expected value of MAMBA_USER for the