diff --git a/cli/Notes.md b/cli/Notes.md index e3922121..b6b1ca4e 100644 --- a/cli/Notes.md +++ b/cli/Notes.md @@ -11,4 +11,8 @@ 用户同步 stackhub 上已经存放的清单,而不是通过 API 获取。原因: 1. 避免API使用需要授权或超时 -2. 避免未发布的应用被安装 \ No newline at end of file +2. 避免未发布的应用被安装 + +#### 如何获取所有已占用的端口号? + +基于 psutil 模块打印所有端口信息,然后匹配关键词 \ No newline at end of file diff --git a/cli/__pycache__/controller.cpython-36.pyc b/cli/__pycache__/controller.cpython-36.pyc index e4777edd..1ebb91a8 100644 Binary files a/cli/__pycache__/controller.cpython-36.pyc and b/cli/__pycache__/controller.cpython-36.pyc differ diff --git a/cli/__pycache__/model.cpython-36.pyc b/cli/__pycache__/model.cpython-36.pyc index c7402bc5..94ae1bef 100644 Binary files a/cli/__pycache__/model.cpython-36.pyc and b/cli/__pycache__/model.cpython-36.pyc differ diff --git a/cli/controller.py b/cli/controller.py index 681ccf5d..819d6c86 100644 --- a/cli/controller.py +++ b/cli/controller.py @@ -1,4 +1,5 @@ -import model, os +import model, os, sys, subprocess +from model import GitOp path_repo = "./data/application.list" path_project = "" @@ -29,14 +30,27 @@ class Create: self.folder = self.app_name def downRepo(self): + '''download repository''' + cmd = "git clone --depth=1 " + model.SmoothUrl.res(github_url) + "/websoft9/docker-" + self.app_name + " " + self.folder if os.path.exists("./"+self.folder): print(os.path.abspath(self.folder)+" folder already exists") + sys.exit(0) else: - os.system(cmd) + GitOp.gitClone(cmd) + + def setEnv(self): + '''set the usable port for application''' + + pass def upRepo(self): + '''docker-compose up repository''' + cmd = "docker-compose -f docker-compose-production.yml --env-file .env_all up -d" print(cmd) os.chdir(self.folder) - os.system(cmd) \ No newline at end of file + os.system(cmd) + + def printResult(self): + pass \ No newline at end of file diff --git a/cli/drupal2 b/cli/drupal2 deleted file mode 160000 index 8531fd12..00000000 --- a/cli/drupal2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8531fd12cacfb9881de3c270f2b81e17b20f5a99 diff --git a/cli/install.sh b/cli/install.sh index 24dc8c31..b664d85f 100644 --- a/cli/install.sh +++ b/cli/install.sh @@ -1 +1 @@ -yum install git pwgen jq wget curl figlet boxes -y \ No newline at end of file +yum install git wget figlet boxes -y \ No newline at end of file diff --git a/cli/joomla b/cli/joomla new file mode 160000 index 00000000..93735135 --- /dev/null +++ b/cli/joomla @@ -0,0 +1 @@ +Subproject commit 93735135cf4529fc7830446bb6604f7c15daae2f diff --git a/cli/model.py b/cli/model.py index 36c3ab25..1063373d 100644 --- a/cli/model.py +++ b/cli/model.py @@ -1,12 +1,12 @@ -import os, io, sys, platform, shutil, urllib3, json, time, subprocess, pprint +import os, io, sys, platform, psutil, json, secrets, string from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union -import urllib.parse import urllib.request + class SmoothUrl: - ''' get url ''' + ''' Get the best smooth url for Git or Download''' def __init__(self): pass @@ -14,28 +14,31 @@ class SmoothUrl: def res(url_list: Tuple): for item in url_list: - req = urllib.request.Request(item) try: urllib.request.urlopen(item,timeout=3).read() + print("Smooth URL is: " + item) return item - except urllib.error.URLError as e: - print(e.reason) + except: continue - return None + print("Necessary resource URL can not reachable, system exit!") + sys.exit(0) + - -class Github: - '''Github operation''' +class GitOp: + '''Git operation''' def __init__(self): pass - def gitClone(): - pass - - - + def gitClone(cmd: str): + '''git clone''' + try: + print("Command is: "+cmd) + os.system(cmd) + except: + print("Git clone failed, try again and check your URL can be accessed") + sys.exit(0) class FileOp: '''File operation''' @@ -45,4 +48,55 @@ class FileOp: def printJson(path: str): with open(path,newline='') as file: - print(file.read()) \ No newline at end of file + print(file.read()) + + def convertToJson(path: str): + pass + + +class NetOp: + '''Network and port manage''' + + def __init__(self): + pass + + def checkPort(self, port: int): + '''check the target port's status''' + search_key = "port="+str(port) + if str(psutil.net_connections()).find(search_key) != -1: + print(str(port)+" is used") + return False + else: + print(str(port)+" is free") + return True + + def setPort(self, port: int): + '''set usable port''' + while self.checkPort(port) == False: + port=port+1 + + print(port) + return port + +class SecurityOp: + '''Password and security operation''' + + def __int__(self): + pass + + def randomPass(self, length: Optional[int] = 16): + '''set password''' + + alphabet = string.ascii_letters + string.digits + while True: + password = ''.join(secrets.choice(alphabet) for i in range(length)) + if (any(c.islower() for c in password) + and any(c.isupper() for c in password) + and sum(c.isdigit() for c in password) >= 3): + break + print(password) + + +test=SecurityOp() +#test.setPort(9001) +test.randomPass(25) \ No newline at end of file diff --git a/cli/requirements.txt b/cli/requirements.txt index 7379290e..14fedd0b 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -1 +1,3 @@ -typer \ No newline at end of file +typer +psutil +jq \ No newline at end of file diff --git a/cli/stackhub.py b/cli/stackhub.py index 0a9bab23..a7a002dc 100644 --- a/cli/stackhub.py +++ b/cli/stackhub.py @@ -19,6 +19,13 @@ def create(app_name: str, project_name: Optional[str] = None): create = controller.Create(app_name, project_name) create.downRepo() create.upRepo() + create.setEnv() + create.printResult() + +@app.command() +def start(app_name: str, project_name: Optional[str] = None): + '''start one application''' + pass @app.command() def update(name: str): diff --git a/cli/test.py b/cli/test.py index e69de29b..6c4e5795 100644 --- a/cli/test.py +++ b/cli/test.py @@ -0,0 +1,4 @@ +import json + +with open("./joomla/.env_all","r") as file: + jsonData = json.dump(file, tempfile) \ No newline at end of file diff --git a/cli/version b/cli/version new file mode 100644 index 00000000..fcd84483 --- /dev/null +++ b/cli/version @@ -0,0 +1,2 @@ +stable: 1.3 +compatible: 1.23 \ No newline at end of file