From 959b530248af8d9e9b31785977b607db8445535e Mon Sep 17 00:00:00 2001 From: Ahmed Bilal Khalid Date: Wed, 28 Aug 2019 12:13:05 +0500 Subject: [PATCH] a --- .vscode/settings.json | 3 +++ app/api.py | 20 ++++++++++++++------ app/helper.py | 28 +++++++++++++++++++++++++++- init.sh | 12 ++++++++++-- 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..714f513 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/home/meow/.local/share/virtualenvs/ucloud-setup-20frMi5h/bin/python" +} \ No newline at end of file diff --git a/app/api.py b/app/api.py index 4dd06c1..3a60f05 100644 --- a/app/api.py +++ b/app/api.py @@ -3,7 +3,9 @@ import subprocess import os from app.helper import clone, clone_common,\ - clone_etcd_wrapper, GitOperation, PipenvOperation, FileOperation + clone_etcd_wrapper, GitOperation,\ + PipenvOperation, FileOperation,\ + PackageManagementOperation @click.group() def api(): @@ -22,7 +24,12 @@ def setup(path, auth_name, auth_seed, auth_realm, realm_allowed, otp_server): os.chdir(path) - op_result = GitOperation.clone("https://code.ungleich.ch/ungleich-public/ucloud-api.git") + + # Install Package + op = PackageManagementOperation.install("asdnioasndisa") + + # Git Operation Depends on success of previous operation i.e PackageManagementOperation + op.add(GitOperation.clone("https://code.ungleich.ch/ungleich-public/ucloud-api.git")) content = f"AUTH_NAME={auth_name}\n" \ f"AUTH_SEED={auth_seed}\n" \ @@ -30,14 +37,15 @@ def setup(path, auth_name, auth_seed, auth_realm, f"REALM_ALLOWED={list(realm_allowed)}\n" \ f"OTP_SERVER={otp_server}\n" - op_result.add(FileOperation.write, + # FileOperation depends on success of previos operation i.e GitOperation.clone + op.add(FileOperation.write, path=os.path.join("ucloud-api", ".env"), content=content) - op_result.add(GitOperation.clone, path="ucloud-api", + op.add(GitOperation.clone, path="ucloud-api", url="https://code.ungleich.ch/ungleich-public/ucloud_common") - op_result.add(GitOperation.clone, path="ucloud-api", + op.add(GitOperation.clone, path="ucloud-api", url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper") - op_result.add(PipenvOperation.install, path="ucloud-api") \ No newline at end of file + op.add(PipenvOperation.install, path="ucloud-api") diff --git a/app/helper.py b/app/helper.py index a45fc02..449c3c3 100644 --- a/app/helper.py +++ b/app/helper.py @@ -87,4 +87,30 @@ class FileOperation(object): return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name) else: return Result("", ResultType.success) - \ No newline at end of file + + +def get_distro_name(): + distro_name = None + with open("/etc/os-release") as f: + content = f.read() + start = content.find("ID=") + 3 + end = content.find("\n", start) + distro_name = content[start:end] + return distro_name + +class PackageManagementOperation(object): + @staticmethod + def install(package_name): + try: + distro = get_distro_name() + if distro == "alpine": + command = f"apk add {package_name}" + else: + assert "Unknown Distro" + + subprocess.check_output(distro) + except Exception as e: + print(e) + return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name) + else: + return Result("", ResultType.success) diff --git a/init.sh b/init.sh index 21532b8..b0d207b 100644 --- a/init.sh +++ b/init.sh @@ -1,10 +1,18 @@ -# Require Alpine 3.10 +# Enable Alpine Edge Repos +cat > /etc/apk/repositories << END \ +http://dl-cdn.alpinelinux.org/alpine/edge/main +http://dl-cdn.alpinelinux.org/alpine/edge/community +http://dl-cdn.alpinelinux.org/alpine/edge/testing +END -sed -i 's/v3.9/v3.10/g' /etc/apk/repositories +# Update Package List and Upgrade System apk update apk upgrade + +# Install system packages apk add python3 gcc g++ python3-dev + pip3 install --upgrade pip pip3 install pipenv pipenv install