Files
lasuite-docs/bin/Tiltfile
T
Manuel Raynaud e9ba24e0c4 (helm) add a ServiceMonitor and a PodMonitor when metrics enabled
When metrics is enabled, we want to create a ServiceMonitor od
PodMonitor in order to scrap the metrics from django and yhub. We have
to add an exception on the redirect to ssl for the metrics endpoint,
like for the probes endpoint, the traffic is internal.
2026-09-22 16:04:23 +02:00

129 lines
5.2 KiB
Python

load('ext://uibutton', 'cmd_button', 'bool_input', 'location')
load('ext://namespace', 'namespace_create', 'namespace_inject')
namespace_create('impress')
docker_build(
'localhost:5001/impress-backend:latest',
context='..',
dockerfile='../Dockerfile',
only=['./src/backend', './src/mail', './docker'],
target = 'backend-production',
build_args={'DOCKER_USER': '1000:1000'},
live_update=[
sync('../src/backend', '/app'),
run(
'pip install -r /app/requirements.txt',
trigger=['./api/requirements.txt']
)
]
)
docker_build(
'localhost:5001/impress-y-provider:latest',
context='..',
dockerfile='../src/frontend/servers/y-provider/Dockerfile',
only=['./src/frontend/', './docker/', './.dockerignore'],
target = 'y-provider',
build_args={'DOCKER_USER': '1000:1000'},
live_update=[
sync('../src/frontend/servers/y-provider/src', '/home/frontend/servers/y-provider/src'),
]
)
docker_build(
'localhost:5001/impress-frontend:latest',
context='..',
dockerfile='../src/frontend/Dockerfile',
only=['./src/frontend', './docker', './.dockerignore'],
target = 'impress',
build_args={'DOCKER_USER': '1000:1000'},
live_update=[
sync('../src/frontend', '/home/frontend'),
]
)
docker_build(
'localhost:5001/impress-yhub:latest',
context='..',
dockerfile='../src/yhub-server/Dockerfile',
only=['./src/yhub-server', './docker', './.dockerignore'],
target = 'yhub',
build_args={'DOCKER_USER': '1000:1000'},
live_update=[
sync('../src/yhub-server', '/app'),
]
)
k8s_resource('impress-docs-backend-migrate', resource_deps=['dev-backend-postgres'])
k8s_resource('impress-docs-backend-createsuperuser', resource_deps=['impress-docs-backend-migrate'])
k8s_resource('impress-docs-yhub-init-db', resource_deps=['dev-backend-postgres', 'valkey-yhub'])
k8s_resource('dev-backend-keycloak', resource_deps=['dev-backend-keycloak-pg'])
k8s_resource('impress-docs-backend', resource_deps=['impress-docs-backend-migrate', 'valkey-docs', 'dev-backend-keycloak', 'dev-backend-postgres', 'dev-backend-minio:statefulset'])
k8s_resource('impress-docs-celery-worker', resource_deps=['valkey-docs'])
k8s_resource('impress-docs-yhub', resource_deps=['valkey-yhub'])
k8s_resource('impress-docs-yhub-worker', resource_deps=['valkey-yhub'])
# The Prometheus Operator carries the CRDs of its release, and the Prometheus
# it runs (a workload of its own kind, whose pods the operator creates). The
# ServiceMonitors of the application are a resource apart, applied once the
# operator is up: their kind does not exist before its CRDs do, and nothing of
# the application waits for them. The kind is a regular expression, matched
# anywhere in the name: anchored, or it takes the PrometheusRule too.
k8s_kind('^Prometheus$', pod_readiness='ignore')
k8s_resource('prometheus-operator', objects=[
'alertmanagerconfigs.monitoring.coreos.com:customresourcedefinition',
'alertmanagers.monitoring.coreos.com:customresourcedefinition',
'podmonitors.monitoring.coreos.com:customresourcedefinition',
'probes.monitoring.coreos.com:customresourcedefinition',
'prometheusagents.monitoring.coreos.com:customresourcedefinition',
'prometheuses.monitoring.coreos.com:customresourcedefinition',
'prometheusrules.monitoring.coreos.com:customresourcedefinition',
'scrapeconfigs.monitoring.coreos.com:customresourcedefinition',
'servicemonitors.monitoring.coreos.com:customresourcedefinition',
'thanosrulers.monitoring.coreos.com:customresourcedefinition',
])
k8s_resource('prometheus-prometheus', objects=[
'prometheus-prometheus:ingress',
# the example console of django-prometheus and the rules feeding it
'django-console:configmap',
'django:prometheusrule',
], resource_deps=['prometheus-operator'], links=[
'https://docs-prometheus.127.0.0.1.nip.io/targets',
'https://docs-prometheus.127.0.0.1.nip.io/consoles/django.html',
])
k8s_resource(new_name='impress-docs-monitors', objects=[
'impress-docs-backend:servicemonitor',
'impress-docs-yhub:servicemonitor',
'impress-docs-yhub-worker:servicemonitor',
], resource_deps=['prometheus-operator'])
# the valkey chart leaves its objects without a namespace, and the CRDs of the
# prometheus release only come with --include-crds
k8s_yaml(namespace_inject(local('cd ../src/helm && helmfile -n impress -e dev template --include-crds .'), 'impress'))
migration = '''
set -eu
# get k8s pod name from tilt resource name
POD_NAME="$(tilt get kubernetesdiscovery impress-backend -ojsonpath='{.status.pods[0].name}')"
kubectl -n impress exec "$POD_NAME" -- python manage.py makemigrations
'''
cmd_button('Make migration',
argv=['sh', '-c', migration],
resource='impress-backend',
icon_name='developer_board',
text='Run makemigration',
)
pod_migrate = '''
set -eu
# get k8s pod name from tilt resource name
POD_NAME="$(tilt get kubernetesdiscovery impress-backend -ojsonpath='{.status.pods[0].name}')"
kubectl -n impress exec "$POD_NAME" -- python manage.py migrate --no-input
'''
cmd_button('Migrate db',
argv=['sh', '-c', pod_migrate],
resource='impress-backend',
icon_name='developer_board',
text='Run database migration',
)