diff --git a/app/api.py b/app/api.py index f719018..0b1281c 100644 --- a/app/api.py +++ b/app/api.py @@ -53,7 +53,7 @@ def setup(path, auth_name, auth_seed, auth_realm, dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"), ) - install_available(os.path.join(repo_name, "Pipfile")) + install_available(repo_name) # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv','--site-packages', '--python', '3'], cwd=repo_name) diff --git a/app/file.py b/app/file.py index e46ecbd..4d7177c 100644 --- a/app/file.py +++ b/app/file.py @@ -35,7 +35,7 @@ def setup(path, base_dir, file_prefix, etcd_url): # Clone etcd wrapper clone_etcd_wrapper(path=repo_name) - install_available(os.path.join(repo_name, "Pipfile")) + install_available(repo_name) # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv','--site-packages', '--python', '3'], cwd=repo_name) diff --git a/app/helper.py b/app/helper.py index b413ae5..4612d19 100644 --- a/app/helper.py +++ b/app/helper.py @@ -2,10 +2,11 @@ import subprocess as sp import subprocess as sp import requests import json +import os from decouple import config -def install_available(pipfile): +# def install_available(pipfile): """ Install Python packages or their dependencies mentioned in pipfile if they are available in System repos """ @@ -55,6 +56,20 @@ def install_available(pipfile): except: print(f"Could not install {package}") +def install_available(project_path): + if get_distro_name() == "alpine": + sp.check_output(['pipenv', 'lock']) + + with open(os.path.join(project_path, "Pipfile.lock")) as f: + content = json.load(f) + + for package in content["default"].keys(): + try: + sp.check_output(["apk", "add", f"py3-{package}"]) + except Exception: + pass + + def clone_common(path='.'): sp.check_output(['git', 'clone', f'https://code.ungleich.ch/ungleich-public/ucloud_common'], cwd=path) diff --git a/app/host.py b/app/host.py index 7a0553f..718ecd4 100644 --- a/app/host.py +++ b/app/host.py @@ -49,7 +49,7 @@ def setup(path, ssh_username, ssh_key_path, ssh_key_pass, etcd_url, without_ceph dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"), ) - install_available(os.path.join(repo_name, "Pipfile")) + install_available(repo_name) # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv','--site-packages', '--python', '3'], cwd=repo_name) diff --git a/app/image.py b/app/image.py index f504659..de1ff16 100644 --- a/app/image.py +++ b/app/image.py @@ -35,7 +35,7 @@ def setup(path, base_dir, etcd_url, without_ceph): clone_etcd_wrapper(path=repo_name) - install_available(os.path.join(repo_name, "Pipfile")) + install_available(repo_name) # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv','--site-packages', '--python', '3'], cwd=repo_name) diff --git a/app/scheduler.py b/app/scheduler.py index ec61a7a..94f2e97 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -47,7 +47,7 @@ def setup(path, vm_prefix, host_prefix, request_prefix, etcd_url): dst=os.path.join(repo_name, "ucloud_common", "etcd3_wrapper"), ) - install_available(os.path.join(repo_name, "Pipfile")) + install_available(repo_name) # Create virtualenv with site-packages enabled and install all dependencies sp.check_output(['pipenv','--site-packages', '--python', '3'], cwd=repo_name) diff --git a/test.py b/test.py new file mode 100644 index 0000000..df6d3f7 --- /dev/null +++ b/test.py @@ -0,0 +1,7 @@ +import json +import os + +with open(os.path.expanduser("~/Desktop/code/ucloud-vm/Pipfile.lock")) as f: + # content = f.read() + content = json.load(f) +print(content["default"].keys()) \ No newline at end of file