Skip to content

Commit

Permalink
several bug fixes to docker apps feature
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Oct 3, 2024
1 parent 13e51d7 commit d4df241
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 10 deletions.
1 change: 0 additions & 1 deletion dockerManager/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,6 @@ def getDockersiteList(self, userID=None, data=None):
da = Docker_Sites(None, passdata)
retdata = da.ListContainers()


data_ret = {'status': 1, 'error_message': 'None', 'data':retdata}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
Expand Down
7 changes: 7 additions & 0 deletions dockerManager/dockerInstall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/local/CyberCP/bin/python
import os
import sys
sys.path.append('/usr/local/CyberCP')
import plogical.CyberCPLogFileWriter as logging
Expand All @@ -20,6 +21,12 @@ def submitInstallDocker(CommandCP = 0):

if ProcessUtilities.decideDistro() == ProcessUtilities.cent8:

if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile(f'Docker installation started for cent8/9')

command = 'sudo yum install -y yum-utils'
ServerStatusUtil.executioner(command, statusFile)

command = 'yum install yum-utils -y'
ServerStatusUtil.executioner(command, statusFile)

Expand Down
1 change: 1 addition & 0 deletions dockerManager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def removeImage(request):
return coreResult
except KeyError:
return redirect(loadLoginPage)

@preDockerRun
def getDockersiteList(request):
import json
Expand Down
82 changes: 74 additions & 8 deletions plogical/DockerSites.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def __init__(self, function_run, data):
ProcessUtilities.executioner(execPath)




def run(self):
try:
if self.function_run == 'DeployWPContainer':
Expand Down Expand Up @@ -233,9 +231,16 @@ def DeployWPContainer(self):

command = 'docker --help'
result = ProcessUtilities.outputExecutioner(command)
print(f'return code of docker install {result}')

if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(f'return code of docker install {result}')

if result.find("not found") > -1:
DockerInstall.submitInstallDocker(1)
if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(f'About to run docker install function...')

execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py"
ProcessUtilities.executioner(execPath)

logging.statusWriter(self.JobID, 'Docker is ready to use..,10')

Expand Down Expand Up @@ -316,7 +321,12 @@ def DeployWPContainer(self):

####

command = f"docker-compose -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d"
if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos:
dockerCommand = 'docker compose'
else:
dockerCommand = 'docker-compose'

command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d"
result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1)

if os.path.exists(ProcessUtilities.debugPath):
Expand All @@ -330,6 +340,25 @@ def DeployWPContainer(self):

time.sleep(25)

### checking if everything ran properly

passdata = {}
passdata["JobID"] = None
passdata['name'] = self.data['ServiceName']
da = Docker_Sites(None, passdata)
retdata, containers = da.ListContainers()

containers = json.loads(containers)

if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(str(containers))

### it means less then two containers which means something went wrong
if len(containers) < 2:
logging.writeToFile(f'Unkonwn error, containers not running. [DeployWPContainer]')
logging.statusWriter(self.JobID, f'Unkonwn error, containers not running. [DeployWPContainer]')
return 0

### Set up Proxy

execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py"
Expand Down Expand Up @@ -572,6 +601,10 @@ def DeleteDockerApp(self):
command = f'docker rm {container.short_id}'
ProcessUtilities.executioner(command)


command = f"rm -rf /home/{self.data['domain']}/public_html/.htaccess'"
ProcessUtilities.executioner(command)

from plogical.installUtilities import installUtilities
installUtilities.reStartLiteSpeed()

Expand Down Expand Up @@ -718,9 +751,16 @@ def DeployN8NContainer(self):

command = 'docker --help'
result = ProcessUtilities.outputExecutioner(command)
print(f'return code of docker install {result}')

if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(f'return code of docker install {result}')

if result.find("not found") > -1:
DockerInstall.submitInstallDocker()
if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(f'About to run docker install function...')

execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/dockerManager/dockerInstall.py"
ProcessUtilities.executioner(execPath)

logging.statusWriter(self.JobID, 'Docker is ready to use..,10')

Expand Down Expand Up @@ -799,9 +839,15 @@ def DeployN8NContainer(self):

####

command = f"docker-compose -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d"
if ProcessUtilities.decideDistro() == ProcessUtilities.cent8 or ProcessUtilities.decideDistro() == ProcessUtilities.centos:
dockerCommand = 'docker compose'
else:
dockerCommand = 'docker-compose'

command = f"{dockerCommand} -f {self.data['ComposePath']} -p '{self.data['SiteName']}' up -d"
result, message = ProcessUtilities.outputExecutioner(command, None, None, None, 1)


if result == 0:
logging.statusWriter(self.JobID, f'Error {str(message)} . [404]')
return 0
Expand All @@ -810,6 +856,26 @@ def DeployN8NContainer(self):

time.sleep(25)


### checking if everything ran properly

passdata = {}
passdata["JobID"] = None
passdata['name'] = self.data['ServiceName']
da = Docker_Sites(None, passdata)
retdata, containers = da.ListContainers()

containers = json.loads(containers)

if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(str(containers))

### it means less then two containers which means something went wrong
if len(containers) < 2:
logging.writeToFile(f'Unkonwn error, containers not running. [DeployN8NContainer]')
logging.statusWriter(self.JobID, f'Unkonwn error, containers not running. [DeployN8NContainer]')
return 0

### Set up Proxy

execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/DockerSites.py"
Expand Down
3 changes: 3 additions & 0 deletions serverStatus/serverStatusUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def run(self):
@staticmethod
def executioner(command, statusFile):
try:
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile(command)

res = subprocess.call(command, stdout=statusFile, stderr=statusFile, shell=True)
if res == 1:
return 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ <h3 class="content-box-header">
<label class="col-sm-3 control-label">{% trans "Select App" %}</label>
<div class="col-sm-6">
<select ng-model="App" class="form-control">
<option>WordPress</option>
<option>n8n</option>
</select>
</div>
Expand Down

0 comments on commit d4df241

Please sign in to comment.