Skip to content

Commit

Permalink
Add Morpheus devcontainer (#535)
Browse files Browse the repository at this point in the history
Adds a devcontainer capable of building Morpheus without invalidating the conda env on change.

Authors:
  - Christopher Harris (https://github.com/cwharris)

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

URL: #535
  • Loading branch information
cwharris authored Jan 4, 2023
1 parent 882e2a9 commit 0003f99
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.

FROM nvidia/cuda:11.5.1-devel-ubuntu20.04 AS base

RUN apt-get update && \
apt-get install --no-install-recommends --yes \
wget git-lfs gdb iputils-ping

ENV CONDA_DIR=/opt/conda

RUN wget "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh" && \
bash Mambaforge-$(uname)-$(uname -m).sh -b -p ${CONDA_DIR} && \
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh && conda activate base" >> /etc/skel/.bashrc && \
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh && conda activate base" >> ~/.bashrc

ENV PATH="${CONDA_DIR}/bin:${PATH}"

ENV MAMBA_NO_BANNER=1
ENV PATH="${PATH}:/workspaces/morpheus/.devcontainer/bin"
77 changes: 77 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!--
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.
-->

# Morpheus Devcontainer

The Morpheus devcontainer is provided as a quick-to-set-up development and exploration environment for use with [Visual Studio Code](https://code.visualstudio.com) (Code). The devcontainer is a lightweight container which mounts-in a conda environment with cached packages, alleviating long conda download times on subsequent launches. It provides a simple framework for adding developer-centric [scripts](#scripts), and incorperates some helpful Code plugins, such as clangd and cmake support.

More information about devcontainers can be found at [containers.dev](https://containers.dev/).

## Getting Started

To get started, simply open the morpheus repository root folder within Code. A window should appear at the bottom-right corner of the editor asking if you would like to reopen the workspace inside of the dev container. After clicking the confirmation dialog, the container will first build, then launch, then remote-attach.

If the window does not appear, or you would like to rebuild the container, click ctrl-shift-p and search for `Dev Containers: Rebuild and Reopen in Container`. Hit enter, and the container will first build, then launch, then remote-attach.

Once remoted in to the devcontainer within code, the `setup-morpheus-env` script will begin to run and solve a morpheus conda environment (this conda environment is local to the morpheus repository and dev container and will not override any host environments). You should see the script executing in one of Code's integrated terminal. Once the script has completed, we're ready to start development or exploration of Morpheus. By default, each _new_ integrated terminal will automatically conda activate the morpheus environment.

## Development Scripts
Several convienient scripts are available in the devcontainer's `PATH` (`.devcontainer/bin`) for starting, stopping, and interacting with Triton and Kafka. More scripts can be added as needed.

### Interacting with Triton
To start Triton and connect it to the devcontainer network, the `dev-triton-start` script can be used. The following example starts _or restarts_ Triton with the `abp-pcap-xgb` model loaded.
```
dev-triton-start abp-pcap-xgb
```
Triton should now be started and DNS resolvable as `triton`.
```
ping triton
```
To load a different model, simply call `dev-triton-start` with a different model name. Multiple models can be loaded simultaneously by adding more model names to the command.
```
dev-triton-start model-1 model-2 ... model-n
```
To stop Triton, call `dev-triton-stop`. This may take several seconds as the Triton server shuts down gracefully.
```
dev-triton-stop
```
### Interacting with Kafka
To start Kafka and connect it to the devcontainer network, the `dev-kafka-start` script can be used. The following example starts _or restarts_ Kafka and Zookeeper.
```
dev-kafka-start
```
Kafka should now be started and DNS resolveable as `kafka`.
```
ping kafka
```
It can be extremely useful to interact directly with Kafka to produce test data to a specific topic. To do this, the `dev-kafka-produce` script can be used. This script opens a connect to the Kafka server and starts `kafka-console-producer.sh`. In this case with a specific topic. Once started, a prompt will appear in which new-line delimited messages can be entered in to the console.
```
dev-kafka-produce test-topic
>
```
It can also be useful to produce messages from a file. For this, the `dev-kafka-produce` script can be used with two arguments. The first argument is the topic name, and the second argument is the file to be forwarded to the console producer.
```
dev-kafka-produce test-topic $MORPHEUS_ROOT/examples/data/pcap_dump.jsonlines
```
To retrieve the logs from Kafka and Zookeeper, use the `dev-kafka-logs` script.
```
dev-kafka-logs
```
To stop Kafka and Zookeeper, use the `dev-kafka-stop` script.
```
dev-kafka-stop
```
19 changes: 19 additions & 0 deletions .devcontainer/bin/dev-kafka-logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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.

COMPOSE_FILE="${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml"

docker compose -f $COMPOSE_FILE logs zookeeper kafka
24 changes: 24 additions & 0 deletions .devcontainer/bin/dev-kafka-produce
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/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.

COMPOSE_FILE="${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml"

if [[ $# -eq 2 ]]; then
docker compose -f $COMPOSE_FILE cp $2 kafka:/tmp/kafka-topic-input
docker compose -f $COMPOSE_FILE exec kafka bash -c "cat /tmp/kafka-topic-input | kafka-console-producer.sh --bootstrap-server kafka:9092 --topic $1"
else
docker compose -f $COMPOSE_FILE exec -it kafka kafka-console-producer.sh --bootstrap-server kafka:9092 --topic $1
fi
21 changes: 21 additions & 0 deletions .devcontainer/bin/dev-kafka-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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.

COMPOSE_FILE="${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml"

docker compose -f $COMPOSE_FILE up -d zookeeper kafka
export ZOOKEEPER_HOST=$(docker compose -f $COMPOSE_FILE exec zookeper hostname -i)
export KAFKA_HOST=$(docker compose -f $COMPOSE_FILE exec kafka hostname -i)
17 changes: 17 additions & 0 deletions .devcontainer/bin/dev-kafka-stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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.

docker compose -f ${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml stop kafka zookeeper
34 changes: 34 additions & 0 deletions .devcontainer/bin/dev-triton-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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.

args=""

if [ $# -gt 0 ] ; then
args="$args --model-control-mode=explicit"
fi

for model in $@ ; do
args="$args --load-model=$model"
done

export TRITON_MODEL_ARGS="$args"

COMPOSE_FILE="${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml"

docker compose -f $COMPOSE_FILE up -d triton
export TRITON_HOST=$(docker compose -f $COMPOSE_FILE exec triton hostname -i)
sleep 1 # wait for triton to load models
docker compose -f $COMPOSE_FILE logs triton
17 changes: 17 additions & 0 deletions .devcontainer/bin/dev-triton-stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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.

docker compose -f ${MORPHEUS_ROOT}/.devcontainer/docker-compose.yml stop triton
28 changes: 28 additions & 0 deletions .devcontainer/bin/setup-morpheus-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/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.

conda_env_find(){
conda env list | grep "${@}" >/dev/null 2>/dev/null
}

ENV_NAME=${ENV_NAME:-morpheus}

sed -ri "s/conda activate base/conda activate $ENV_NAME/g" ~/.bashrc;

if conda_env_find "${ENV_NAME}" ; \
then mamba env update --name ${ENV_NAME} -f ${MORPHEUS_ROOT}/docker/conda/environments/cuda11.5_dev.yml; \
else mamba env create --name ${ENV_NAME} -f ${MORPHEUS_ROOT}/docker/conda/environments/cuda11.5_dev.yml; \
fi
82 changes: 82 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// !/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.
{
"name": "Morpheus",
"build": {
"dockerfile": "Dockerfile"
},

"hostRequirements": {
"gpu": true
},

"capAdd":[
"SYS_NICE",
"SYS_PTRACE"
],

"securityOpt": [
"seccomp=unconfined"
],

"runArgs": [
"--network=morpheus"
],

"containerEnv": {
"HOST_MORPHEUS_ROOT": "${localWorkspaceFolder}",
"MORPHEUS_ROOT": "/workspaces/morpheus"
},

"postStartCommand": "${MORPHEUS_ROOT}/.devcontainer/bin/setup-morpheus-env",

"initializeCommand": [ "./.devcontainer/init.sh" ],

"remoteUser": "coder",

"mounts": [
{"type":"bind", "source": "/var/run/docker.sock", "target": "/var/run/docker.sock"},
{"type":"bind", "source": "${localWorkspaceFolder}/.cache/conda", "target": "/home/coder/.conda"}
],

"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"uid": "1000",
"gid": "1000",
"username": "coder"
},
"ghcr.io/devcontainers/features/docker-from-docker": {}
},

"customizations": {
"vscode": {
"extensions": [
"eamodio.gitlens",
"llvm-vs-code-extensions.vscode-clangd",
"ms-python.python",
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"nvidia.nsight-vscode-edition",
"twxs.cmake",
"xaver.clang-format"
]
}
},
"settings": {
"C_Cpp.intelliSenseEngine": "disabled",
"python.terminal.activateEnvironment": false
}
}
Loading

0 comments on commit 0003f99

Please sign in to comment.