From d5374fc4e2e376ee6d876552eed9cd52d3887b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20T=C3=B9ng=20L=C3=A2m=20=28Linus=29?= Date: Tue, 12 Oct 2021 10:53:50 +0700 Subject: [PATCH] Download cloudflared binary from github release instead of equinox (#8) * Download cloudflared binary from github release instead of equinox * Minor typo fixed * Bump colab_ssh version to 0.1.6 * Make the downloaded binary executable --- colab_ssh/tunel.py | 12 ++++-------- colab_ssh/utils.py | 12 ++++++++++-- setup.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/colab_ssh/tunel.py b/colab_ssh/tunel.py index cb60a14..4822f28 100644 --- a/colab_ssh/tunel.py +++ b/colab_ssh/tunel.py @@ -1,11 +1,10 @@ """Config Argo tunnel for the SSH tunnel""" -import shutil import subprocess import time import urllib from typing import Tuple -from colab_ssh.utils import download_file +from colab_ssh.utils import download_file, make_executable def config_argo_tunnel(msg: str) -> Tuple[str, str, str, str]: @@ -21,13 +20,10 @@ def config_argo_tunnel(msg: str) -> Tuple[str, str, str, str]: ssh_config (str): The SSH config block for Mattermost push notification hostname (str): The hostname of the server, also for Mattermost push notification """ + download_file( - "https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.tgz", "cloudflared.tgz") - try: - shutil.unpack_archive("cloudflared.tgz") - except OSError: # pragma: no cover - print("Seems like we already had cloudflared binary") - pass + "https://github.com/cloudflare/cloudflared/releases/download/2021.9.2/cloudflared-linux-amd64", "cloudflared") + make_executable("cloudflared") subprocess.run(["./cloudflared", "update"]) cfd_proc = subprocess.Popen( ["./cloudflared", "tunnel", "--url", "ssh://localhost:22", diff --git a/colab_ssh/utils.py b/colab_ssh/utils.py index cf911ca..fb9ebad 100644 --- a/colab_ssh/utils.py +++ b/colab_ssh/utils.py @@ -32,19 +32,26 @@ def download_file(url: str, path: str): raise +def make_executable(path): + mode = os.stat(path).st_mode + mode |= (mode & 0o444) >> 2 # copy R bits to X + os.chmod(path, mode) + + def get_gpu_name(): """ Get current GPU name """ try: process = subprocess.run(["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], - stdout=subprocess.PIPE, universal_newlines=True, check=False) + stdout=subprocess.PIPE, universal_newlines=True, check=False) if process.returncode != 0: # pragma: no cover return None return process.stdout.strip() # pragma: no cover except FileNotFoundError: return None + def check_gpu_available(): """ Check if any GPU is available @@ -90,7 +97,8 @@ def get_instance_info() -> Dict[str, str]: } """ try: - gpu_info = subprocess.run(['nvidia-smi'], stdout=subprocess.PIPE, check=False) + gpu_info = subprocess.run( + ['nvidia-smi'], stdout=subprocess.PIPE, check=False) gpu_info = gpu_info.stdout.decode("utf-8") # pragma: no cover except FileNotFoundError: gpu_info = 'failed' diff --git a/setup.py b/setup.py index 8bc48b0..02151e3 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import find_packages, setup -__version__ = "0.1.5" +__version__ = "0.1.6" def read_me():