4
4
import asyncio
5
5
from gitpod import Gitpod
6
6
import gitpod .lib as util
7
+ from gitpod .types .environment_spec_param import EnvironmentSpecParam
7
8
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
9
12
async def main () -> None :
10
13
client = Gitpod ()
11
14
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
16
16
17
17
env_class = util .find_most_used_environment_class (client )
18
18
if not env_class :
@@ -21,27 +21,25 @@ async def main() -> None:
21
21
22
22
port = 8888
23
23
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
40
38
}
41
- ]
42
- }
43
- ).environment .id
39
+ }]}
40
+ }
44
41
42
+ environment_id = client .environments .create (spec = spec ).environment .id
45
43
try :
46
44
util .wait_for_environment_ready (client , environment_id )
47
45
0 commit comments