Skip to content

Commit

Permalink
Download cloudflared binary from github release instead of equinox (#8)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lamhoangtung committed Oct 12, 2021
1 parent 759a0ac commit d5374fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 4 additions & 8 deletions colab_ssh/tunel.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand All @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions colab_ssh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import find_packages, setup

__version__ = "0.1.5"
__version__ = "0.1.6"


def read_me():
Expand Down

0 comments on commit d5374fc

Please sign in to comment.