system/README.md
gitea_admin_user fba827a948
All checks were successful
CI Workflow / test (push) Successful in 1m52s
CI Workflow / Containerize the Block (push) Successful in 1m38s
Add initial files
2025-04-09 16:45:34 +00:00

37 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Activity Block Wrapper
## Overview
This project includes a setup to wrap a user-defined `block.py` file into an activity block that runs within a managed worker environment. The setup uses `entrypoint.py` as a wrapper to dynamically load and execute the logic defined in `block.py` and make it available as an activity block.
This README explains the purpose and functionality of `entrypoint.py`, the `activity_block_wrapper` base image, and how it all comes together within the Dockerfile to create a production-ready, deployable worker.
## Files
### 1. `entrypoint.py`
`entrypoint.py` is the main entry script for the activity block wrapper. It provides the following functionality:
- **Dynamic Loading**: Imports `block.py` and retrieves its `__main__` function dynamically. This function is wrapped and managed within the worker environment.
- **Logging and Error Handling**: Includes logging and error handling to ensure issues are properly recorded and managed, which is essential for production environments.
- **Worker Management**: Starts a worker instance that manages the execution of the activity block, making the `block.py` logic available as an activity in the specified task queue and namespace.
#### Configuration
- `TASK_QUEUE`: The task queue name for the worker. Set via environment variable.
- `NAMESPACE`: The namespace for the worker to operate within. Set via environment variable.
#### Example Usage
To configure and run `entrypoint.py` in your environment:
1. Set the `TASK_QUEUE` and `NAMESPACE` environment variables.
2. Run `entrypoint.py`, and it will automatically wrap `block.py` as an activity block within the worker.
### 2. Dockerfile
The Dockerfile is structured to create an image that:
- Uses `activity_block_wrapper` as a base, which includes `entrypoint.py` and pre-installed dependencies.
- Copies the users `block.py` and other project-specific files into the container.
- Creates a symbolic link to `entrypoint.py` as `block.py`, making it appear as if `block.py` is the entry point, while actually running `entrypoint.py` to manage the activity block.
#### Key Dockerfile Commands
- **FROM activity_block_wrapper:latest**: Builds on top of the `activity_block_wrapper` image, which includes the necessary runtime environment and `entrypoint.py`.
- **COPY**: Copies the users `block.py` and other related files into the container.
- **RUN ln -s /app/entrypoint.py /app/block.py**: Creates a symbolic link from `entrypoint.py` to `block.py`, allowing `entrypoint.py` to manage the activity block while maintaining `block.py` as the visible entry point.
### Example Usage with Docker
1. **Build the Base Image**:
```bash
docker build -f Dockerfile.base -t activity_block_wrapper:latest .