import os from invoke import task SPEECH_COLLECT_RESPOSITORY = os.environ.get("SPEECH_COLLECT_RESPOSITORY", "registry.runcible.io/speech-collect") SPEECH_COLLECT_HELM_CHART_DIR = "./charts/speech-collect" @task def serve(c): """Serves the speech-collect application locally.""" c.run("LITESTAR_APP=speech_collect.app:app litestar run --port 8888 --host 0.0.0.0 --reload") @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 build_image(c, dev=True): """Builds the speech-collect container image.""" context_dir = c.run("pwd", hide=True).stdout.strip() commit_sha = c.run("git rev-parse --short HEAD", hide=True).stdout.strip() c.run( f"docker build --build-arg='COMMIT_SHA={commit_sha}' -t speech-collect:{commit_sha}{'-dev' if dev else ''} {context_dir}" ) @task def delint(c): """Applies automated linters to project""" c.run("isort ./speech_collect ./tests ./tasks.py", pty=True) c.run("black ./speech_collect ./tests ./tasks.py", pty=True) @task def template_chart(c, values=None): """Templates the speech-collect Helm chart with an optional custom values.yaml""" cmd = f"helm template {SPEECH_COLLECT_HELM_CHART_DIR}" if values: cmd += f" --values {values}" c.run(cmd) @task def rebuild_chart(c): """Rebuilds the speech-collect helm chart""" c.run(f"ls {SPEECH_COLLECT_HELM_CHART_DIR}") c.run(f"rm -rf {SPEECH_COLLECT_HELM_CHART_DIR}/Chart.lock {SPEECH_COLLECT_HELM_CHART_DIR}/charts") # c.run(f"helm dependency update --respository-config .charts/repositories.yaml {SPEECH_COLLECT_HELM_CHART_DIR}") @task(pre=[rebuild_chart]) def package_chart(c, pre_release=None, destination="./build"): """Packages the speech-collect helm chart.""" # Helm requires a valid semantic version. # See https://semver.org chart_version = c.run( f"helm show chart {SPEECH_COLLECT_HELM_CHART_DIR} | grep version | tail -1 | cut -d ':' -f2 | xargs" ).stdout.strip() if pre_release is not None: chart_version = chart_version + str(pre_release) c.run(f"helm package {SPEECH_COLLECT_HELM_CHART_DIR} --version {chart_version} --destination {destination}")