Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
liqul committed Feb 23, 2024
1 parent aeeef01 commit 40c8bef
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 71 deletions.
22 changes: 22 additions & 0 deletions ces_container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use the official Python 3.10 image as the base image
FROM python:3.10

# Set the working directory to /app
WORKDIR /app

# Copy the requrements file
COPY requirements.txt /app/requirements.txt

# Install any necessary dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the project code
COPY taskweaver/ces /app/taskweaver/ces
COPY taskweaver/plugin /app/taskweaver/plugin
COPY taskweaver/__init__.py /app/taskweaver/__init__.py
# Add the taskweaver directories to the PYTHONPATH
ENV PYTHONPATH="${PYTHONPATH}:/app/taskweaver"

CMD ["python", "/app/taskweaver/ces/docker_entry.py"]


30 changes: 30 additions & 0 deletions ces_container/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
param (
[string]$imageName
)

if (-not $imageName) {
Write-Host "Please provide an image name as an argument."
exit 1
}

$taskweaverPath = "..\taskweaver"
$requirementsPath = "..\requirements.txt"

if (Test-Path $taskweaverPath) {
Write-Host "Using local files from $taskweaverPath"
Copy-Item -Path $taskweaverPath -Destination ".\taskweaver" -Recurse
Copy-Item -Path $requirementsPath -Destination ".\requirements.txt"
} else {
Write-Host "Cloning repository and using repository files"
git clone https://github.com/microsoft/TaskWeaver.git
Move-Item -Path ".\TaskWeaver\taskweaver" -Destination ".\taskweaver"
Move-Item -Path ".\TaskWeaver\requirements.txt" -Destination ".\requirements.txt"
Remove-Item -Path ".\TaskWeaver" -Recurse -Force
}

# Build the Docker image
docker build -t $imageName .

# Remove temporary files
Remove-Item -Path ".\taskweaver" -Recurse -Force
Remove-Item -Path ".\requirements.txt" -Force
28 changes: 28 additions & 0 deletions ces_container/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Please provide an image name as an argument."
exit 1
fi

imageName="$1"
taskweaverPath="../taskweaver"
requirementsPath="../requirements.txt"

if [ -d "$taskweaverPath" ]; then
echo "Using local files from $folderPath"
cp -r "$taskweaverPath" .
cp "$requirementsPath" .
else
echo "Cloning repository and using repository files"
git clone https://github.com/microsoft/TaskWeaver.git
mv ".TaskWeaver/taskweaver" .
mv ".TaskWeaver/requirements.txt" .
rm -rf ".TaskWeaver"
fi

# Build the Docker image
docker build -t "$imageName" .

rm -rf taskweaver
rm requirements.txt
1 change: 1 addition & 0 deletions taskweaver/ces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from taskweaver.ces.common import Manager
from taskweaver.ces.environment import Environment, EnvMode
from taskweaver.ces.manager.sub_proc import SubProcessManager


Expand Down
49 changes: 49 additions & 0 deletions taskweaver/ces/docker_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import time

from taskweaver.ces import Environment, EnvMode

# Flag to control the main loop
keep_running = True

env_id = os.getenv(
"TASKWEAVER_ENV_ID",
"local",
)
env_dir = os.getenv(
"TASKWEAVER_ENV_DIR",
os.path.realpath(os.getcwd()),
)
session_id = os.getenv(
"TASKWEAVER_SESSION_ID",
"session_id",
)
port_start = int(
os.getenv(
"TASKWEAVER_PORT_START",
"12300",
),
)
kernel_id = os.getenv(
"TASKWEAVER_KERNEL_ID",
"kernel_id",
)


if __name__ == "__main__":
env = Environment(env_id, env_dir, env_mode=EnvMode.InsideContainer)
env.start_session(session_id, port_start=port_start, kernel_id=kernel_id)

print(f"Session {session_id} is running at {env_dir} inside a container.")

# Keep the script running until it receives a termination signal
try:
# Keep the script running indefinitely
while True:
time.sleep(10) # Sleep for 10 seconds
except KeyboardInterrupt:
# Handle Ctrl-C or other interruption signals
pass
finally:
# Clean up and shut down the kernel
env.stop_session(session_id)
Loading

0 comments on commit 40c8bef

Please sign in to comment.