xref: /aosp_15_r20/external/skia/infra/bots/assets/kubectl/create.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1#!/usr/bin/env python
2#
3# Copyright 2017 Google Inc.
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
12import argparse
13import requests
14import subprocess
15
16
17VERSION = 'v1.25.4'
18DOWNLOAD_URL = 'https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl' % VERSION
19SHA256_URL = 'https://dl.k8s.io/%s/bin/linux/amd64/kubectl.sha256' % VERSION
20
21
22def create_asset(target_dir):
23  """Create the asset."""
24  subprocess.check_call(['curl', '-LO', DOWNLOAD_URL], cwd=target_dir)
25  sha256 = requests.get(SHA256_URL).text
26  p = subprocess.Popen(
27      ['sha256sum', '--check'],
28      cwd=target_dir,
29      stdout=subprocess.PIPE,
30      stderr=subprocess.STDOUT,
31      stdin=subprocess.PIPE)
32  output = p.communicate(
33      input=(sha256 + ' kubectl').encode('utf-8'))[0].decode('utf-8')
34  if 'OK' not in output:
35    raise ValueError('Got wrong checksum for kubectl: %s' % output)
36  subprocess.check_call(['chmod', 'a+x', 'kubectl'], cwd=target_dir)
37
38
39def main():
40  parser = argparse.ArgumentParser()
41  parser.add_argument('--target_dir', '-t', required=True)
42  args = parser.parse_args()
43  create_asset(args.target_dir)
44
45
46if __name__ == '__main__':
47  main()
48
49