8
8
9
9
10
10
def get_latest_sha ():
11
- idris_latest_sha = requests .get ('https://api.github.com/repos/idris-lang/Idris2/commits' ).json ()[0 ]['sha' ]
12
- lsp_latest_sha = requests .get ('https://api.github.com/repos/idris-community/idris2-lsp/commits' ).json ()[0 ]['sha' ]
11
+ idris_latest_sha = requests .get (
12
+ 'https://api.github.com/repos/idris-lang/Idris2/commits' ).json ()[0 ]['sha' ]
13
+ lsp_latest_sha = requests .get (
14
+ 'https://api.github.com/repos/idris-community/idris2-lsp/commits' ).json ()[0 ]['sha' ]
13
15
return {
14
16
'idris' : idris_latest_sha ,
15
17
'lsp' : lsp_latest_sha
@@ -40,34 +42,34 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
40
42
# for sha-specific devcontainer images, we also need to pass in the sha from the idris2 github repo
41
43
# by default, this is the latest idris2 sha.
42
44
idris_sha = sha_info ['idris' ] if idris_base_version == 'latest' else idris_base_version
43
- subprocess .run ([ 'docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
44
- '--build-arg' , f'IDRIS_SHA={ idris_sha } ' ,
45
- '--build-arg' , f'IDRIS_LSP_SHA={ sha_info ["lsp" ]} ' ,
45
+ subprocess .run (['docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
46
+ '--build-arg' , f'IDRIS_SHA={ idris_sha } ' ,
47
+ '--build-arg' , f'IDRIS_LSP_SHA={ sha_info ["lsp" ]} ' ,
46
48
'--build-arg' , f'IDRIS_VERSION={ idris_base_version } ' ,
47
- '.' ])
49
+ '.' ])
48
50
else :
49
- subprocess .run ([ 'docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
50
- '--build-arg' , f'IDRIS_SHA={ sha_info ["idris" ]} ' , '.' ])
51
+ subprocess .run (['docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
52
+ '--build-arg' , f'IDRIS_SHA={ sha_info ["idris" ]} ' , '.' ])
51
53
print (f'Image built with tag { tag } ' )
52
54
53
55
54
56
if __name__ == '__main__' :
55
57
parser = argparse .ArgumentParser (description = 'Builds a docker image' )
56
58
parser .add_argument (
57
- '--image' ,
59
+ '--image' ,
58
60
help = 'The image to build. One of (base | debian | ubuntu | devcontainer). Defaults to base.' ,
59
61
default = 'base' )
60
62
group = parser .add_mutually_exclusive_group ()
61
63
group .add_argument (
62
- '--version' ,
64
+ '--version' ,
63
65
help = 'Idris version to use. Defaults to `latest`, and of the form `v0.6.0`' ,
64
66
default = 'latest' )
65
67
group .add_argument (
66
- '--sha' ,
68
+ '--sha' ,
67
69
help = 'Idris/Idris LSP SHA to use. Should not be used with `--version`. SHAs also cannot be used with base or debian images.' ,
68
70
default = None )
69
71
parser .add_argument (
70
- '--tag' ,
72
+ '--tag' ,
71
73
help = 'Tag to use for the image. Defaults to `{image}-{version}` or `{image}-{tag}.' ,
72
74
default = None )
73
75
parser .add_argument (
@@ -80,7 +82,7 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
80
82
if args .image not in ['base' , 'debian' , 'ubuntu' , 'devcontainer' ]:
81
83
print ('Invalid image. Must be one of (base | debian | ubuntu | devcontainer).' )
82
84
exit (1 )
83
-
85
+
84
86
if args .version and args .version != 'latest' :
85
87
# Build versioned image.
86
88
dockerfile = f'{ args .image } .Dockerfile'
@@ -90,18 +92,28 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
90
92
# build image
91
93
if args .image == 'devcontainer' :
92
94
lsp_version = get_lsp_version (args .version )
93
- subprocess .run ([ 'docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
94
- '--build-arg' , f'IDRIS_VERSION={ args .version } ' ,
95
- '--build-arg' , f'IDRIS_LSP_VERSION={ lsp_version } ' ,
96
- '.' ])
95
+ subprocess .run (['docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
96
+ '--build-arg' , f'IDRIS_VERSION={ args .version } ' ,
97
+ '--build-arg' , f'IDRIS_LSP_VERSION={ lsp_version } ' ,
98
+ '.' ])
97
99
else :
98
- subprocess .run ([ 'docker' , 'build' , '-t' , tag , '-f' , dockerfile , '--build-arg' , f'IDRIS_VERSION={ args .version } ' , '.' ])
100
+ subprocess .run (['docker' , 'build' , '-t' , tag , '-f' , dockerfile ,
101
+ '--build-arg' , f'IDRIS_VERSION={ args .version } ' , '.' ])
99
102
print (f'Image built with tag { tag } ' )
100
103
101
104
elif args .version == 'latest' :
102
- sha_info = get_latest_sha ()
103
- tag = f'{ args .image } -latest' if not args .tag else args .tag
104
- build_image_sha (args .image , sha_info , args .idris_base_version , tag )
105
+ if args .image in ['base' , 'devcontainer' ]:
106
+ # base and devcontainer need idris' latest SHA to build
107
+ sha_info = get_latest_sha ()
108
+ tag = f'{ args .image } -latest' if not args .tag else args .tag
109
+ build_image_sha (args .image , sha_info , args .idris_base_version , tag )
110
+
111
+ else :
112
+ tag = f'{ args .image } -latest' if not args .tag else args .tag
113
+ print (f'Building { args .image } .Dockerfile with tag { tag } ' )
114
+ subprocess .run (['docker' , 'build' , '-t' , tag , '-f' ,
115
+ f'{ args .image } .Dockerfile' , '.' ])
116
+ print (f'Image built with tag { tag } ' )
105
117
106
118
elif args .sha :
107
119
if args .image in ['base' , 'debian' ]:
@@ -117,4 +129,4 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
117
129
118
130
else :
119
131
print ('This should never happen.' )
120
- exit (1 )
132
+ exit (1 )
0 commit comments