mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-16 02:06:13 +01:00
n8n container deployment improvement
This commit is contained in:
@@ -782,36 +782,14 @@ services:
|
|||||||
|
|
||||||
def setup_n8n_data_directory(self):
|
def setup_n8n_data_directory(self):
|
||||||
"""Helper method to create and set up n8n data directory with proper permissions"""
|
"""Helper method to create and set up n8n data directory with proper permissions"""
|
||||||
# Create all required n8n directories
|
# Create base n8n data directory
|
||||||
base_dir = f"/home/docker/{self.data['finalURL']}/n8n_data"
|
base_dir = f"/home/docker/{self.data['finalURL']}/n8n_data"
|
||||||
required_dirs = [
|
command = f"mkdir -p {base_dir}"
|
||||||
f"{base_dir}",
|
|
||||||
f"{base_dir}/.n8n",
|
|
||||||
f"{base_dir}/.n8n/.n8n", # Additional nested directory required by n8n
|
|
||||||
f"{base_dir}/.n8n/data",
|
|
||||||
f"{base_dir}/.n8n/config"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Create directories
|
|
||||||
for directory in required_dirs:
|
|
||||||
command = f"mkdir -p {directory}"
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
# Set proper ownership for n8n data directory and all subdirectories
|
|
||||||
command = f"chown -R 1000:1000 {base_dir}"
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
# Set proper permissions
|
|
||||||
# 755 for directories to allow n8n to read/write/execute
|
|
||||||
command = f"find {base_dir} -type d -exec chmod 755 {{}} \\;"
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
# 644 for files to allow n8n to read/write
|
|
||||||
command = f"find {base_dir} -type f -exec chmod 644 {{}} \\;"
|
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
# Generate encryption key
|
# Generate encryption key
|
||||||
encryption_key = f"auto_generated_key_{randomPassword.generate_pass(32)}"
|
encryption_key = f"auto_generated_key_{randomPassword.generate_pass(32)}"
|
||||||
|
self.data['N8N_ENCRYPTION_KEY'] = encryption_key
|
||||||
|
|
||||||
# Create n8n config with the encryption key
|
# Create n8n config with the encryption key
|
||||||
config_content = {
|
config_content = {
|
||||||
@@ -819,9 +797,15 @@ services:
|
|||||||
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
||||||
"nodes": {},
|
"nodes": {},
|
||||||
"credentials": {},
|
"credentials": {},
|
||||||
"settings": {},
|
"settings": {
|
||||||
|
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
||||||
|
"tunnelSubdomain": None,
|
||||||
|
"deployment": "default"
|
||||||
|
},
|
||||||
"versionNotifications": {
|
"versionNotifications": {
|
||||||
"enabled": False
|
"enabled": False,
|
||||||
|
"endpoint": "https://api.n8n.io/api/v1/versions/notifications.json",
|
||||||
|
"infoUrl": "https://docs.n8n.io/reference/release-notes.html"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,19 +814,47 @@ services:
|
|||||||
with open(temp_config, 'w') as f:
|
with open(temp_config, 'w') as f:
|
||||||
json.dump(config_content, f, indent=2)
|
json.dump(config_content, f, indent=2)
|
||||||
|
|
||||||
# Move config to final location with proper permissions
|
# Create necessary directories with proper permissions
|
||||||
config_file = f"{base_dir}/.n8n/config/config.json"
|
required_dirs = [
|
||||||
|
f"{base_dir}/.n8n",
|
||||||
|
f"{base_dir}/.n8n/config"
|
||||||
|
]
|
||||||
|
|
||||||
|
for directory in required_dirs:
|
||||||
|
command = f"mkdir -p {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Move config to final location
|
||||||
|
config_file = f"{base_dir}/.n8n/config/config"
|
||||||
command = f"mv {temp_config} {config_file}"
|
command = f"mv {temp_config} {config_file}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
command = f"chown 1000:1000 {config_file}"
|
# Set ownership recursively
|
||||||
|
command = f"chown -R 1000:1000 {base_dir}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
command = f"chmod 644 {config_file}"
|
# Set directory permissions
|
||||||
|
command = f"find {base_dir} -type d -exec chmod 755 {{}} \\;"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
# Store encryption key for use in container environment
|
# Set file permissions
|
||||||
self.data['N8N_ENCRYPTION_KEY'] = encryption_key
|
command = f"find {base_dir} -type f -exec chmod 644 {{}} \\;"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Create empty directories that n8n expects
|
||||||
|
additional_dirs = [
|
||||||
|
f"{base_dir}/.n8n/database",
|
||||||
|
f"{base_dir}/.n8n/workflows",
|
||||||
|
f"{base_dir}/.n8n/credentials"
|
||||||
|
]
|
||||||
|
|
||||||
|
for directory in additional_dirs:
|
||||||
|
command = f"mkdir -p {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
command = f"chown 1000:1000 {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
command = f"chmod 755 {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
def DeployN8NContainer(self):
|
def DeployN8NContainer(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user