Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reactor repo #1

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Frinx common use-case wfs
description: Report a bug or unexpected behavior
labels: [bug, pending]

body:
- type: markdown
attributes:
value: Thank you for contributing to repository!

- type: textarea
id: description
attributes:
label: Description
description: |
Please explain what you're seeing and what you would expect to see.

Please provide as much detail as possible to make understanding and solving your problem as quick as possible.
validations:
required: true

- type: textarea
id: example
attributes:
label: Example Code
description: >
If applicable, please add a self-contained,
[minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example)
demonstrating the bug.

placeholder: |
import frinx

...
render: Python

- type: textarea
id: version
attributes:
label: Python, Poetry & Packages Version
description: |
Which versions of packages you are using?

Please run the following command (or equivalent) and copy the output below:

```bash
poetry env info
poetry show
poetry self --version
```

render: Text
validations:
required: true
49 changes: 49 additions & 0 deletions .github/workflows/pr_code_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check code quality

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
check:
name: Test code quality
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
matrix:
python-version: ['3.11']
poetry-version: ['1.7.1']

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install package dependencies
run: |
export POETRY_INSTALLER_PARALLEL=false
poetry install

- name: Run mypy
run: |
poetry run mypy .

- name: Run ruff
run: |
poetry run ruff check .

- name: Run pyright
run: |
poetry run pyright .
137 changes: 18 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,35 @@
# frinx-workers-boilerplate

- helm-chart: Frinx Machine installation scripts
- worker: Python worker project
This repository provides an easy setup for the [workflow manager worker](https://docs.frinx.io/frinx-workflow-manager/python-sdk/).

## Frinx Machine installation
### Prerequisities

### Cluster setup
Before you begin, ensure you have the following tools installed:

Start minikube with recommended settings
```bash
minikube start --cpus=max --memory=24G --addons=ingress
```

Get minikube ip

```bash
minikube ip

192.168.49.2
```

Add to your /etc/hosts. Change to your minikube ip

```bash
#/etc/hosts
192.168.49.2 krakend.127.0.0.1.nip.io workflow-manager.127.0.0.1.nip.io
```

```bash
kubectl create namespace frinx
```

### Helm Charts installation

Create a kubernetes Docker registry secret for pulling images from private registry:

```bash
# PLACEHOLDERS must be replaced with user credentials
kubectl create secret -n frinx docker-registry regcred \
--docker-server="https://index.docker.io/v1/" \
--docker-username="<PLACEHOLDER>" \
--docker-password="<PLACEHOLDER>"
```

For more info about accessing private images, visit [Download Frinx Uniconfig](https://docs.frinx.io/frinx-uniconfig/getting-started/#download-frinx-uniconfig)


Frinx Machine operators
```bash
helm dependency build ./helm-charts/frinx-machine-operators
helm upgrade --install -n frinx frinx-machine-operators ./helm-charts/frinx-machine-operators
```
- `python`: Version 3.10 or higher
- `poetry`: Python packaging and dependency management tool
- `frinx-machine`: Follow the instructions at [Frinx Machine GitHub](https://github.com/FRINXio/gitops-boilerplate)

Frinx Machine
```bash
helm dependency build ./helm-charts/frinx-machine
helm upgrade --install -n frinx frinx-machine ./helm-charts/frinx-machine
```

In case, you want to work with simulated devices, run sample-topology as well

Sample Topology
```bash
helm dependency build ./helm-charts/sample-topology
helm upgrade --install -n frinx sample-topology ./helm-charts/sample-topology
```

### Custom Worker customization

Change image repositor and tag to address your image

```bash
# helm-charts/custom-worker/values.yaml
image:
repository: frinx/frinx-demo-workflows
tag: "6.0.0"
```

You can import your custom image via:
## Quick Start

```bash
minikube image load your/image:tag
```

## Custom worker setup

### Create project
Ensure you are using Python version 3.10 or higher.
Set up your environment and install dependencies with `poetry`:

```bash
# Use python version 3.10 or higher
poetry env use python3.10
poetry install
```

### Start project

```bash
poetry run python3 main.py
```
Use Krakend and worker ingress for local development.
Override default SDK environment variables with your own.
Note that these environment variables should not be used in a Kubernetes deployment.

### Configure rbac
Use a config/env_local.template file and configure it as follows:

```bash
# .env
# CONFIGURE CONDUCTOR CLIENT URL
CONDUCTOR_URL_BASE=http://workflow-manager.127.0.0.1.nip.io/api
# USE KRAKEND ENDPOINTS To ACCESS API
Expand All @@ -115,38 +43,9 @@ UNICONFIG_ZONE_URL_TEMPLATE=http://krakend.127.0.0.1.nip.io/api/{uc}
X_AUTH_USER_GROUP=FRINXio
```

### Configure Ingress for services

```yaml

frinx-machine:
krakend:
ingress:
enabled: true
className: nginx
annotations:
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
hosts:
- host: krakend.127.0.0.1.nip.io
paths:
- path: "/"
pathType: ImplementationSpecific
Export the environment variables and run the main script:

workflow-manager:
ingress:
enabled: true
hosts:
- host: workflow-manager.127.0.0.1.nip.io
paths:
- path: "/"
pathType: ImplementationSpecific
schellarHosts:
- host: workflow-manager-schellar.127.0.0.1.nip.io
paths:
- path: "/"
pathType: ImplementationSpecific
```bash
export $(cat config/env_local.template | sed -e /^$/d -e /^#/d | xargs)
poetry run python3 main.py
```

File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions app/workers/boilerplate_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from frinx.common.conductor_enums import TaskResultStatus
from frinx.common.type_aliases import ListAny
from frinx.common.worker.task_def import TaskDefinition
from frinx.common.worker.task_def import TaskInput
from frinx.common.worker.task_def import TaskOutput
from frinx.common.worker.task_result import TaskResult
from frinx.common.worker.worker import WorkerImpl


class SumWorker(WorkerImpl):
class WorkerDefinition(TaskDefinition):
name: str = "SUM_int"
description: str = "Sum two numbers together"
labels: ListAny = ["TEST"]
timeout_seconds: int = 60
response_timeout_seconds: int = 60

class WorkerInput(TaskInput):
num_a: int
num_b: int

class WorkerOutput(TaskOutput):
output: int

def execute(self, worker_input: WorkerInput) -> TaskResult[WorkerOutput]:
result = worker_input.num_a + worker_input.num_b

return TaskResult(
status=TaskResultStatus.COMPLETED,
logs=["SUM worker invoked successfully"],
output=self.WorkerOutput(output=result)
)
File renamed without changes.
56 changes: 56 additions & 0 deletions app/workflows/boilerplate_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from frinx.common.conductor_enums import TimeoutPolicy
from frinx.common.type_aliases import ListStr
from frinx.common.workflow.task import SimpleTask
from frinx.common.workflow.task import SimpleTaskInputParameters
from frinx.common.workflow.workflow import FrontendWFInputFieldType
from frinx.common.workflow.workflow import WorkflowImpl
from frinx.common.workflow.workflow import WorkflowInputField

from app.workers.boilerplate_worker import SumWorker


class SumWorkflow(WorkflowImpl):
name: str = "Sum_numbers"
version: int = 1
description: str = "Sum 2 int numbers together"
labels: ListStr = ["TEST"]
timeout_seconds: int = 60 * 5
timeout_policy: TimeoutPolicy = TimeoutPolicy.TIME_OUT_WORKFLOW

class WorkflowInput(WorkflowImpl.WorkflowInput):
num_a: WorkflowInputField = WorkflowInputField(
name="num_a",
frontend_default_value=5,
description="Number A",
type=FrontendWFInputFieldType.INT,
)

num_b: WorkflowInputField = WorkflowInputField(
name="num_b",
frontend_default_value=3,
description="Number B",
type=FrontendWFInputFieldType.INT,
)

class WorkflowOutput(WorkflowImpl.WorkflowOutput):
sum: str

def workflow_builder(self, workflow_inputs: WorkflowInput) -> None:

sum_task = SimpleTask(
name=SumWorker,
task_reference_name="sum",
input_parameters=SimpleTaskInputParameters(
root=dict(
num_a=workflow_inputs.num_a.wf_input,
num_b=workflow_inputs.num_b.wf_input
)
)
)
self.tasks = [
sum_task
]

self.output_parameters = self.WorkflowOutput(
sum=sum_task.output_ref("sum")
)
File renamed without changes.
Loading
Loading