a
This commit is contained in:
parent
0a521eac33
commit
959b530248
4 changed files with 54 additions and 9 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "/home/meow/.local/share/virtualenvs/ucloud-setup-20frMi5h/bin/python"
|
||||||
|
}
|
20
app/api.py
20
app/api.py
|
@ -3,7 +3,9 @@ import subprocess
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from app.helper import clone, clone_common,\
|
from app.helper import clone, clone_common,\
|
||||||
clone_etcd_wrapper, GitOperation, PipenvOperation, FileOperation
|
clone_etcd_wrapper, GitOperation,\
|
||||||
|
PipenvOperation, FileOperation,\
|
||||||
|
PackageManagementOperation
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def api():
|
def api():
|
||||||
|
@ -22,7 +24,12 @@ def setup(path, auth_name, auth_seed, auth_realm,
|
||||||
realm_allowed, otp_server):
|
realm_allowed, otp_server):
|
||||||
os.chdir(path)
|
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" \
|
content = f"AUTH_NAME={auth_name}\n" \
|
||||||
f"AUTH_SEED={auth_seed}\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"REALM_ALLOWED={list(realm_allowed)}\n" \
|
||||||
f"OTP_SERVER={otp_server}\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"),
|
path=os.path.join("ucloud-api", ".env"),
|
||||||
content=content)
|
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")
|
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")
|
url="https://code.ungleich.ch/ahmedbilal/etcd3_wrapper")
|
||||||
|
|
||||||
op_result.add(PipenvOperation.install, path="ucloud-api")
|
op.add(PipenvOperation.install, path="ucloud-api")
|
||||||
|
|
|
@ -87,4 +87,30 @@ class FileOperation(object):
|
||||||
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
|
return Result(e, ResultType.failure, inspect.currentframe().f_code.co_name)
|
||||||
else:
|
else:
|
||||||
return Result("", ResultType.success)
|
return Result("", ResultType.success)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
12
init.sh
12
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 update
|
||||||
apk upgrade
|
apk upgrade
|
||||||
|
|
||||||
|
# Install system packages
|
||||||
apk add python3 gcc g++ python3-dev
|
apk add python3 gcc g++ python3-dev
|
||||||
|
|
||||||
pip3 install --upgrade pip
|
pip3 install --upgrade pip
|
||||||
pip3 install pipenv
|
pip3 install pipenv
|
||||||
pipenv install
|
pipenv install
|
||||||
|
|
Loading…
Add table
Reference in a new issue