99
1010load ("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+
1217docker_build (
1318 "backend" ,
1419 context = "backend" ,
@@ -29,9 +34,37 @@ docker_build(
2934)
3035{% endif % }
3136
32- k8s_yaml (
33- kustomize ("./k8s/local/" )
34- )
37+ # Load base kubernetes configuration
38+ k8s_yaml_raw = kustomize ("./k8s/local/" )
39+
40+ # Apply debugpy patches if enabled
41+ if enable_debugpy :
42+ objects = decode_yaml_stream (str (k8s_yaml_raw ))
43+ for o in objects :
44+ # Patch backend Service to add debug port
45+ if o ['kind' ] == 'Service' and o ['metadata' ]['name' ] == 'backend' :
46+ if 'ports' not in o ['spec' ]:
47+ o ['spec' ]['ports' ] = []
48+ o ['spec' ]['ports' ].append ({
49+ 'port' : 5678 ,
50+ 'targetPort' : 5678 ,
51+ 'name' : 'debug'
52+ })
53+
54+ # Patch backend Deployment to add debugpy command and port
55+ if o ['kind' ] == 'Deployment' and o ['metadata' ]['name' ] == 'backend' :
56+ container = o ['spec' ]['template' ]['spec' ]['containers' ][0 ]
57+ container ['command' ] = ["python" , "-m" , "debugpy" , "--listen" , "0.0.0.0:5678" , "manage.py" , "runserver" , "0.0.0.0:8000" ]
58+ if 'ports' not in container :
59+ container ['ports' ] = []
60+ container ['ports' ].append ({
61+ 'name' : 'debug' ,
62+ 'containerPort' : 5678
63+ })
64+
65+ k8s_yaml (encode_yaml_stream (objects ))
66+ else :
67+ k8s_yaml (k8s_yaml_raw )
3568
3669syncback (
3770 "backend-sync" ,
@@ -55,7 +88,8 @@ syncback(
5588{% if copier__create_nextjs_frontend % }
5689k8s_resource (workload = 'frontend' , port_forwards = 3000 )
5790{% endif % }
58- k8s_resource (workload = 'backend' , port_forwards = 5678 )
91+ if enable_debugpy :
92+ k8s_resource (workload = 'backend' , port_forwards = 5678 )
5993k8s_resource (workload = 'backend' , port_forwards = 8000 )
6094k8s_resource (workload = 'mailhog' , port_forwards = 8025 )
6195k8s_resource (workload = 'postgres' , port_forwards = 5432 )
0 commit comments