44import asyncio
55from gitpod import Gitpod
66import gitpod .lib as util
7+ from gitpod .types .environment_spec_param import EnvironmentSpecParam
78
8- # Example: ./examples/run_service.py https://github.com/gitpod-io/empty
9+ # Examples:
10+ # - ./examples/run_service.py
11+ # - ./examples/run_service.py https://github.com/gitpod-io/empty
912async def main () -> None :
1013 client = Gitpod ()
1114
12- if len (sys .argv ) < 2 :
13- print ("Usage: ./examples/run_service.py <CONTEXT_URL>" )
14- sys .exit (1 )
15- context_url = sys .argv [1 ]
15+ context_url = sys .argv [1 ] if len (sys .argv ) > 1 else None
1616
1717 env_class = util .find_most_used_environment_class (client )
1818 if not env_class :
@@ -21,27 +21,25 @@ async def main() -> None:
2121
2222 port = 8888
2323
24- environment_id = client .environments .create (
25- spec = {
26- "desired_phase" : "ENVIRONMENT_PHASE_RUNNING" ,
27- "content" : {
28- "initializer" : {"specs" : [{
29- "contextUrl" : {
30- "url" : context_url
31- }
32- }]}
33- },
34- "machine" : {"class" : env_class .id },
35- "ports" : [
36- {
37- "name" : "Lama Service" ,
38- "port" : port ,
39- "admission" : "ADMISSION_LEVEL_EVERYONE"
24+ spec : EnvironmentSpecParam = {
25+ "desired_phase" : "ENVIRONMENT_PHASE_RUNNING" ,
26+ "machine" : {"class" : env_class .id },
27+ "ports" : [{
28+ "name" : "Lama Service" ,
29+ "port" : port ,
30+ "admission" : "ADMISSION_LEVEL_EVERYONE"
31+ }]
32+ }
33+ if context_url :
34+ spec ["content" ] = {
35+ "initializer" : {"specs" : [{
36+ "contextUrl" : {
37+ "url" : context_url
4038 }
41- ]
42- }
43- ).environment .id
39+ }]}
40+ }
4441
42+ environment_id = client .environments .create (spec = spec ).environment .id
4543 try :
4644 util .wait_for_environment_ready (client , environment_id )
4745
0 commit comments