def download_kustomize(version): now = datetime.datetime.utcnow() now = now.replace(microsecond=0) scratch_dir = os.path.join( e2e.workspace_dir(), "kustomize-scratch-" + now.strftime("%Y%m%d%H%M%s")) # We build up symlinks to the downloaded binaries in the bin directory bin_dir = os.path.join(scratch_dir, "bin") os.makedirs(bin_dir, exist_ok=True) url = "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v{version}/kustomize_v{version}_linux_amd64.tar.gz".format( version=version) downloads.exec(["curl", "-LJO", url], cwd=scratch_dir) tarfile = os.path.join( scratch_dir, "kustomize_v{version}_linux_amd64.tar.gz".format(version=version)) expanded = downloads.expand_tar(tarfile) kustomize_path = os.path.join(bin_dir, "kustomize") os.symlink(os.path.join(expanded, "kustomize"), kustomize_path) downloads.exec(["chmod", "+x", kustomize_path]) return Kustomize(kustomize_path)
def download_from_gcs(self, url, dest): mirror = os.environ.get("GCS_TRUSTED_MIRROR") if mirror: print("using GCS_TRUSTED_MIRROR %s" % (mirror)) if not mirror.endswith("/"): mirror += "/" url = mirror + url.replace("gs://", "gs/") args = ["cp", url, dest] return downloads.exec([self.gsutil] + args, env=self.env).strip()
def download_kpt(version, gcloud=None, statedir=None): now = datetime.datetime.utcnow() now = now.replace(microsecond=0) scratch_dir = os.path.join(e2e.workspace_dir(), "kpt-scratch-" + now.strftime("%Y%m%d%H%M%s")) # We build up symlinks to the downloaded binaries in the bin directory bin_dir = os.path.join(scratch_dir, "bin") os.makedirs(bin_dir, exist_ok=True) url = "gs://kpt-dev/releases/v{version}/linux_amd64/kpt_linux_amd64-v{version}.tar.gz".format( version=version) tarfile = os.path.join(scratch_dir, "kpt.tar.gz") gcloud.download_from_gcs(url, tarfile) expanded = downloads.expand_tar(tarfile) kpt_path = os.path.join(bin_dir, "kpt") os.symlink(os.path.join(expanded, "kpt"), kpt_path) downloads.exec(["chmod", "+x", kpt_path]) return Kpt(kpt_path, statedir=statedir)
def download_anthoscli(version, gcloud=None): now = datetime.datetime.utcnow() now = now.replace(microsecond=0) scratch_dir = os.path.join( e2e.workspace_dir(), "anthoscli-scratch-" + now.strftime("%Y%m%d%H%M%s") ) # We build up symlinks to the downloaded binaries in the bin directory bin_dir = os.path.join(scratch_dir, "bin") os.makedirs(bin_dir, exist_ok=True) url = "gs://gke-on-prem-staging/anthos-cli/v{version}-gke.0/anthoscli_linux_amd64-{version}.tar.gz".format(version=version) tarfile = os.path.join(scratch_dir, "anthoscli.tar.gz") gcloud.download_from_gcs(url, tarfile) expanded = downloads.expand_tar(tarfile) anthoscli_path = os.path.join(bin_dir, "anthoscli") os.symlink(os.path.join(expanded, "anthoscli"), anthoscli_path) downloads.exec(["chmod", "+x", anthoscli_path]) return AnthosCLI(anthoscli_path)
def __init__(self, user_email, user_name, env=None): if env is None: env = os.environ.copy() self.bin = "git" self.env = env downloads.exec(["chmod", "600", "/root/.ssh/id_rsa"]) downloads.exec(["git", "config", "--global", "user.email", user_email]) downloads.exec(["git", "config", "--global", "user.name", user_name])
def download_kubectl(k8s_version): now = datetime.datetime.utcnow() now = now.replace(microsecond=0) scratch_dir = os.path.join( e2e.workspace_dir(), "kubectl-scratch-" + now.strftime("%Y%m%d%H%M%s") ) # We build up symlinks to the downloaded binaries in the bin directory bin_dir = os.path.join(scratch_dir, "bin") os.makedirs(bin_dir, exist_ok=True) url = ( "https://storage.googleapis.com/kubernetes-release/release/" + k8s_version + "/bin/linux/amd64/kubectl" ) kubectl = downloads.download_hashed_url(url) downloads.exec(["chmod", "+x", kubectl]) kubectl_path = os.path.join(bin_dir, "kubectl") os.symlink(kubectl, kubectl_path) return Kubectl(kubectl_path)
def exec(self, args, dir=None): return downloads.exec([self.bin] + args, cwd=dir, env=self.env).strip()
def exec_and_parse_json(self, args): j = downloads.exec([self.bin, "--format", "json"] + args, cwd=self.statedir, env=self.env).strip() return json.loads(j)
def exec(self, args): return downloads.exec([self.bin] + args, cwd=self.statedir, env=self.env).strip()
def exec_and_parse_json(self, args): j = downloads.exec([self.bin, "-ojson"] + args, env=self.env).strip() return json.loads(j)
def clone(self, repo, directory): downloads.exec(["git", "clone", "--recursive", repo, directory]) self.statedir = directory
def __repr__(self): return "Git:" + downloads.exec(["which", "git"])