Skip to content

Commit 41943a8

Browse files
committed
refactor: use tilt to patch debugpy port into k8s/local
1 parent 2235bbe commit 41943a8

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

template/Tiltfile

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ print(
99

1010
load("ext://syncback", "syncback")
1111

12+
# Check for --debugpy argument
13+
config.define_bool("debugpy", False, "Enable debugpy debugging support")
14+
cfg = config.parse()
15+
enable_debugpy = cfg.get("debugpy", False)
16+
1217
docker_build(
1318
"backend",
1419
context="backend",
@@ -29,9 +34,46 @@ docker_build(
2934
)
3035
{% endif %}
3136

32-
k8s_yaml(
33-
kustomize("./k8s/local/")
34-
)
37+
def patch_debugpy_support(k8s_objects):
38+
"""Patch the backend deployment to add debugpy support"""
39+
return blob(
40+
str(k8s_objects) +
41+
"""
42+
---
43+
apiVersion: v1
44+
kind: Service
45+
metadata:
46+
name: backend
47+
spec:
48+
ports:
49+
- port: 5678
50+
targetPort: 5678
51+
name: debug
52+
---
53+
apiVersion: apps/v1
54+
kind: Deployment
55+
metadata:
56+
name: backend
57+
spec:
58+
template:
59+
spec:
60+
containers:
61+
- name: backend
62+
command: ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678", "manage.py", "runserver", "0.0.0.0:8000"]
63+
ports:
64+
- name: debug
65+
containerPort: 5678
66+
"""
67+
)
68+
69+
# Load base kubernetes configuration
70+
k8s_objects = kustomize("./k8s/local/")
71+
72+
# Apply debugpy patches if enabled
73+
if enable_debugpy:
74+
k8s_objects = patch_debugpy_support(k8s_objects)
75+
76+
k8s_yaml(k8s_objects)
3577

3678
syncback(
3779
"backend-sync",
@@ -55,7 +97,8 @@ syncback(
5597
{% if copier__create_nextjs_frontend %}
5698
k8s_resource(workload='frontend', port_forwards=3000)
5799
{% endif %}
58-
k8s_resource(workload='backend', port_forwards=5678)
100+
if enable_debugpy:
101+
k8s_resource(workload='backend', port_forwards=5678)
59102
k8s_resource(workload='backend', port_forwards=8000)
60103
k8s_resource(workload='mailhog', port_forwards=8025)
61104
k8s_resource(workload='postgres', port_forwards=5432)

template/k8s/base/django.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ spec:
1212
- port: 8000
1313
targetPort: http-server
1414
name: wsgi
15-
- port: 5678
16-
targetPort: 5678
17-
name: debug
1815
---
1916
apiVersion: apps/v1
2017
kind: Deployment
@@ -37,12 +34,9 @@ spec:
3734
- name: backend
3835
image: backend:latest
3936
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
40-
# command: ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678", "manage.py", "runserver", "0.0.0.0:8000"]
4137
ports:
4238
- name: http-server
4339
containerPort: 8000
44-
- name: debug
45-
containerPort: 5678
4640
envFrom:
4741
- configMapRef:
4842
name: app-config

0 commit comments

Comments
 (0)