import os from invoke import task IMAGE_RESPOSITORY = os.environ.get("IMAGE_RESPOSITORY", "registry.runcible.io/learn_otel") @task def update_deps(c): """Updates depenencies""" c.run("pip-compile requirements.in", pty=True) c.run("pip-compile dev-requirements.in", pty=True) @task def sync_deps(c): """Syncs local dependencies""" c.run("pip-sync requirements.txt dev-requirements.txt") @task def lint(c): """Runs all linters against the project.""" c.run("./scripts/run_linters.sh", pty=True) @task def delint(c): """Applies automated linters to project""" c.run("isort ./learn_otel ./tests ./tasks.py", pty=True) c.run("black ./learn_otel ./tests ./tasks.py", pty=True) @task def build(c): """Builds the project as a Python package.""" c.run("python3 -m build") @task def build_image(c, dev=True, registry_user=None, registry_token=None, push=False, login=False): """Builds the learn_otel container image.""" context_dir = c.run("pwd", hide=True).stdout.strip() commit_sha = c.run("git rev-parse --short HEAD", hide=True).stdout.strip() image_name = f"{IMAGE_RESPOSITORY}:{commit_sha}{'-dev' if dev else ''}" c.run(f"docker build --build-arg='COMMIT_SHA={commit_sha}' -t {image_name} {context_dir}") if login: if registry_user is None or registry_token is None: raise ValueError("--registry_user and --registry_token must be provided if using --login parameter") c.run(f"docker login -u {registry_user} -p {registry_token}") if push: c.run(f"docker push {image_name}")