Skip to content

Commit 4d2bb7c

Browse files
committed
fix build image
1 parent 1bfc3ea commit 4d2bb7c

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

scripts/build-image.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99

1010
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']
1315
return {
1416
'idris': idris_latest_sha,
1517
'lsp': lsp_latest_sha
@@ -40,34 +42,34 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
4042
# for sha-specific devcontainer images, we also need to pass in the sha from the idris2 github repo
4143
# by default, this is the latest idris2 sha.
4244
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"]}',
4648
'--build-arg', f'IDRIS_VERSION={idris_base_version}',
47-
'.' ])
49+
'.'])
4850
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"]}', '.'])
5153
print(f'Image built with tag {tag}')
5254

5355

5456
if __name__ == '__main__':
5557
parser = argparse.ArgumentParser(description='Builds a docker image')
5658
parser.add_argument(
57-
'--image',
59+
'--image',
5860
help='The image to build. One of (base | debian | ubuntu | devcontainer). Defaults to base.',
5961
default='base')
6062
group = parser.add_mutually_exclusive_group()
6163
group.add_argument(
62-
'--version',
64+
'--version',
6365
help='Idris version to use. Defaults to `latest`, and of the form `v0.6.0`',
6466
default='latest')
6567
group.add_argument(
66-
'--sha',
68+
'--sha',
6769
help='Idris/Idris LSP SHA to use. Should not be used with `--version`. SHAs also cannot be used with base or debian images.',
6870
default=None)
6971
parser.add_argument(
70-
'--tag',
72+
'--tag',
7173
help='Tag to use for the image. Defaults to `{image}-{version}` or `{image}-{tag}.',
7274
default=None)
7375
parser.add_argument(
@@ -80,7 +82,7 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
8082
if args.image not in ['base', 'debian', 'ubuntu', 'devcontainer']:
8183
print('Invalid image. Must be one of (base | debian | ubuntu | devcontainer).')
8284
exit(1)
83-
85+
8486
if args.version and args.version != 'latest':
8587
# Build versioned image.
8688
dockerfile = f'{args.image}.Dockerfile'
@@ -90,18 +92,28 @@ def build_image_sha(image: str, sha_info: dict, idris_base_version: str, tag: st
9092
# build image
9193
if args.image == 'devcontainer':
9294
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+
'.'])
9799
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}', '.'])
99102
print(f'Image built with tag {tag}')
100103

101104
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}')
105117

106118
elif args.sha:
107119
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
117129

118130
else:
119131
print('This should never happen.')
120-
exit(1)
132+
exit(1)

0 commit comments

Comments
 (0)