Skip to content

Commit

Permalink
Update to work with the ETOS controller (#106)
Browse files Browse the repository at this point in the history
* Make environment provider compatible with the kubernetes controller
  • Loading branch information
t-persson authored Nov 21, 2024
1 parent f45fa6e commit 9b543a8
Show file tree
Hide file tree
Showing 19 changed files with 924 additions and 430 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile to use with the controller environment where we run the environment provider as a Job
# instead of running it as an imported service in the suite runner.
FROM python:3.9-bookworm AS build

COPY . /src
WORKDIR /src
RUN pip install --no-cache-dir build && python3 -m build

FROM python:3.9-slim-bookworm

COPY --from=build /src/dist/*.whl /tmp
# hadolint ignore=DL3013

RUN pip install --no-cache-dir /tmp/*.whl && groupadd -r etos && useradd -r -m -s /bin/false -g etos etos

USER etos

LABEL org.opencontainers.image.source=https://github.com/eiffel-community/etos-environment-provider
LABEL org.opencontainers.image.authors=etos-maintainers@googlegroups.com
LABEL org.opencontainers.image.licenses=Apache-2.0

CMD ["python", "-u", "-m", "environment_provider.environment_provider"]
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"jsontas~=1.3",
"packageurl-python~=0.11",
"etcd3gw~=2.3",
"etos_lib==4.3.6",
"etos-lib==4.4.1",
"opentelemetry-api~=1.21",
"opentelemetry-exporter-otlp~=1.21",
"opentelemetry-sdk~=1.21",
Expand Down Expand Up @@ -52,4 +52,4 @@ norecursedirs = ["dist", "build", ".tox"]
testpaths = ["tests"]

[tool.setuptools.packages]
find = { where = ["src"], exclude = ["tests"] }
find = { where = ["src"], exclude = ["tests"] }
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cryptography>=42.0.4,<43.0.0
jsontas~=1.3
packageurl-python~=0.11
etcd3gw~=2.3
etos_lib==4.3.6
etos-lib==4.4.1
opentelemetry-api~=1.21
opentelemetry-exporter-otlp~=1.21
opentelemetry-sdk~=1.21
Expand Down
39 changes: 32 additions & 7 deletions src/environment_provider/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"""Backend for the environment requests."""
import json
import time
import sys
import traceback
import logging
import re
from typing import Optional, Union

Expand All @@ -26,6 +28,7 @@

from environment_provider.lib.database import ETCDPath
from environment_provider.lib.registry import ProviderRegistry
from environment_provider.lib.releaser import EnvironmentReleaser
from execution_space_provider import ExecutionSpaceProvider
from execution_space_provider.execution_space import ExecutionSpace
from iut_provider import IutProvider
Expand Down Expand Up @@ -71,16 +74,12 @@ def release_environment(
"""
etos.config.set("SUITE_ID", sub_suite.get("suite_id"))
iut = sub_suite.get("iut")
iut_ruleset = provider_registry.get_iut_provider_by_id(iut.get("provider_id")).get("iut")
iut_ruleset = provider_registry.get_iut_provider().get("iut")
executor = sub_suite.get("executor")
executor_ruleset = provider_registry.get_execution_space_provider_by_id(
executor.get("provider_id")
).get("execution_space")
executor_ruleset = provider_registry.get_execution_space_provider().get("execution_space")

log_area = sub_suite.get("log_area")
log_area_ruleset = provider_registry.get_log_area_provider_by_id(
log_area.get("provider_id")
).get("log")
log_area_ruleset = provider_registry.get_log_area_provider().get("log")

failure = None

Expand Down Expand Up @@ -151,3 +150,29 @@ def release_full_environment(etos: ETOS, jsontas: JsonTas, suite_id: str) -> tup
traceback.format_exception(failure, value=failure, tb=failure.__traceback__)
)
return True, ""


def run(environment_id: str):
"""Run is an entrypoint for releasing environments."""
logformat = "[%(asctime)s] %(levelname)s:%(message)s"
logging.basicConfig(
level=logging.INFO, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
)
try:
releaser = EnvironmentReleaser()
releaser.run(environment_id)
result = {"conclusion": "Successful", "description": "Successfully released an environment"}
with open("/dev/termination-log", "w", encoding="utf-8") as termination_log:
json.dump(result, termination_log)
except:
try:
result = {"conclusion": "Failed", "description": traceback.format_exc()}
with open("/dev/termination-log", "w", encoding="utf-8") as termination_log:
json.dump(result, termination_log)
except PermissionError:
pass
raise


if __name__ == "__main__":
run(sys.argv[1])
Loading

0 comments on commit 9b543a8

Please sign in to comment.