Skip to content

Commit 37153b4

Browse files
authored
Add artifact support with ORAS to make them OCI format (#15)
* Add artifact support with ORAS to make them OCI format Signed-off-by: kerthcet <kerthcet@gmail.com> * format Signed-off-by: kerthcet <kerthcet@gmail.com> * fix ci test Signed-off-by: kerthcet <kerthcet@gmail.com> * fix ci test Signed-off-by: kerthcet <kerthcet@gmail.com> * fix ci test Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent 73f11c6 commit 37153b4

24 files changed

Lines changed: 578 additions & 17 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# We use PG by default as the metadata database.
22
METADATA_DB_URL=postgresql+psycopg2://user:pass@localhost:5432/mydb
3+
ARTIFACT_REGISTRY_URL=http://localhost:5000/
34
LOG_LEVEL=INFO

.env.integration-test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
METADATA_DB_URL=sqlite:///:memory:
2+
ARTIFACT_REGISTRY_URL=europe-west2-docker.pkg.dev/runsandbox-449400/
3+
LOG_LEVEL=INFO

.env.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
METADATA_DB_URL=sqlite:///:memory:
2+
ARTIFACT_REGISTRY_URL=localhost:5000
3+
LOG_LEVEL=INFO

.github/workflows/python-ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ jobs:
2525
run: poetry config virtualenvs.in-project true
2626

2727
- name: Install dependencies
28-
run: poetry install --no-interaction --no-ansi
28+
run: poetry install --with dev --no-interaction --no-ansi
29+
30+
# Lint is already included in `make test`
2931

3032
- name: Run tests
3133
run: make test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Dockerfile.cross
99

1010
# Test binary, build with `go test -c`
1111
*.test
12+
!.env.test
1213

1314
# Output of the go coverage tool, specifically when used with LiteIDE
1415
*.out

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ publish: build
1212
launch:
1313
docker-compose up -d
1414

15-
.PHONY: test
16-
test:
17-
$(POETRY) run pytest
18-
1915
.PHONY: format
2016
format:
21-
ruff format .
22-
ruff check --fix .
17+
$(POETRY) run ruff format .
18+
$(POETRY) run ruff check .
19+
20+
.PHONY: test
21+
test: format
22+
$(POETRY) run pytest tests/unit
23+
24+
.PHONY: test-integration
25+
test-integration: format
26+
$(POETRY) run pytest tests/integration

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
**AlphaTrion** is an open-source and all-in-one platform to build LLM-powered applications. Named after the wise Transformer mentor, it embodies guidance and innovation to help developers build **production-ready** GenAI applications with ease. *Still under active development.*
44

5+
## How to Install
6+
7+
### Install from PyPI
8+
9+
```bash
10+
pip install alphatrion
11+
```
12+
13+
### Install from Source
14+
15+
Refer to [developer.md](./docs/development.md) for more information on how to set up your development environment.
16+
17+
## Quick Start
18+
19+
Still under active development now.
20+
21+
Refer to [troubleshooting.md](./docs/troubleshooting.md) for common issues and solutions which may help.
22+
523
## How to Contribute
624

725
We welcome all kinds of contributions! Please see our [contribution guidelines](CONTRIBUTING.md) for more details.

alphatrion/artifact/__init__.py

Whitespace-only changes.

alphatrion/artifact/artifact.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
3+
import oras.client
4+
5+
from alphatrion import consts
6+
from alphatrion.runtime.runtime import Runtime
7+
8+
SUCCESS_CODE = 201
9+
10+
11+
class Artifact:
12+
def __init__(self, runtime: Runtime):
13+
self._runtime = runtime
14+
self._url = os.environ.get(consts.ARTIFACT_REGISTRY_URL)
15+
self._url = self._url.replace("https://", "").replace("http://", "")
16+
self._client = oras.client.OrasClient(
17+
hostname=self._url.strip("/"), auth_backend="token"
18+
)
19+
20+
def push(self, experiment_name: str, files: list[str], version: str = "latest"):
21+
url = self._url if self._url.endswith("/") else f"{self._url}/"
22+
23+
target = f"{url}{self._runtime._project_id}/{experiment_name}:{version}"
24+
25+
try:
26+
self._client.push(target, files=files)
27+
except Exception as e:
28+
raise RuntimeError("Failed to push artifacts") from e
29+
30+
def list_tags(self, experiment_name: str) -> list[str]:
31+
url = self._url if self._url.endswith("/") else f"{self._url}/"
32+
target = f"{url}{self._runtime._project_id}/{experiment_name}"
33+
try:
34+
tags = self._client.get_tags(target)
35+
return tags
36+
except Exception as e:
37+
raise RuntimeError("Failed to list artifacts tags") from e
38+
39+
def delete_tags(self, experiment_name: str, versions: str | list):
40+
url = self._url if self._url.endswith("/") else f"{self._url}/"
41+
target = f"{url}{self._runtime._project_id}/{experiment_name}"
42+
43+
try:
44+
self._client.delete_tags(target, tags=versions)
45+
except Exception as e:
46+
raise RuntimeError("Failed to delete tags") from e

alphatrion/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
METADATA_DB_URL = "METADATA_DB_URL"
2+
ARTIFACT_REGISTRY_URL = "ARTIFACT_REGISTRY_URL"

0 commit comments

Comments
 (0)