-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from konstellation-io/feat/KAI-138-add-uv-to-th…
…e-project Feat/kai 138 add uv to the project and rest trigger in golang
- Loading branch information
Showing
13 changed files
with
1,914 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Training process | ||
|
||
This process is an example of a training process for a machine learning model. | ||
|
||
## Pre-requisites | ||
|
||
- python 3.13. Please refer to [installation](https://www.python.org/about/gettingstarted/) | ||
- uv: It is used as the package/project manager for this project. Please refer to [installation](https://docs.astral.sh/uv/getting-started/installation/) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
[project] | ||
name = "training" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = "~=3.13" | ||
authors = ["Intelygenz - KAI Team"] | ||
maintainers = ["Intelygenz - KAI Team"] | ||
|
||
dependencies = [ | ||
"nats-py==2.6.0", | ||
"protobuf==4.23.4", | ||
"loguru==0.7.0", | ||
"kai-runner", | ||
] | ||
|
||
[dependency-groups] | ||
dev = [ | ||
"ruff==0.8.1", | ||
] | ||
|
||
[tool.uv] | ||
default-groups = ["dev"] | ||
|
||
[tool.uv.sources] | ||
kai-runner = { git = "https://github.com/konstellation-io/kai-pysdk.git" } | ||
|
||
[tool.ruff] | ||
# Exclude a variety of commonly ignored directories. | ||
exclude = [ | ||
"*_pb2.py", | ||
".bzr", | ||
".direnv", | ||
".eggs", | ||
".git", | ||
".git-rewrite", | ||
".hg", | ||
".ipynb_checkpoints", | ||
".mypy_cache", | ||
".nox", | ||
".pants.d", | ||
".pyenv", | ||
".pytest_cache", | ||
".pytype", | ||
".ruff_cache", | ||
".svn", | ||
".tox", | ||
".venv", | ||
".vscode", | ||
"__pypackages__", | ||
"_build", | ||
"buck-out", | ||
"build", | ||
"dist", | ||
"node_modules", | ||
"site-packages", | ||
"venv", | ||
] | ||
|
||
# Same as Black. | ||
line-length = 88 | ||
indent-width = 4 | ||
|
||
target-version = "py313" | ||
|
||
[tool.ruff.lint] | ||
select = ["E4", "E7", "E9", "F", "Q"] | ||
ignore = [] | ||
|
||
fixable = ["ALL"] | ||
unfixable = [] | ||
|
||
# Allow unused variables when underscore-prefixed. | ||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" | ||
|
||
[tool.ruff.format] | ||
# Like Black, use double quotes for strings. | ||
quote-style = "double" | ||
|
||
# Like Black, indent with spaces, rather than tabs. | ||
indent-style = "space" | ||
|
||
# Like Black, respect magic trailing commas. | ||
skip-magic-trailing-comma = false | ||
|
||
# Like Black, automatically detect the appropriate line ending. | ||
line-ending = "auto" | ||
|
||
# Enable auto-formatting of code examples in docstrings. Markdown, | ||
# reStructuredText code/literal blocks and doctests are all supported. | ||
# | ||
# This is currently disabled by default, but it is planned for this | ||
# to be opt-out in the future. | ||
docstring-code-format = false | ||
|
||
# Set the line length limit used when formatting code snippets in | ||
# docstrings. | ||
# | ||
# This only has an effect when the `docstring-code-format` setting is | ||
# enabled. | ||
docstring-code-line-length = "dynamic" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM golang:1.22.0-alpine3.19 AS builder | ||
|
||
# Build the binary statically. | ||
ENV CGO_ENABLED=0 | ||
|
||
WORKDIR /app | ||
COPY go.* ./ | ||
RUN go mod download | ||
COPY . . | ||
RUN go build -o process . | ||
|
||
FROM alpine:3.10.2 | ||
|
||
# Create kai user. | ||
ENV USER=kai | ||
ENV UID=10001 | ||
|
||
RUN apk add -U --no-cache ca-certificates | ||
RUN mkdir -p /var/log/app | ||
|
||
RUN adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
"${USER}" | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/process process | ||
|
||
RUN chown -R kai:0 /app \ | ||
&& chmod -R g+w /app \ | ||
&& mkdir /var/log/app -p \ | ||
&& chown -R kai:0 /var/log/app \ | ||
&& chmod -R g+w /var/log/app | ||
|
||
USER kai | ||
|
||
CMD ["sh","-c","/app/process"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# REST trigger | ||
|
||
The REST webhook trigger is a predefined KAI process that creates a REST server instance. | ||
It will stay listening for client requests through port 8080. | ||
|
||
## How to setup | ||
|
||
There is an optional "path" configuration for users to specify the path in which the REST service will be deployed. | ||
If no "path" is setup, the trigger will be in the default "trigger" path. | ||
|
||
Processes communicating with this trigger must be prepared to do so. Processes listening to | ||
the REST trigger need to unmmarshal protobuf based JSON messages, and processes sending messages to | ||
the trigger need to marshal protobuf based JSON messages. | ||
|
||
Both output and input messages towards this process require the usage of specific keys in the JSON. | ||
|
||
### Configuration | ||
|
||
The configuration should be defined inside the `centralized configuration scope`: | ||
|
||
| Key | Optional | Type | Value | | ||
|-----------|-----------|------|----------------------------------------------------------------| | ||
| path | yes | str | Where the REST service will be deployed ("trigger" by default). | | ||
|
||
#### Configuration Example | ||
|
||
```yaml | ||
centralized_configuration: | ||
process: | ||
config: | ||
path: 'mypath' | ||
``` | ||
### Trigger's Output (JSON) | ||
| Key | Type | Value | | ||
|-----------|---------|-------------------------------------------------------------------------------------------| | ||
| method | str | The REST method used | | ||
| body | []byte | Optional. For POST and PUT methods the body is taken from the request's body | | ||
#### Trigger's Output Example | ||
```json | ||
{ | ||
"method": "POST", | ||
"body": {"keyA": "valueA", "keyB": "valueB"}, | ||
} | ||
``` | ||
|
||
### Trigger's Input from other processes (JSON) | ||
|
||
| Key | Type | Value | | ||
|-------------|------|----------------------------------------------------------------------------| | ||
| status_code | str | Status code for the workflow execution, used later in http server response | | ||
| message | str | A message sent by the user | | ||
|
||
#### Trigger's Input Example | ||
|
||
```json | ||
{ | ||
"status_code": "200", | ||
"message": "All good!", | ||
} | ||
``` | ||
|
||
### Trigger's Output to client (JSON) | ||
|
||
| Key | Type | Value | | ||
|-----------|------|------------------------------------------------------------------------| | ||
| message | str | A message | | ||
|
||
#### Trigger's Output to client | ||
|
||
```json | ||
{ | ||
"message": "All good!", | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module github.com/konstellation-io/kai-processes/rest-trigger | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.9.1 | ||
github.com/google/uuid v1.3.1 | ||
github.com/konstellation-io/kai-sdk/go-sdk/v2 v2.1.1 | ||
google.golang.org/protobuf v1.31.0 | ||
) | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.2.1 // indirect | ||
github.com/Nerzal/gocloak/v13 v13.8.0 // indirect | ||
github.com/bytedance/sonic v1.9.1 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-logr/logr v1.3.0 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-logr/zapr v1.2.4 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.14.0 // indirect | ||
github.com/go-resty/resty/v2 v2.7.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/compress v1.17.0 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/minio/md5-simd v1.1.2 // indirect | ||
github.com/minio/minio-go/v7 v7.0.63 // indirect | ||
github.com/minio/sha256-simd v1.0.1 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/nats-io/nats.go v1.31.0 // indirect | ||
github.com/nats-io/nkeys v0.4.6 // indirect | ||
github.com/nats-io/nuid v1.0.1 // indirect | ||
github.com/opentracing/opentracing-go v1.2.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/redis/go-redis/v9 v9.3.0 // indirect | ||
github.com/rs/xid v1.5.0 // indirect | ||
github.com/sagikazarmark/locafero v0.3.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/segmentio/ksuid v1.0.4 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.10.0 // indirect | ||
github.com/spf13/cast v1.5.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.17.0 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/testcontainers/testcontainers-go v0.26.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
go.opentelemetry.io/otel v1.21.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.21.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.21.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.21.0 // indirect | ||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.26.0 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/crypto v0.17.0 // indirect | ||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.15.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect | ||
google.golang.org/grpc v1.59.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.