Debian Codegraph @

infra/bots/assets/kubeval/create.py

raw
1 #!/usr/bin/env python3
2 #
3 # Copyright 2024 Google LLC
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Create the asset."""
10
11
12 import argparse
13 import os
14 import subprocess
15 import tempfile
16
17 URL = 'https://github.com/instrumenta/kubeval/releases/download/v0.16.1/kubeval-linux-amd64.tar.gz'
18 SHA256 = '2d6f9bda1423b93787fa05d9e8dfce2fc1190fefbcd9d0936b9635f3f78ba790'
19
20 BINARY = URL.split('/')[-1]
21
22
23 def create_asset(target_dir):
24 """Create the asset."""
25 tmp = tempfile.mkdtemp()
26 target_file = os.path.join(tmp, 'kubeval.tar.gz')
27 subprocess.call(['wget', '--quiet', '--output-document', target_file, URL])
28 output = subprocess.check_output(['sha256sum', target_file], encoding='utf-8')
29 actual_hash = output.split(' ')[0]
30 if actual_hash != SHA256:
31 raise Exception('SHA256 does not match (%s != %s)' % (actual_hash, SHA256))
32 subprocess.check_call(
33 ['tar', 'xf', os.path.join(tmp, 'kubeval.tar.gz'), 'kubeval'],
34 cwd=target_dir)
35 subprocess.check_call(['rm', '-rf', tmp])
36
37
38 def main():
39 parser = argparse.ArgumentParser()
40 parser.add_argument('--target_dir', '-t', required=True)
41 args = parser.parse_args()
42 create_asset(args.target_dir)
43
44
45 if __name__ == '__main__':
46 main()
47