Added new python scripts

This commit is contained in:
Alexey Safronov 2023-10-18 18:07:33 +04:00
parent b2f2890fbc
commit 0075961d5a
3 changed files with 290 additions and 0 deletions

200
build.backend.docker.py Executable file
View File

@ -0,0 +1,200 @@
#!/usr/bin/python3
import os
import subprocess
import sys, getopt
import shutil
import netifaces as ni
def help():
# Display Help
print("Build and run backend and working environment. (Use 'yarn start' to run client -> https://github.com/ONLYOFFICE/DocSpace-client)")
print()
print("Syntax: available params [-h|f|s|c|d|]")
print("options:")
print("h Print this Help.")
print("f Force rebuild base images.")
print("s Run as SAAS otherwise as STANDALONE.")
print("c Run as COMMUNITY otherwise ENTERPRISE.")
print("d Run dnsmasq.")
print()
rd = os.path.dirname(os.path.abspath(__file__))
dir = os.path.abspath(os.path.join(rd, ".."))
dockerDir = os.path.join(dir, "buildtools", "install", "docker")
# local_ip = subprocess.check_output(["ipconfig", "getifaddr", "en0"], text=True)
local_ip = ni.ifaddresses('en0')[ni.AF_INET][0]['addr']
doceditor = local_ip + ":5013"
login = f"{local_ip}:5011"
client = f"{local_ip}:5001"
portal_url = f"http://{local_ip}"
force = False
dns = False
standalone = True
community = False
migration_type = "STANDALONE" # SAAS
installation_type = "ENTERPRISE"
document_server_image_name = "onlyoffice/documentserver-de:latest"
# Get the options
opts, args = getopt.getopt(sys.argv[1:], "hfscd")
for opt, arg in opts:
if opt == "-h":
help()
sys.exit()
elif opt == "-f":
force = arg if arg else True
elif opt == "-s":
standalone = arg if arg else False
elif opt == "-c":
community = arg if arg else True
elif opt == "-d":
dns = arg if arg else True
else:
print("Error: Invalid '-" + opt + "' option")
sys.exit()
print("Run script directory:", dir)
print("Root directory:", dir)
print("Docker files root directory:", dockerDir)
print()
print(f"SERVICE_DOCEDITOR: {doceditor}")
print(f"SERVICE_LOGIN: {login}")
print(f"SERVICE_CLIENT: {client}")
print(f"DOCSPACE_APP_URL: {portal_url}")
print()
print("FORCE REBUILD BASE IMAGES:", force)
print("Run dnsmasq:", dns)
if standalone == False:
migration_type = "SAAS"
if community == True:
installation_type = "COMMUNITY"
document_server_image_name = "onlyoffice/documentserver:latest"
print()
print("MIGRATION TYPE:", migration_type)
print("INSTALLATION TYPE:", installation_type)
print("DS image:", document_server_image_name)
print()
# Stop all backend services
subprocess.call([os.path.join(dir, "buildtools", "start", "stop.backend.docker.sh")])
print("Run MySQL")
arch_name = os.uname().machine
existsnetwork = subprocess.check_output(["docker", "network", "ls"]).decode("utf-8").splitlines()
existsnetwork = [line.split()[1] for line in existsnetwork]
if "onlyoffice" not in existsnetwork:
subprocess.call(["docker", "network", "create", "--driver", "bridge", "onlyoffice"])
if arch_name == "x86_64":
print("CPU Type: x86_64 -> run db.yml")
subprocess.call(["docker", "compose", "-f", os.path.join(dockerDir, "db.yml"), "up", "-d"])
elif arch_name == "arm64":
print("CPU Type: arm64 -> run db.yml with arm64v8 image")
os.environ["MYSQL_IMAGE"] = "arm64v8/mysql:8.0.32-oracle"
subprocess.call(["docker", "compose", "-f", os.path.join(dockerDir, "db.yml"), "up", "-d"])
else:
print("Error: Unknown CPU Type:", arch_name)
sys.exit(1)
if dns == True:
print("Run local dns server")
os.environ["ROOT_DIR"] = dir
subprocess.call(["docker", "compose", "-f", os.path.join(dockerDir, "dnsmasq.yml"), "up", "-d"])
print("Clear publish folder")
shutil.rmtree(os.path.join(dir, "publish/services"), True)
print("Build backend services (to 'publish/' folder)")
subprocess.call([os.path.join(dir, "buildtools", "install", "common", "build-services.py")])
def check_image(image_name):
return subprocess.check_output(f'docker images --format "{{.Repository}}:{{.Tag}}"', shell=True, text=True).__contains__(image_name)
dotnet_image_name = "onlyoffice/4testing-docspace-dotnet-runtime"
dotnet_version = "dev"
dotnet_image = f"{dotnet_image_name}:{dotnet_version}"
exists = check_image(dotnet_image)
if not exists or force == True:
print("Build dotnet base image from source (apply new dotnet config)")
subprocess.call(["docker", "build", "-t", dotnet_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "dotnetrun", "."])
else:
print(f"SKIP build {dotnet_image} (already exists)")
node_image_name = "onlyoffice/4testing-docspace-nodejs-runtime"
node_version = "dev"
node_image = f"{node_image_name}:{node_version}"
exists = check_image(node_image)
if not exists or force == True:
print("Build nodejs base image from source")
subprocess.call(["docker", "build", "-t", node_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "noderun", "."])
else:
print(f"SKIP build {node_image} (already exists)")
proxy_image_name = "onlyoffice/4testing-docspace-proxy-runtime"
proxy_version = "dev"
proxy_image = f"{proxy_image_name}:{proxy_version}"
exists = check_image(proxy_image)
if not exists or force == True:
print("Build proxy base image from source (apply new nginx config)")
subprocess.call(["docker", "build", "-t", proxy_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "router", "."])
else:
print(f"SKIP build {proxy_image} (already exists)")
print("Run migration and services")
os.environ["ENV_EXTENSION"] = "dev"
os.environ["INSTALLATION_TYPE"] = installation_type
os.environ["Baseimage_Dotnet_Run"] = "onlyoffice/4testing-docspace-dotnet-runtime:" + dotnet_version
os.environ["Baseimage_Nodejs_Run"] = "onlyoffice/4testing-docspace-nodejs-runtime:" + node_version
os.environ["Baseimage_Proxy_Run"] = "onlyoffice/4testing-docspace-proxy-runtime:" + proxy_version
os.environ["DOCUMENT_SERVER_IMAGE_NAME"] = document_server_image_name
os.environ["SERVICE_DOCEDITOR"] = doceditor
os.environ["SERVICE_LOGIN"] = login
os.environ["SERVICE_CLIENT"] = client
os.environ["ROOT_DIR"] = dir
os.environ["BUILD_PATH"] = "/var/www"
os.environ["SRC_PATH"] = os.path.join(dir, "publish/services")
os.environ["DATA_DIR"] = os.path.join(dir, "data")
os.environ["APP_URL_PORTAL"] = portal_url
os.environ["MIGRATION_TYPE"] = migration_type
subprocess.call(["docker-compose", "-f", os.path.join(dockerDir, "docspace.profiles.yml"), "-f", os.path.join(dockerDir, "docspace.overcome.yml"), "--profile", "migration-runner", "--profile", "backend-local", "up", "-d"])
print()
print("Run script directory:", dir)
print("Root directory:", dir)
print("Docker files root directory:", dockerDir)
print()
print(f"SERVICE_DOCEDITOR: {doceditor}")
print(f"SERVICE_LOGIN: {login}")
print(f"SERVICE_CLIENT: {client}")
print(f"DOCSPACE_APP_URL: {portal_url}")
print()
print("FORCE REBUILD BASE IMAGES:", force)
print("Run dnsmasq:", dns)
print()
print("MIGRATION TYPE:", migration_type)
print("INSTALLATION TYPE:", installation_type)
print("DS image:", document_server_image_name)
print()

View File

@ -0,0 +1,68 @@
#!/usr/bin/python3
import os
import stat
import subprocess
import shutil
SRC_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
BUILD_PATH = os.path.join(SRC_PATH, "publish")
print(f"SRC_PATH = {SRC_PATH}")
print(f"BUILD_PATH = {BUILD_PATH}")
BACKEND_NODEJS_SERVICES = ["ASC.Socket.IO", "ASC.SsoAuth"]
BACKEND_DOTNETCORE_SERVICES = ["ASC.Files", "ASC.People", "ASC.Data.Backup", "ASC.Files.Service", "ASC.Notify", "ASC.Studio.Notify", "ASC.Web.Api", "ASC.Web.Studio", "ASC.Data.Backup.BackgroundTasks", "ASC.ClearEvents", "ASC.ApiSystem", "ASC.Web.HealthChecks.UI"]
SELF_CONTAINED = "false"
PUBLISH_CNF = "Debug"
FRONTEND_BUILD_ARGS = "build"
FRONTEND_DEPLOY_ARGS = "deploy"
DEBUG_INFO_CHECK = ""
MIGRATION_CHECK = "true"
DOCKER_ENTRYPOINT="docker-entrypoint.py"
DOCKER_ENTRYPOINT_PATH = os.path.join(SRC_PATH, "buildtools", "install", "docker", DOCKER_ENTRYPOINT)
if os.path.exists(os.path.join(BUILD_PATH, "services")):
print("== Clean up services ==")
shutil.rmtree(os.path.join(BUILD_PATH, "services"))
print("== Build ASC.Web.slnf ==")
subprocess.run(["dotnet", "build", os.path.join(SRC_PATH, "server", "ASC.Web.slnf")])
print("== Build ASC.Migrations.sln ==")
subprocess.run(["dotnet", "build", os.path.join(SRC_PATH, "server", "ASC.Migrations.sln"), "-o", os.path.join(BUILD_PATH, "services", "ASC.Migration.Runner", "service")])
print("== Add docker-migration-entrypoint.sh to ASC.Migration.Runner ==")
file_path = os.path.join(BUILD_PATH, "services", "ASC.Migration.Runner", "service", "docker-migration-entrypoint.sh")
with open(os.path.join(SRC_PATH, "buildtools", "install", "docker", "docker-migration-entrypoint.sh"), "r") as file:
content = file.read().replace("\r", "")
with open(file_path, "w") as new_file:
new_file.write(content)
st = os.stat(file_path)
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
for service in BACKEND_NODEJS_SERVICES:
print(f"== Build {service} project ==")
src = os.path.join(SRC_PATH, "server", "common", service)
subprocess.run(["yarn", "install", "--cwd", src])
dst = os.path.join(BUILD_PATH, "services", service, "service")
if not os.path.exists(dst):
os.makedirs(dst, exist_ok=True)
print(f"== Copy service data to {dst}")
shutil.copytree(src, dst, dirs_exist_ok=True)
print(f"== Add docker-entrypoint.py to {service}")
shutil.copyfile(DOCKER_ENTRYPOINT_PATH, os.path.join(dst, DOCKER_ENTRYPOINT))
print("== Publish ASC.Web.slnf ==")
subprocess.run(["dotnet", "publish", os.path.join(SRC_PATH, "server", "ASC.Web.slnf"), "-p", "PublishProfile=FolderProfile"])
for service in BACKEND_DOTNETCORE_SERVICES:
print(f"== Add {DOCKER_ENTRYPOINT} to {service}")
dst = os.path.join(BUILD_PATH, "services", service, "service")
shutil.copyfile(DOCKER_ENTRYPOINT_PATH, os.path.join(dst, DOCKER_ENTRYPOINT))

22
requirements.txt Normal file
View File

@ -0,0 +1,22 @@
aiohttp==3.8.4
aiosignal==1.3.1
APScheduler==3.6.3
async-timeout==4.0.2
attrs==23.1.0
cachetools==4.2.2
certifi==2023.5.7
charset-normalizer==3.2.0
frozenlist==1.3.3
idna==3.4
multidict==6.0.4
netifaces==0.11.0
openai==0.27.8
python-telegram-bot==13.6
pytz==2023.3
requests==2.31.0
six==1.16.0
tornado==6.3.2
tqdm==4.65.0
tzlocal==5.0.1
urllib3==2.0.3
yarl==1.9.2