Browse Source

Runner skeleton

pull/26/head
Daniel Gyulai 3 years ago
parent
commit
885c5a4a90
  1. 34
      alice-ci/src/alice/cli.py
  2. 4
      alice-ci/src/alice/runnerfactory.py
  3. 18
      alice-ci/src/alice/runners/dockerrunner.py
  4. 9
      alice-ci/src/alice/runners/pypirunner.py
  5. 13
      alice-ci/src/alice/runners/pyutils.py
  6. 15
      ci-examples/full.yaml
  7. 25
      docs/runners/docker.md

34
alice-ci/src/alice/cli.py

@ -6,6 +6,40 @@ from alice.configparser import ConfigParser
from alice.exceptions import ConfigException, NonZeroRetcode, RunnerError from alice.exceptions import ConfigException, NonZeroRetcode, RunnerError
class ConfigHolder:
__instance = None
file_name = ".alice"
@staticmethod
def getInstance():
""" Static access method. """
if ConfigHolder.__instance is None:
ConfigHolder()
return ConfigHolder.__instance
def __init__(self):
""" Virtually private constructor. """
if ConfigHolder.__instance is not None:
raise Exception("This class is a singleton!")
else:
ConfigHolder.__instance = self
config = os.path.abspath(os.path.join(os.getcwd(), self.file_name))
self.vars = {}
if os.path.isfile(config):
with open(config) as f:
for line in f:
items = line.split("=")
if len(items) > 1:
self.vars[items[0]] = line.replace(f"{items[0]}=", "")
logging.debug(f"Loaded from {self.file_name}: {self.vars}")
def get(self, key):
try:
self.vars[key]
except KeyError:
raise ConfigException(f"{key} not defined in .conf!")
def gen_env(param_list): def gen_env(param_list):
env_vars = {} env_vars = {}
for item in param_list: for item in param_list:

4
alice-ci/src/alice/runnerfactory.py

@ -3,6 +3,7 @@ from os.path import join, abspath
from alice.runners.pythonrunner import PythonRunner from alice.runners.pythonrunner import PythonRunner
from alice.runners.pypirunner import PyPiRunner from alice.runners.pypirunner import PyPiRunner
from alice.runners.dockerrunner import DockerRunner
from alice.exceptions import ConfigException from alice.exceptions import ConfigException
@ -21,7 +22,8 @@ class Factory():
# module = __import__("module_file") # module = __import__("module_file")
# my_class = getattr(module, "class_name") # my_class = getattr(module, "class_name")
self.runnertypes = {"python": PythonRunner, self.runnertypes = {"python": PythonRunner,
"pypi": PyPiRunner} "pypi": PyPiRunner,
"docker": DockerRunner}
logging.info(f"[Alice] Available runners: {'|'.join(self.runnertypes.keys())}") logging.info(f"[Alice] Available runners: {'|'.join(self.runnertypes.keys())}")

18
alice-ci/src/alice/runners/dockerrunner.py

@ -1 +1,19 @@
# TODO Implement # TODO Implement
class DockerConfig:
def __init__(self, config={}) -> None:
pass
def copy(self, job_config):
pass
# Supported tasks:
# - Build image
# - Push image to repo
# - Run arbitrary code in image
class DockerRunner():
def __init__(self) -> None:
pass
def run(self, job_spec):
pass

9
alice-ci/src/alice/runners/pypirunner.py

@ -7,17 +7,10 @@ import sys
from urllib import request, error from urllib import request, error
from pkg_resources import parse_version from pkg_resources import parse_version
from os import environ, path from os import environ, path
from alice.runners.pyutils import PackageManager, glob from alice.runners.pyutils import PackageManager, glob, grab_from
from alice.exceptions import ConfigException, RunnerError from alice.exceptions import ConfigException, RunnerError
def grab_from(target):
if "from_env" in target:
return environ[target["from_env"]]
else:
raise ConfigException(f"Unsupported grabber: {target.keys()}")
def get_uri(config, default): def get_uri(config, default):
url = config.get("repo", {}).get("uri", default) url = config.get("repo", {}).get("uri", default)
if url is not None: if url is not None:

13
alice-ci/src/alice/runners/pyutils.py

@ -6,6 +6,7 @@ from pkg_resources import parse_version
import re import re
from alice.exceptions import RunnerError, ConfigException from alice.exceptions import RunnerError, ConfigException
from alice.cli import ConfigHolder
class PackageManager: class PackageManager:
@ -111,3 +112,15 @@ def glob_command(command, workdir):
for item in command: for item in command:
new_command += glob(item, workdir) new_command += glob(item, workdir)
return new_command return new_command
def grab_from(target):
if "from_env" in target:
try:
return os.environ[target["from_env"]]
except KeyError:
raise ConfigException(f"Env var unset: {target['from_env']}")
elif "from_cfg" in target:
ConfigHolder.getInstance().get(target["from_cfg"])
else:
raise ConfigException(f"Unsupported grabber: {target.keys()}")

15
ci-examples/full.yaml

@ -15,6 +15,8 @@ runners:
dependencies: dependencies:
- flake8 - flake8
- build - build
docker:
credentials:
jobs: jobs:
- name: env - name: env
type: python type: python
@ -46,6 +48,19 @@ jobs:
from_env: PYPIPASS from_env: PYPIPASS
packages: packages:
- alice-ci - alice-ci
- name: image
type: docker
image:
credentials:
user:
from_env: DOCKERUSER
pass:
from_env: DOCKERPASS
name: python:latest
build_dir: ci-examples/docker
commands:
- python3 --version
pipelines: pipelines:
default: default:
- lint - lint

25
docs/runners/docker.md

@ -0,0 +1,25 @@
# Schema
```
name: ""
type: docker
credentials: - global ...ish
user
pass
image: - to use, pull, run
credentials:
build:
dir:
dockerfile:
name:
args:
- name:
- value:
name: - pulls, current working image - mutually exclusive with build
command: - overwrite, not append
- ...
tag:
publish: true
name: - published name with repo and everything
credentials:
```
Loading…
Cancel
Save