From 2b3e8cec9e76393c2f2fd56b74423797dd728583 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 27 Dec 2023 12:55:22 +0500 Subject: [PATCH 1/4] n8n container --- plogical/DockerSites.py | 50 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index fce28e9e5..732b0afb4 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -578,42 +578,36 @@ volumes: services: '{self.data['ServiceName']}-db': - image: postgres:11 + image: docker.io/bitnami/postgresql:16 restart: always environment: - - POSTGRES_USER:"root" - - POSTGRES_PASSWORD:"{self.data['MySQLPassword']}" - - POSTGRES_DB:"{self.data['MySQLDBName']}" - - POSTGRES_NON_ROOT_USER:"{self.data['MySQLDBNUser']}" - - POSTGRES_NON_ROOT_PASSWORD:"{self.data['MySQLPassword']}" +# - POSTGRES_USER:root + - POSTGRESQL_USERNAME={self.data['MySQLPassword']} + - POSTGRESQL_DATABASE={self.data['MySQLDBName']} + - POSTGRESQL_POSTGRES_PASSWORD={self.data['MySQLDBNUser']} + - POSTGRESQL_PASSWORD={self.data['MySQLPassword']} volumes: - - "/home/docker/{self.data['finalURL']}/db:/var/lib/postgresql/data" - healthcheck: - test: ['CMD-SHELL', 'pg_isready -h localhost -U "{self.data['MySQLDBNUser']}" -d "{self.data['MySQLDBName']}"'] - interval: 5s - timeout: 5s - retries: 10 +# - "/home/docker/{self.data['finalURL']}/db:/var/lib/postgresql/data" + - "/home/docker/{self.data['finalURL']}/db:/bitnami/postgresql" '{self.data['ServiceName']}': image: docker.n8n.io/n8nio/n8n restart: always environment: - DB_TYPE=postgresdb - - DB_POSTGRESDB_HOST='{self.data['ServiceName']}-db' + - DB_POSTGRESDB_HOST={self.data['ServiceName']}-db - DB_POSTGRESDB_PORT=5432 - - DB_POSTGRESDB_DATABASE="{self.data['MySQLDBName']}" - - DB_POSTGRESDB_USER="{self.data['MySQLDBNUser']}" - - DB_POSTGRESDB_PASSWORD="{self.data['MySQLPassword']}" + - DB_POSTGRESDB_DATABASE={self.data['MySQLDBName']} + - DB_POSTGRESDB_USER={self.data['MySQLDBNUser']} + - DB_POSTGRESDB_PASSWORD={self.data['MySQLPassword']} ports: - "{self.data['port']}:5678" links: - - postgres + - {self.data['ServiceName']}-db volumes: - - n8n_storage:/home/node/.n8n - "/home/docker/{self.data['finalURL']}/data:/home/node/.n8n" depends_on: - postgres: - condition: service_healthy + - '{self.data['ServiceName']}-db' ''' ### WriteConfig to compose-file @@ -666,13 +660,13 @@ services: execPath = execPath + f" SetupHTAccess --port {self.data['port']} --htaccess {self.data['htaccessPath']}" ProcessUtilities.executioner(execPath, self.data['externalApp']) - if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - group = 'nobody' - else: - group = 'nogroup' - - command = f"chown -R nobody:{group} /home/docker/{self.data['finalURL']}/data" - ProcessUtilities.executioner(command) + # if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + # group = 'nobody' + # else: + # group = 'nogroup' + # + # command = f"chown -R nobody:{group} /home/docker/{self.data['finalURL']}/data" + # ProcessUtilities.executioner(command) ### just restart ls for htaccess @@ -734,7 +728,7 @@ def Main(): "docRoot": "/home/docker.cyberpanel.net" } ds = Docker_Sites('', data) - ds.DeployWPContainer() + ds.DeployN8NContainer() elif args.function == 'DeleteDockerApp': data = { From 6834668688844055c63d16d9768dffba02d81d7b Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 27 Dec 2023 13:04:30 +0500 Subject: [PATCH 2/4] default cpu to 2 --- websiteFunctions/website.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index be1810ef9..252701c01 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -6660,7 +6660,7 @@ StrictHostKeyChecking no if PackageAssignment.objects.all().count() == 0: name = 'Default' - cpu = 1 + cpu = 2 Memory = 1024 Bandwidth = '100' disk = '100' From 28322543bfaf2eb891d9e2ae9ef0cace8c79e545 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 27 Dec 2023 17:41:04 +0500 Subject: [PATCH 3/4] n8n container --- plogical/DockerSites.py | 18 +++++++++++++----- .../websiteFunctions/CreateDockerSite.html | 3 ++- websiteFunctions/website.py | 19 ++----------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index 732b0afb4..0fd816b88 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -37,6 +37,8 @@ class Docker_Sites(multi.Thread): self.DeployWPContainer() elif self.function_run == 'SubmitDockersiteCreation': self.SubmitDockersiteCreation() + elif self.function_run == 'DeployN8NContainer': + self.DeployN8NContainer() except BaseException as msg: @@ -399,8 +401,12 @@ services: ) dockersiteobj.save() - background = Docker_Sites('DeployWPContainer', f_data) - background.start() + if self.data['App'] == 'WordPress': + background = Docker_Sites('DeployWPContainer', f_data) + background.start() + elif self.data['App'] == 'n8n': + background = Docker_Sites('DeployN8NContainer', f_data) + background.start() except BaseException as msg: logging.writeToFile("Error Submit Docker site Creation ....... %s" % str(msg)) @@ -579,12 +585,13 @@ volumes: services: '{self.data['ServiceName']}-db': image: docker.io/bitnami/postgresql:16 + user: root restart: always environment: # - POSTGRES_USER:root - - POSTGRESQL_USERNAME={self.data['MySQLPassword']} + - POSTGRESQL_USERNAME={self.data['MySQLDBNUser']} - POSTGRESQL_DATABASE={self.data['MySQLDBName']} - - POSTGRESQL_POSTGRES_PASSWORD={self.data['MySQLDBNUser']} + - POSTGRESQL_POSTGRES_PASSWORD={self.data['MySQLPassword']} - POSTGRESQL_PASSWORD={self.data['MySQLPassword']} volumes: # - "/home/docker/{self.data['finalURL']}/db:/var/lib/postgresql/data" @@ -592,6 +599,7 @@ services: '{self.data['ServiceName']}': image: docker.n8n.io/n8nio/n8n + user: root restart: always environment: - DB_TYPE=postgresdb @@ -704,7 +712,7 @@ def Main(): # port, SitePath, CPUsSite, MemorySite, SiteName # finalURL, blogTitle, adminUser, adminPassword, adminEmail, htaccessPath, externalApp data = { - "JobID": '/home/cyberpanel/error-logs.txt', + "JobID": '/home/cyberpanel/hey.txt', "ComposePath": "/home/docker.cyberpanel.net/docker-compose.yml", "MySQLPath": '/home/docker.cyberpanel.net/public_html/sqldocker', "MySQLRootPass": 'testdbwp12345', diff --git a/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html b/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html index e897c9879..e9fe979c7 100644 --- a/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html +++ b/websiteFunctions/templates/websiteFunctions/CreateDockerSite.html @@ -169,7 +169,8 @@
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 252701c01..440f0a331 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -6863,23 +6863,7 @@ StrictHostKeyChecking no data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Blacklisted domain."} json_data = json.dumps(data_ret) return HttpResponse(json_data) - # extraArgs = {} - # extraArgs['admin'] = admin - # extraArgs['domainName'] = data['domain'] - # extraArgs['home'] = data['home'] - # extraArgs['shopName'] = data['shopName'] - # extraArgs['firstName'] = data['firstName'] - # extraArgs['lastName'] = data['lastName'] - # extraArgs['databasePrefix'] = data['databasePrefix'] - # extraArgs['email'] = data['email'] - # extraArgs['password'] = data['passwordByPass'] - # extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) - # - # if data['home'] == '0': - # extraArgs['path'] = data['path'] - # - # background = ApplicationInstaller('prestashop', extraArgs) - # background.start() + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) data = {} @@ -6896,6 +6880,7 @@ StrictHostKeyChecking no data['WPusername'] = WPusername data['WPpasswd'] = WPpasswd data['externalApp'] = "".join(re.findall("[a-zA-Z]+", Domain))[:5] + str(randint(1000, 9999)) + data['App'] = App background = Docker_Sites('SubmitDockersiteCreation', data) background.start() From d901b59b648e6b1131deaa0ba496df7a9e81ad1c Mon Sep 17 00:00:00 2001 From: usmannasir Date: Wed, 27 Dec 2023 18:41:53 +0500 Subject: [PATCH 4/4] some docker functions --- dockerManager/container.py | 53 +++++++++++++++++++++++++++++++++++++- plogical/DockerSites.py | 32 +++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/dockerManager/container.py b/dockerManager/container.py index 71ddacc26..b03feeda7 100755 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -1175,7 +1175,6 @@ class ContainerManager(multi.Thread): if admin.acl.adminStatus != 1: return ACLManager.loadError() - name = data['name'] WPusername = data['WPusername'] WPemail = data['WPemail'] @@ -1207,6 +1206,58 @@ class ContainerManager(multi.Thread): json_data = json.dumps(data_ret) return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def RestartContainerAPP(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + name = data['name'] + containerID = data['id'] + + passdata = {} + passdata['containerID'] = containerID + + da = Docker_Sites(None, passdata) + retdata = da.RestartContainer() + + + data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def StopContainerAPP(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + + if admin.acl.adminStatus != 1: + return ACLManager.loadError() + + name = data['name'] + containerID = data['id'] + + passdata = {} + passdata['containerID'] = containerID + + da = Docker_Sites(None, passdata) + retdata = da.StopContainer() + + + data_ret = {'status': 1, 'error_message': 'None', 'data':retdata} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: data_ret = {'removeImageStatus': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index 0fd816b88..2e4106184 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -555,6 +555,38 @@ services: self.DeleteDockerApp() self.SubmitDockersiteCreation() + def RestartContainer(self): + try: + import docker + # Create a Docker client + client = docker.from_env() + + # Get the container by ID + container = client.containers.get(self.data['containerID']) + + container.restart() + + return 1, None + except BaseException as msg: + logging.writeToFile("List Container ....... %s" % str(msg)) + return 0, str(msg) + + def StopContainer(self): + try: + import docker + # Create a Docker client + client = docker.from_env() + + # Get the container by ID + container = client.containers.get(self.data['containerID']) + + container.stop() + + return 1, None + except BaseException as msg: + logging.writeToFile("List Container ....... %s" % str(msg)) + return 0, str(msg) + ##### N8N Container def DeployN8NContainer(self):