Skip to content

Commit

Permalink
Development container image (#236)
Browse files Browse the repository at this point in the history
Resolves #203

Authors:
  - Ryan Olson (https://github.com/ryanolson)

Approvers:
  - Michael Demoret (https://github.com/mdemoret-nv)

URL: #236
  • Loading branch information
ryanolson authored Dec 8, 2022
1 parent c40154c commit c4f1c0d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 59 deletions.
59 changes: 59 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "mrc-dev",
"build": {
"context": "..",
"dockerfile": "${localWorkspaceFolder}/Dockerfile",
"target": "development",
"args": {
"USERNAME": "${localEnv:USER}",
"USER_ID": "${localEnv:UID}"
}
},
// todo(252)
// new capability with vs code 1.74 (November 2022 Release)
// https://github.com/microsoft/vscode-docs/blob/main/remote-release-notes/v1_74.md#gpu-host-requirement
// enable this after more testing is conducted
// "hostRequirements": {
// "gpu": true
// },
"runArgs": [
"--gpus=all",
"--runtime=nvidia",
"--network=host",
"--cap-add=SYS_PTRACE",
"--cap-add=SYS_NICE",
"--security-opt",
"seccomp=unconfined"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/work,type=bind,consistency=cached",
"workspaceFolder": "/work",
"containerEnv": {
// the post_start script will look for these envs, if they are set, git will be configured
"GIT_AUTHOR_NAME": "${localEnv:GIT_AUTHOR_NAME}",
"GIT_AUTHOR_EMAIL": "${localEnv:GIT_AUTHOR_EMAIL}"
},
"remoteUser": "${localEnv:USER}",
"updateRemoteUserUID": true,
"postStartCommand": ".devcontainer/scripts/post_start.sh",
"overrideCommand": true, // infinite loop of sleeps,
"customizations": {
"vscode": {
"extensions": [
"eamodio.gitlens",
"formulahendry.terminal",
"hbenl.vscode-test-explorer",
"josetr.cmake-language-support-vscode",
"llvm-vs-code-extensions.vscode-clangd",
"matepek.vscode-catch2-test-adapter",
"ms-dotnettools.vscode-dotnet-runtime",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"ms-vscode.test-adapter-converter",
"twxs.cmake",
"xaver.clang-format"
]
}
}
}
26 changes: 26 additions & 0 deletions .devcontainer/scripts/post_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

if [[ -n "${GIT_AUTHOR_NAME}" ]] && [[ -n "${GIT_AUTHOR_EMAIL}" ]]
then
echo "setting git config --global user.name ${GIT_AUTHOR_NAME}"
echo "setting git config --global user.email ${GIT_AUTHOR_EMAIL}"
git config --global user.name ${GIT_AUTHOR_NAME}
git config --global user.email ${GIT_AUTHOR_EMAIL}
else
echo "skipping git config setup"
echo "set the following envs to configure git on startup: GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL"
fi
103 changes: 103 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# syntax=docker/dockerfile:1.3

# SPDX-FileCopyrightText: Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.


ARG FROM_IMAGE="rapidsai/ci"
ARG CUDA_VER=11.4.1
ARG LINUX_DISTRO=ubuntu
ARG LINUX_VER=20.04
ARG PYTHON_VER=3.8

# ============= base ===================
FROM ${FROM_IMAGE}:cuda${CUDA_VER}-${LINUX_DISTRO}${LINUX_VER}-py${PYTHON_VER} AS base

ARG PROJ_NAME=mrc

SHELL ["/bin/bash", "-c"]

RUN --mount=type=cache,target=/var/cache/apt \
apt update &&\
apt install --no-install-recommends -y \
libnuma1 && \
rm -rf /var/lib/apt/lists/*

COPY ./ci/conda/environments/* /opt/mrc/conda/environments/

RUN --mount=type=cache,target=/opt/conda/pkgs,sharing=locked \
echo "create env: ${PROJ_NAME}" && \
CONDA_ALWAYS_YES=true \
/opt/conda/bin/mamba env create -q -n ${PROJ_NAME} --file /opt/mrc/conda/environments/dev_env.yml && \
/opt/conda/bin/mamba env update -q -n ${PROJ_NAME} --file /opt/mrc/conda/environments/clang_env.yml && \
/opt/conda/bin/mamba env update -q -n ${PROJ_NAME} --file /opt/mrc/conda/environments/ci_env.yml && \
sed -i "s/conda activate base/conda activate ${PROJ_NAME}/g" ~/.bashrc && \
chmod -R a+rwX /opt/conda && \
rm -rf /tmp/conda

# disable sscache wrappers around compilers
ENV CMAKE_CUDA_COMPILER_LAUNCHER=
ENV CMAKE_CXX_COMPILER_LAUNCHER=
ENV CMAKE_C_COMPILER_LAUNCHER=

# ============ driver ==================
FROM base as driver

RUN --mount=type=cache,target=/var/cache/apt \
apt update && \
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC \
apt install --no-install-recommends -y \
libnvidia-compute-495 \
&& \
rm -rf /var/lib/apt/lists/*

# ========= development ================
FROM base as development

RUN --mount=type=cache,target=/var/cache/apt \
apt-get update &&\
apt-get install --no-install-recommends -y \
gdb \
htop \
less \
openssh-client \
psmisc \
sudo \
vim-tiny \
&& \
rm -rf /var/lib/apt/lists/*

# create a user inside the container
ARG USERNAME=morpheus
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
usermod --shell /bin/bash $USERNAME && \
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
chmod 0440 /etc/sudoers.d/$USERNAME && \
cp /root/.bashrc /home/$USERNAME/.bashrc

USER $USERNAME

# default working directory
WORKDIR /work

# Setup git to allow other users to access /work. Requires git 2.35.3 or
# greater. See https://marc.info/?l=git&m=164989570902912&w=2. Only enable for
# development
RUN git config --global --add safe.directory "*" && \
git config --global core.editor "vim"
2 changes: 1 addition & 1 deletion ci/conda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To build the Conda packages, it's recommended to run the provided scripts from a

```bash
cd ${MRC_HOME}
docker buildx build --target development -t mrc-conda-build .
docker buildx build --target developement -t mrc-conda-build .
```

This will create the image `mrc-conda-build` that can be used to build MRC conda packages. When running this container, is recommended to set the environment variable `CONDA_PKGS_DIRS` to a path mounted on the host to speed up the build process. Without this variable set, the packages needed during the build will need to be re-downloaded each time the container is run.
Expand Down
57 changes: 0 additions & 57 deletions ci/runner/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion ci/runner/build_and_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if [[ "${SKIP_BUILD}" == "" ]]; then
for build_target in ${DOCKER_TARGET[@]}; do
FULL_NAME=$(get_image_full_name)
echo "Building target \"${build_target}\" as ${FULL_NAME}";
docker build --network=host ${DOCKER_EXTRA_ARGS} --target ${build_target} -t ${FULL_NAME} -f ci/runner/Dockerfile .
docker buildx build --network=host ${DOCKER_EXTRA_ARGS} --target ${build_target} -t ${FULL_NAME} -f ./Dockerfile .
done
fi

Expand Down

0 comments on commit c4f1c0d

Please sign in to comment.