You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
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}")
|
|
|
|
|
|
@task
|
|
def serve_dev(c, otel=False):
|
|
if otel:
|
|
c.run(
|
|
"FLASK_APP=./learn_otel/app.py OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true "
|
|
"opentelemetry-instrument --traces_exporter console --metrics_exporter console --logs_exporter console "
|
|
"--service_name dice-server flask run -p 8888"
|
|
)
|
|
else:
|
|
c.run("FLASK_APP=./learn_otel/app.py flask run -p 8888")
|