Skip to content

Commit

Permalink
Renamed worker to runner everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwik-g committed Jan 8, 2025
1 parent ddcb988 commit f92fea2
Show file tree
Hide file tree
Showing 38 changed files with 72 additions and 585 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- 'unstract/**'
- 'platform-service/**'
- 'x2text-service/**'
- 'worker/**'
- 'runner/**'
- 'docker/dockerfiles/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
Expand All @@ -27,7 +27,7 @@ on:
- 'unstract/**'
- 'platform-service/**'
- 'x2text-service/**'
- 'worker/**'
- 'runner/**'
- 'docker/dockerfiles/**'

jobs:
Expand All @@ -52,7 +52,7 @@ jobs:
cp ../backend/sample.env ../backend/.env
cp ../platform-service/sample.env ../platform-service/.env
cp ../prompt-service/sample.env ../prompt-service/.env
cp ../worker/sample.env ../worker/.env
cp ../runner/sample.env ../runner/.env
cp ../x2text-service/sample.env ../x2text-service/.env
cp sample.essentials.env essentials.env
cp sample.env .env
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ jobs:
- name: Render the report to the PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: worker-test-report
header: runner-test-report
recreate: true
path: worker-report.md
path: runner-report.md

- name: Output reports to the job summary when tests fail
shell: bash
run: |
if [ -f "worker-report.md" ]; then
echo "<details><summary>Worker Test Report</summary>" >> $GITHUB_STEP_SUMMARY
if [ -f "runner-report.md" ]; then
echo "<details><summary>Runner Test Report</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat "worker-report.md" >> $GITHUB_STEP_SUMMARY
cat "runner-report.md" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
fi
2 changes: 1 addition & 1 deletion .github/workflows/production-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
service_name: [backend, frontend, platform-service, prompt-service, worker, x2text-service]
service_name: [backend, frontend, platform-service, prompt-service, runner, x2text-service]

steps:
- name: Checkout code for release
Expand Down
2 changes: 1 addition & 1 deletion backend/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ API_STORAGE_DIR = "/data/api"
PLATFORM_SERVICE_HOST=http://unstract-platform-service
PLATFORM_SERVICE_PORT=3001

# Tool Runner (Worker Service)
# Tool Runner
UNSTRACT_RUNNER_HOST=http://unstract-runner
UNSTRACT_RUNNER_PORT=5002

Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ services:
build:
dockerfile: docker/dockerfiles/backend.Dockerfile
context: ..
worker:
image: unstract/worker:${VERSION}
runner:
image: unstract/runner:${VERSION}
build:
dockerfile: docker/dockerfiles/worker.Dockerfile
dockerfile: docker/dockerfiles/runner.Dockerfile
context: ..
platform-service:
image: unstract/platform-service:${VERSION}
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ services:
- traefik.enable=false

runner:
image: unstract/worker:${VERSION}
image: unstract/runner:${VERSION}
container_name: unstract-runner
restart: unless-stopped
ports:
- 5002:5002
env_file:
- ../worker/.env
- ../runner/.env
volumes:
- ./workflow_data:/data
# Docker socket bind mount to spawn tool containers
Expand Down
2 changes: 1 addition & 1 deletion docker/dockerfiles/backend.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ platform-service
prompt-service
tools
!unstract
worker
runner
x2text-service
2 changes: 1 addition & 1 deletion docker/dockerfiles/frontend.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ platform-service
prompt-service
tools
unstract
worker
runner
x2text-service
2 changes: 1 addition & 1 deletion docker/dockerfiles/platform.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ frontend
prompt-service
tools
!unstract
worker
runner
x2text-service
2 changes: 1 addition & 1 deletion docker/dockerfiles/prompt.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ tools
unstract
!unstract/core
!unstract/flags
worker
runner
x2text-service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /unstract

ENV BUILD_CONTEXT_PATH worker
ENV BUILD_CONTEXT_PATH runner
ENV BUILD_PACKAGES_PATH unstract
ENV PDM_VERSION 2.16.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ tools
unstract
!unstract/core
!unstract/flags
!worker
!runner
x2text-service
2 changes: 1 addition & 1 deletion docker/dockerfiles/x2text.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ platform-service
prompt-service
tools
unstract
worker
runner
!x2text-service
2 changes: 1 addition & 1 deletion docker/scripts/pdm-lock-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Helps generate pdm's lockfiles by running the command `pdm lock -G :all -v` on a
- project root
- `backend`
- `prompt-service`
- `worker`
- `runner`
- `unstract/core`
- `unstract/flags`
- `platform-service`
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/pdm-lock-gen/pdm-lock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ directories=(
"."
"backend"
"prompt-service"
"worker"
"runner"
"unstract/filesystem"
"unstract/core"
"unstract/flags"
Expand Down
12 changes: 6 additions & 6 deletions worker/.gitignore → runner/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

src/unstract/worker/clients/
!src/unstract/worker/clients/__init__.py
!src/unstract/worker/clients/interface.py
!src/unstract/worker/clients/helper.py
!src/unstract/worker/clients/docker.py
!src/unstract/worker/clients/test_docker.py
src/unstract/runner/clients/
!src/unstract/runner/clients/__init__.py
!src/unstract/runner/clients/interface.py
!src/unstract/runner/clients/helper.py
!src/unstract/runner/clients/docker.py
!src/unstract/runner/clients/test_docker.py
12 changes: 6 additions & 6 deletions worker/README.md → runner/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Unstract Worker
# Unstract Runner

This module contains the logic for how Tools are executed in DND mode.

## Docker build and publish

Build docker image
```
docker build -t unstract/worker:1.1.1 .
docker build -t unstract/runner:1.1.1 .
```

Then publish it into Docker hub

```
docker push unstract/worker:1.1.1
docker push unstract/runner:1.1.1
```

## Run docker compose

To expose the Unstract worker service.
To expose the Unstract runner service.

```
docker compose -f docker-compose.yaml up
```

## Using with Docker Desktop

The worker makes use of the python docker client's [from_env()](https://docker-py.readthedocs.io/en/stable/client.html#docker.client.from_env) to initialize the docker client. If you are using Docker Desktop, this might not work as expected due to the issue described [here](https://github.com/docker/docker-py/issues/3059). In that case follow the resolutions from the issue
The runner makes use of the python docker client's [from_env()](https://docker-py.readthedocs.io/en/stable/client.html#docker.client.from_env) to initialize the docker client. If you are using Docker Desktop, this might not work as expected due to the issue described [here](https://github.com/docker/docker-py/issues/3059). In that case follow the resolutions from the issue
- Either set `DOCKER_HOST` env to wherever the docker endpoint is configured.
```
export DOCKER_HOST=unix:///$HOME/.docker/desktop/docker.sock
Expand All @@ -44,5 +44,5 @@ sudo ln -s "$HOME/.docker/run/docker.sock" /var/run/docker.sock
| `TOOL_CONTAINER_LABELS` | Labels applied to tool containers for observability [Optional]. |
| `WORKFLOW_DATA_DIR` | Source mount bind directory for tool containers to access input files. |
| `TOOL_DATA_DIR` | Target mount directory within tool containers. (Default: "/data") |
| `LOG_LEVEL` | Log level for worker (Options: INFO, WARNING, ERROR, DEBUG, etc.) |
| `LOG_LEVEL` | Log level for runner (Options: INFO, WARNING, ERROR, DEBUG, etc.) |
| `REMOVE_CONTAINER_ON_EXIT`| Flag to decide whether to clean up/ remove the tool container after execution. (Default: True) |
2 changes: 1 addition & 1 deletion worker/entrypoint.sh → runner/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
--log-level debug \
--timeout 900 \
--access-logfile - \
unstract.worker.main:app
unstract.runner.main:app
File renamed without changes.
4 changes: 2 additions & 2 deletions worker/pyproject.toml → runner/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "unstract-worker"
name = "unstract-runner"
version = "0.1.0"
description = "Platform to interact with tools [Tool's Docker lifecycle management]"
authors = [
Expand Down Expand Up @@ -39,7 +39,7 @@ dev = [

[tool.pdm.scripts]
# Runs the flask service
runner.cmd = "flask --app src/unstract/worker/main.py run --port 5002"
runner.cmd = "flask --app src/unstract/runner/main.py run --port 5002"
runner.env_file = ".env"
runner.help = "Runs the Unstract tool runner"
# Run tests for this service
Expand Down
4 changes: 2 additions & 2 deletions worker/sample.env → runner/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ PRIVATE_REGISTRY_CREDENTIAL_PATH=
PRIVATE_REGISTRY_USERNAME=
PRIVATE_REGISTRY_URL=

# Log level for worker (Options: INFO, WARNING, ERROR, DEBUG, etc.)
# Log level for runner (Options: INFO, WARNING, ERROR, DEBUG, etc.)
LOG_LEVEL="INFO"

# Flag to decide whether to clean up/ remove the tool container after execution.
# (Default: True)
REMOVE_CONTAINER_ON_EXIT=True

# Client module path of the container engine to be used.
CONTAINER_CLIENT_PATH=unstract.worker.clients.docker
CONTAINER_CLIENT_PATH=unstract.runner.clients.docker

EXECUTION_RUN_DATA_FOLDER_PREFIX="/app/workflow_data"

Expand Down
3 changes: 3 additions & 0 deletions runner/src/unstract/runner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .worker import UnstractRunner

__all__ = ["UnstractRunner"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Optional

from flask import Blueprint, Flask, Response, abort, jsonify, request
from unstract.worker import UnstractWorker
from unstract.worker.utils import Utils
from unstract.runner import UnstractRunner
from unstract.runner.utils import Utils

app = Flask(__name__)

Expand Down Expand Up @@ -33,8 +33,8 @@ def run_container() -> Optional[Any]:
envs = data["envs"]
messaging_channel = data["messaging_channel"]

worker = UnstractWorker(image_name, image_tag, app)
result = worker.run_container(
runner = UnstractRunner(image_name, image_tag, app)
result = runner.run_container(
organization_id=organization_id,
workflow_id=workflow_id,
execution_id=execution_id,
Expand All @@ -61,9 +61,9 @@ def run_command(command: str) -> Optional[Any]:
abort(404)
image_name = request.args.get("image_name")
image_tag = request.args.get("image_tag")
worker = UnstractWorker(image_name, image_tag, app)
runner = UnstractRunner(image_name, image_tag, app)

return worker.run_command(command)
return runner.run_command(command)


# Register the Blueprint with the Flask app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from dotenv import load_dotenv
from flask import Flask
from unstract.worker.clients.helper import ContainerClientHelper
from unstract.worker.clients.interface import (
from unstract.runner.clients.helper import ContainerClientHelper
from unstract.runner.clients.interface import (
ContainerClientInterface,
ContainerInterface,
)
from unstract.worker.constants import Env, FeatureFlag, LogLevel, LogType, ToolKey
from unstract.worker.exception import ToolRunException
from unstract.runner.constants import Env, FeatureFlag, LogLevel, LogType, ToolKey
from unstract.runner.exception import ToolRunException

from unstract.core.constants import LogFieldName
from unstract.core.pubsub_helper import LogPublisher
Expand All @@ -23,7 +23,7 @@
client_class = ContainerClientHelper.get_container_client()


class UnstractWorker:
class UnstractRunner:
def __init__(self, image_name: str, image_tag: str, app: Flask) -> None:
self.image_name = image_name
# If no image_tag is provided will assume the `latest` tag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from dotenv import load_dotenv
from unstract.worker.constants import Env
from unstract.worker.enum import LogLevel
from unstract.runner.constants import Env
from unstract.runner.enum import LogLevel

load_dotenv()

Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tox]
env_list = py{39,310,311}, worker
env_list = py{39,310,311}, runner

# [testenv]
# skip_install = true

[testenv:worker]
changedir = worker
[testenv:runner]
changedir = runner
setenv =
PDM_IGNORE_SAVED_PYTHON="1"
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Expand All @@ -16,4 +16,4 @@ commands_pre =
pdm sync --dev
sh -c '[ -f cloud_requirements.txt ] && pip install -r cloud_requirements.txt || echo "cloud_requirements.txt not found"'
commands =
pytest -v --md-report-verbose=1 --md-report --md-report-flavor gfm --md-report-output ../worker-report.md
pytest -v --md-report-verbose=1 --md-report --md-report-flavor gfm --md-report-output ../runner-report.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class UnstractWorker:
class UnstractRunner:
BASE_API_ENDPOINT = "/v1/api"
RUN_API_ENDPOINT = "/container/run"
SPEC_API_ENDPOINT = "/container/spec"
Expand Down
Loading

0 comments on commit f92fea2

Please sign in to comment.