Skip to content

Commit

Permalink
docker backend fixes for local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pop John committed Aug 2, 2024
1 parent 43c0314 commit d80628c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
15 changes: 2 additions & 13 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ FROM node:20.15.1

WORKDIR /app/backend

RUN apt-get update && apt-get install -y sshpass rsync && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y sshpass rsync bash wget && rm -rf /var/lib/apt/lists/*

COPY backend /app/backend
COPY machine_learning_core /app/machine_learning_core

RUN npm install

RUN echo "PORT=3000" > .env && \
echo "MACHINE_LEARNING_CORE_PATH=${MACHINE_LEARNING_CORE_PATH}" >> .env && \
echo "CONDA_SH_PATH=${CONDA_SH_PATH}" >> .env && \
echo "HUGGING_FACE_ACCESS_TOKEN=${HUGGING_FACE_ACCESS_TOKEN}" >> .env && \
echo "CONNECTION_TYPE=${CONNECTION_TYPE}" >> .env && \
echo "PRIMARY_SSH_HOST=${PRIMARY_SSH_HOST}" >> .env && \
echo "PRIMARY_SSH_PORT=${PRIMARY_SSH_PORT}" >> .env && \
echo "PRIMARY_SSH_USERNAME=${PRIMARY_SSH_USERNAME}" >> .env && \
echo "PRIMARY_SSH_PASSWORD=${PRIMARY_SSH_PASSWORD}" >> .env && \
echo "PRIMARY_SSH_PRIVATE_KEY_PATH=${PRIMARY_SSH_PRIVATE_KEY_PATH}" >> .env

RUN chmod +x setup_python_environment.sh

EXPOSE 3000

CMD ["/bin/bash", "-c", "./setup_python_environment.sh \"$CONNECTION_TYPE\" \"$PRIMARY_SSH_HOST\" \"$PRIMARY_SSH_PORT\" \"$PRIMARY_SSH_USERNAME\" \"$PRIMARY_SSH_PASSWORD\" && node src/index.js"]
CMD ["/bin/bash", "-c", "./setup_python_environment.sh \"$CONNECTION_TYPE\" \"$PRIMARY_SSH_HOST\" \"$PRIMARY_SSH_PORT\" \"$PRIMARY_SSH_USERNAME\" \"$PRIMARY_SSH_PASSWORD\" \"$MACHINE_LEARNING_CORE_PATH\" \"$CONDA_SH_PATH\" \"$HUGGING_FACE_ACCESS_TOKEN\" \"$PRIMARY_SSH_PRIVATE_KEY_PATH\" && node src/index.js"]
19 changes: 18 additions & 1 deletion backend/setup_python_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ PRIMARY_SSH_HOST=$2
PRIMARY_SSH_PORT=$3
PRIMARY_SSH_USERNAME=$4
PRIMARY_SSH_PASSWORD=$5
MACHINE_LEARNING_CORE_PATH=$6
CONDA_SH_PATH=$7
HUGGING_FACE_ACCESS_TOKEN=$8
PRIMARY_SSH_PRIVATE_KEY_PATH=$9

echo "CONNECTION_TYPE is set to: $CONNECTION_TYPE"
echo "PORT=3000" > /app/backend/.env
echo "MACHINE_LEARNING_CORE_PATH=${MACHINE_LEARNING_CORE_PATH}" >> /app/backend/.env
echo "CONDA_SH_PATH=${CONDA_SH_PATH}" >> /app/backend/.env
echo "HUGGING_FACE_ACCESS_TOKEN=${HUGGING_FACE_ACCESS_TOKEN}" >> /app/backend/.env
echo "CONNECTION_TYPE=${CONNECTION_TYPE}" >> /app/backend/.env
echo "PRIMARY_SSH_HOST=${PRIMARY_SSH_HOST}" >> /app/backend/.env
echo "PRIMARY_SSH_PORT=${PRIMARY_SSH_PORT}" >> /app/backend/.env
echo "PRIMARY_SSH_USERNAME=${PRIMARY_SSH_USERNAME}" >> /app/backend/.env
echo "PRIMARY_SSH_PASSWORD=${PRIMARY_SSH_PASSWORD}" >> /app/backend/.env
echo "PRIMARY_SSH_PRIVATE_KEY_PATH=${PRIMARY_SSH_PRIVATE_KEY_PATH}" >> /app/backend/.env

install_miniconda3() {
echo "Installing Miniconda..."
Expand All @@ -21,6 +34,10 @@ install_miniconda3() {
}

setup_local_environment() {
if [ -f /root/miniconda3/etc/profile.d/conda.sh ]; then
source /root/miniconda3/etc/profile.d/conda.sh
fi

if ! command -v conda &> /dev/null; then
echo "Conda command not found. Installing Miniconda3..."
install_miniconda3
Expand Down
4 changes: 2 additions & 2 deletions backend/src/facades/algorithmExecutionFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ScriptExecutor {

buildCommand(scriptPath, algorithm, args) {
if (this.type === ALGORITHM_TYPES.MULTIFLOW) {
return `source "${process.env.CONDA_SH_PATH}" && cd "${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow" && conda activate modelsmith && python3 ${algorithm} ${args}`;
return `bash -c "source ${process.env.CONDA_SH_PATH} && cd ${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow && conda activate modelsmith && python3 ${algorithm} ${args}"`;
}
return `source "${process.env.CONDA_SH_PATH}" && conda activate modelsmith && python3 "${scriptPath}${algorithm}" ${args}`;
return `bash -c "source ${process.env.CONDA_SH_PATH} && conda activate modelsmith && python3 ${scriptPath}${algorithm} ${args}"`;
}

buildPythonCommand(scriptPath, algorithm, args) {
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ services:
- PRIMARY_SSH_PRIVATE_KEY_PATH
ports:
- "3000:3000"
deploy:
resources:
reservations:
devices:
- count: all
capabilities: [gpu]
frontend:
build:
context: ./frontend
Expand Down
16 changes: 9 additions & 7 deletions docs/configure-modelsmith-on-local-machine-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ This command runs the frontend container in detached mode (\`-d\`), names it \`m

Before running the backend container, you need to set up the environment variables. These variables configure various aspects of the backend, including paths, access tokens, and connection details. Here's an explanation of each variable:

- `MACHINE_LEARNING_CORE_PATH`: Path to the machine learning core within the container.
- `CONDA_SH_PATH`: Path to the Conda shell script for environment activation.
- `MACHINE_LEARNING_CORE_PATH`: Path to the machine learning core within the container. The default value is "../machine_learning_core".
- `CONDA_SH_PATH`: Path to the Conda shell script for environment activation within the container. The default value is "../../root/miniconda3/etc/profile.d/conda.sh".
- `HUGGING_FACE_ACCESS_TOKEN`: Your Hugging Face access token for model downloads. Please refer to the [AutoAWQ Configuration Guide](configure-autoawq.md)
- `CONNECTION_TYPE`: Type of connection (e.g., "LOCAL" for virtual machine).
- `CONNECTION_TYPE`: Type of connection ("LOCAL" for docker container machine with host GPU).

Note: The initial backend configuration will take up to 5-10 minutes.

Now, run the backend container with the following command, replacing the placeholder values with your actual configuration:

```shell
docker run -d --name ms-backend-container \
-e MACHINE_LEARNING_CORE_PATH=machine_learning_core \
-e CONDA_SH_PATH=miniconda3/etc/profile.d/conda.sh \
-e HUGGING_FACE_ACCESS_TOKEN=your_hugging_face_token_here \
-e CONNECTION_TYPE=LOCAL \
-e "MACHINE_LEARNING_CORE_PATH=/app/machine_learning_core" \
-e "CONDA_SH_PATH=/root/miniconda3/etc/profile.d/conda.sh" \
-e "HUGGING_FACE_ACCESS_TOKEN=your_hugging_face_token_here" \
-e "CONNECTION_TYPE=LOCAL" \
-p 3000:3000 \
ms-backend
```
Expand Down
24 changes: 12 additions & 12 deletions docs/configure-modelsmith-on-vm-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ This command runs the frontend container in detached mode (`-d`), names it `ms-f

Before running the backend container, you need to set up the environment variables. These variables configure various aspects of the backend, including paths, access tokens, and connection details. Here's an explanation of each variable:

- `MACHINE_LEARNING_CORE_PATH`: Path to the machine learning core within the container.
- `CONDA_SH_PATH`: Path to the Conda shell script for environment activation.
- `MACHINE_LEARNING_CORE_PATH`: Path to the machine learning core within the container. The default value is "machine_learning_core".
- `CONDA_SH_PATH`: Path to the Conda shell script for environment activation. The default value is "miniconda3/etc/profile.d/conda.sh".
- `HUGGING_FACE_ACCESS_TOKEN`: Your Hugging Face access token for model downloads. Please refer to the [AutoAWQ Configuration Guide](configure-autoawq.md)
- `CONNECTION_TYPE`: Type of connection (e.g., "VM" for virtual machine).
- `CONNECTION_TYPE`: Type of connection "VM" for virtual machine.
- `PRIMARY_SSH_HOST`: Hostname or IP address of the primary SSH server.
- `PRIMARY_SSH_PORT`: Port number for SSH connection.
- `PRIMARY_SSH_USERNAME`: Username for SSH authentication.
Expand All @@ -58,15 +58,15 @@ Now, run the backend container with the following command, replacing the placeho

```shell
docker run -d --name ms-backend-container \
-e MACHINE_LEARNING_CORE_PATH=machine_learning_core \
-e CONDA_SH_PATH=miniconda3/etc/profile.d/conda.sh \
-e HUGGING_FACE_ACCESS_TOKEN=your_hugging_face_token_here \
-e CONNECTION_TYPE=VM \
-e PRIMARY_SSH_HOST=your_ssh_host_here \
-e PRIMARY_SSH_PORT=22 \
-e PRIMARY_SSH_USERNAME=your_ssh_username \
-e PRIMARY_SSH_PASSWORD=your_ssh_password \
-e PRIMARY_SSH_PRIVATE_KEY_PATH=/path/to/your/private/key/or_empty \
-e "MACHINE_LEARNING_CORE_PATH=machine_learning_core" \
-e "CONDA_SH_PATH=miniconda3/etc/profile.d/conda.sh" \
-e "HUGGING_FACE_ACCESS_TOKEN=your_hugging_face_token_here" \
-e "CONNECTION_TYPE=VM" \
-e "PRIMARY_SSH_HOST=your_ssh_host_here" \
-e "PRIMARY_SSH_PORT=22" \
-e "PRIMARY_SSH_USERNAME=your_ssh_username" \
-e "PRIMARY_SSH_PASSWORD=your_ssh_password" \
-e "PRIMARY_SSH_PRIVATE_KEY_PATH=/path/to/your/private/key/or_empty" \
-p 3000:3000 \
ms-backend
```
Expand Down

0 comments on commit d80628c

Please sign in to comment.