2023-10-18 14:07:33 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
2023-10-19 08:08:35 +00:00
|
|
|
import socket
|
2023-10-18 14:07:33 +00:00
|
|
|
import subprocess
|
|
|
|
import sys, getopt
|
|
|
|
import shutil
|
2023-10-19 10:07:50 +00:00
|
|
|
import platform
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
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")
|
2023-10-19 08:08:35 +00:00
|
|
|
local_ip = socket.gethostbyname_ex(socket.gethostname())[-1][-1]
|
2023-10-18 14:07:33 +00:00
|
|
|
|
2023-10-19 13:27:43 +00:00
|
|
|
doceditor = f"{local_ip}:5013"
|
2023-10-18 14:07:33 +00:00
|
|
|
login = f"{local_ip}:5011"
|
|
|
|
client = f"{local_ip}:5001"
|
2023-11-21 10:22:45 +00:00
|
|
|
management = f"{local_ip}:5015"
|
2023-10-18 14:07:33 +00:00
|
|
|
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
|
2023-11-02 15:11:21 +00:00
|
|
|
subprocess.run(["python", os.path.join(dir, "buildtools", "start", "stop.backend.docker.py")])
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
print("Run MySQL")
|
|
|
|
|
2023-10-19 10:07:50 +00:00
|
|
|
arch_name = platform.uname().machine
|
|
|
|
|
|
|
|
print(f"PLATFORM {arch_name}")
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
existsnetwork = subprocess.check_output(["docker", "network", "ls"]).decode("utf-8").splitlines()
|
|
|
|
existsnetwork = [line.split()[1] for line in existsnetwork]
|
|
|
|
|
|
|
|
if "onlyoffice" not in existsnetwork:
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "network", "create", "--driver", "bridge", "onlyoffice"])
|
2023-10-18 14:07:33 +00:00
|
|
|
|
2023-11-02 15:11:21 +00:00
|
|
|
if arch_name == "x86_64" or arch_name == "AMD64":
|
2023-10-18 14:07:33 +00:00
|
|
|
print("CPU Type: x86_64 -> run db.yml")
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "compose", "-f", os.path.join(dockerDir, "db.yml"), "up", "-d"])
|
2023-10-18 14:07:33 +00:00
|
|
|
elif arch_name == "arm64":
|
|
|
|
print("CPU Type: arm64 -> run db.yml with arm64v8 image")
|
2024-03-18 15:26:56 +00:00
|
|
|
os.environ["MYSQL_IMAGE"] = "arm64v8/mysql:8.3.0-oracle"
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "compose", "-f", os.path.join(dockerDir, "db.yml"), "up", "-d"])
|
2023-10-18 14:07:33 +00:00
|
|
|
else:
|
|
|
|
print("Error: Unknown CPU Type:", arch_name)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if dns == True:
|
|
|
|
print("Run local dns server")
|
|
|
|
os.environ["ROOT_DIR"] = dir
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "compose", "-f", os.path.join(dockerDir, "dnsmasq.yml"), "up", "-d"])
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
print("Clear publish folder")
|
|
|
|
shutil.rmtree(os.path.join(dir, "publish/services"), True)
|
|
|
|
|
|
|
|
print("Build backend services (to 'publish/' folder)")
|
2023-11-02 15:11:21 +00:00
|
|
|
subprocess.run(["python", os.path.join(dir, "buildtools", "install", "common", "build-services.py")])
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
def check_image(image_name):
|
2023-11-02 15:11:21 +00:00
|
|
|
return subprocess.check_output(["docker", "images", "--format", "'{{.Repository}}:{{.Tag}}'"], shell=True, text=True).__contains__(image_name)
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
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)")
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "build", "-t", dotnet_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "dotnetrun", "."])
|
2023-10-18 14:07:33 +00:00
|
|
|
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")
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "build", "-t", node_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "noderun", "."])
|
2023-10-18 14:07:33 +00:00
|
|
|
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)")
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["docker", "build", "-t", proxy_image, "-f", os.path.join(dockerDir, "Dockerfile.runtime"), "--target", "router", "."])
|
2023-10-18 14:07:33 +00:00
|
|
|
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
|
2023-11-09 14:00:55 +00:00
|
|
|
os.environ["SERVICE_MANAGEMENT"] = management
|
2023-10-18 14:07:33 +00:00
|
|
|
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
|
2023-10-19 13:27:43 +00:00
|
|
|
subprocess.run(["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"])
|
2023-10-18 14:07:33 +00:00
|
|
|
|
|
|
|
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}")
|
2023-11-09 14:00:55 +00:00
|
|
|
print(f"SERVICE_MANAGEMENT: {management}")
|
2023-10-18 14:07:33 +00:00
|
|
|
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()
|