Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the release container does not contain any unintended files #1807

Merged
merged 13 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# [base] -> [conda_env] -> [base_extended] -> [runtime_conda_create] -> [runtime]
# \
# [conda_env_dev] -> [development] -> [development_pydbg]
# \
# [build_docs]
# \
# [git_clone]
#
# base: Contains all system packages common across all environments
# conda_env: Create morpheus conda environment and set it as the new base
Expand All @@ -35,6 +39,9 @@
# source directory.
# development_pydbg: Development + debug build of cpython and various GDB
# debugging macros.
# build_docs: Build the Morpheus documentation
# git_clone: Clone the Morpheus repository to ensure we do not unintentionally
# copy local build artifacts
# ========================================================================= #

# Args used in FROM commands must come first
Expand All @@ -53,6 +60,11 @@ ARG MORPHEUS_ROOT_HOST=.
# Supply a channel alias to use for conda. This is needed if the conda channels go down
ARG CONDA_CHANNEL_ALIAS="https://conda.anaconda.org"

# Git arguments used for the release build
ARG GIT_URL=""
ARG GIT_BRANCH=""
ARG GIT_COMMIT=""

# ============ Stage: base ============
# Configure the base conda environment
FROM ${FROM_IMAGE}:${CUDA_MAJOR_VER}.${CUDA_MINOR_VER}.${CUDA_REV_VER}-base-${LINUX_DISTRO}${LINUX_VER} AS base
Expand Down Expand Up @@ -220,6 +232,35 @@ RUN --mount=type=cache,id=workspace_cache,target=/workspace/.cache,sharing=locke
cd ${MORPHEUS_ROOT_HOST} &&\
MORPHEUS_PYTHON_BUILD_STUBS=OFF CONDA_BLD_PATH=/opt/conda/conda-bld ./ci/conda/recipes/run_conda_build.sh morpheus

# ============ Stage: build_docs ============
# Now build the morpheus docs
FROM conda_env_dev as build_docs

ARG MORPHEUS_ROOT_HOST

# Copy the source
COPY . ./

RUN --mount=type=cache,id=workspace_cache,target=/workspace/.cache,sharing=locked \
--mount=type=bind,from=conda_bld_morpheus,source=/opt/conda/conda-bld,target=/opt/conda/conda-bld \
--mount=type=cache,id=conda_pkgs,target=/opt/conda/pkgs,sharing=locked \
source activate morpheus &&\
CONDA_ALWAYS_YES=true /opt/conda/bin/mamba install -n morpheus \
-c local \
-c conda-forge \
-c huggingface \
-c rapidsai \
-c rapidsai-nightly \
-c nvidia \
-c nvidia/label/dev \
-c pytorch \
-c defaults \
morpheus && \
# Change to the morpheus directory and build the docs
cd ${MORPHEUS_ROOT_HOST} &&\
CMAKE_CONFIGURE_EXTRA_ARGS="-DMORPHEUS_BUILD_DOCS=ON -DMORPHEUS_PYTHON_BUILD_STUBS=OFF -DMORPHEUS_CUDA_ARCHITECTURES=RAPIDS"\
./scripts/compile.sh --target morpheus_docs

# ============ Stage: runtime_conda_create ============
# Setup conda for the runtime environment
FROM base_extended as runtime_conda_create
Expand Down Expand Up @@ -251,21 +292,37 @@ RUN --mount=type=bind,from=conda_bld_morpheus,source=/opt/conda/conda-bld,target
/opt/conda/bin/conda env update --solver=libmamba -n morpheus --file \
conda/environments/runtime_cuda-${CUDA_MAJOR_VER}${CUDA_MINOR_VER}_arch-x86_64.yaml

# ============ Stage: git_clone ============
# Perform a clone of the git repository this ensures that when we copy files from the source repository, we aren't
# unintentionally including build artifacts or other files that shouldn't be in the final image
FROM conda_env_dev as git_clone

ARG GIT_URL
ARG GIT_BRANCH
ARG GIT_COMMIT

RUN source activate morpheus &&\
git clone --branch ${GIT_BRANCH} ${GIT_URL} /tmp/morpheus_repo &&\
cd /tmp/morpheus_repo &&\
git checkout ${GIT_COMMIT} &&\
git lfs install &&\
/tmp/morpheus_repo/scripts/fetch_data.py fetch examples models
dagardner-nv marked this conversation as resolved.
Show resolved Hide resolved
dagardner-nv marked this conversation as resolved.
Show resolved Hide resolved

# ============ Stage: runtime ============
# Setup container for runtime environment
FROM runtime_conda_create as runtime

ARG MORPHEUS_ROOT_HOST

# Only copy specific files/folders over that are necessary for runtime
COPY "${MORPHEUS_ROOT_HOST}/conda/environments/*.yaml" "./conda/environments/"
COPY "${MORPHEUS_ROOT_HOST}/docker" "./docker"
COPY "${MORPHEUS_ROOT_HOST}/docs" "./docs"
COPY "${MORPHEUS_ROOT_HOST}/examples" "./examples"
COPY "${MORPHEUS_ROOT_HOST}/models" "./models"
COPY "${MORPHEUS_ROOT_HOST}/scripts" "./scripts"
COPY "${MORPHEUS_ROOT_HOST}/*.md" "./"
COPY "${MORPHEUS_ROOT_HOST}/LICENSE" "./"
COPY --from=git_clone "/tmp/morpheus_repo/conda/environments/*.yaml" "./conda/environments/"
COPY --from=git_clone "/tmp/morpheus_repo/docker" "./docker"
COPY --from=build_docs "/workspace/build/docs/html" "./docs"
COPY --from=git_clone "/tmp/morpheus_repo/examples" "./examples"
COPY --from=git_clone "/tmp/morpheus_repo/models" "./models"
COPY --from=git_clone "/tmp/morpheus_repo/scripts" "./scripts"
COPY --from=git_clone "/tmp/morpheus_repo/*.md" "./"
COPY --from=git_clone "/tmp/morpheus_repo/LICENSE" "./"

RUN /opt/conda/bin/conda clean -afy && \
# Ensure the conda-bld directory is indexed even if empty
Expand Down
8 changes: 8 additions & 0 deletions docker/build_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ LINUX_VER=${LINUX_VER:-22.04}
MORPHEUS_SUPPORT_DOCA=${MORPHEUS_SUPPORT_DOCA:-"OFF"}
PYTHON_VER=${PYTHON_VER:-3.10}

# Build args needed for the release build
GIT_URL=${GIT_URL:-""}
GIT_BRANCH=${GIT_BRANCH:-""}
GIT_COMMIT=${GIT_COMMIT:-""}

# Determine the relative path from $PWD to $MORPHEUS_ROOT
MORPHEUS_ROOT_HOST=${MORPHEUS_ROOT_HOST:-"$(realpath --relative-to=${PWD} ${MORPHEUS_ROOT})"}

Expand All @@ -52,6 +57,9 @@ DOCKER_ARGS="${DOCKER_ARGS} --build-arg LINUX_VER=${LINUX_VER}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg MORPHEUS_ROOT_HOST=${MORPHEUS_ROOT_HOST}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg MORPHEUS_SUPPORT_DOCA=${MORPHEUS_SUPPORT_DOCA}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg PYTHON_VER=${PYTHON_VER}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg GIT_URL=${GIT_URL}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg GIT_BRANCH=${GIT_BRANCH}"
DOCKER_ARGS="${DOCKER_ARGS} --build-arg GIT_COMMIT=${GIT_COMMIT}"
DOCKER_ARGS="${DOCKER_ARGS} --network=host"

# Last add any extra args (duplicates override earlier ones)
Expand Down
10 changes: 7 additions & 3 deletions docker/build_container_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ export DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-"nvcr.io/nvidia/morpheus/morpheus"
export DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG:-"$(git describe --tags --abbrev=0)-runtime"}
export DOCKER_TARGET=${DOCKER_TARGET:-"runtime"}

popd &> /dev/null
export GIT_URL=${GIT_URL:-$(git remote get-url origin)}
dagardner-nv marked this conversation as resolved.
Show resolved Hide resolved

# Ensure we have an https url
GIT_URL=$(echo $url | sed -e 's|^git@github\.com:|https://github.com/|')
export GIT_BRANCH=$(git branch --show-current)
export GIT_COMMIT=$(git log -n 1 --pretty=format:%H)

# Fetch data
"${SCRIPT_DIR}/../scripts/fetch_data.py" fetch docs examples models
popd &> /dev/null

# Call the general build script
${SCRIPT_DIR}/build_container.sh
Loading