mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-14 01:06:09 +01:00
n8n container deployment improvement
This commit is contained in:
@@ -782,75 +782,94 @@ 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 base n8n data directory
|
try:
|
||||||
base_dir = f"/home/docker/{self.data['finalURL']}/n8n_data"
|
# Create base n8n data directory
|
||||||
command = f"mkdir -p {base_dir}"
|
base_dir = f"/home/docker/{self.data['finalURL']}/n8n_data"
|
||||||
ProcessUtilities.executioner(command)
|
command = f"mkdir -p {base_dir}"
|
||||||
|
|
||||||
# Generate encryption key
|
|
||||||
encryption_key = f"auto_generated_key_{randomPassword.generate_pass(32)}"
|
|
||||||
self.data['N8N_ENCRYPTION_KEY'] = encryption_key
|
|
||||||
|
|
||||||
# Create n8n config with the encryption key
|
|
||||||
config_content = {
|
|
||||||
"encryptionKey": encryption_key,
|
|
||||||
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
|
||||||
"nodes": {},
|
|
||||||
"credentials": {},
|
|
||||||
"settings": {
|
|
||||||
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
|
||||||
"tunnelSubdomain": None,
|
|
||||||
"deployment": "default"
|
|
||||||
},
|
|
||||||
"versionNotifications": {
|
|
||||||
"enabled": False,
|
|
||||||
"endpoint": "https://api.n8n.io/api/v1/versions/notifications.json",
|
|
||||||
"infoUrl": "https://docs.n8n.io/reference/release-notes.html"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create necessary directories
|
|
||||||
required_dirs = [
|
|
||||||
f"{base_dir}/.n8n",
|
|
||||||
f"{base_dir}/.n8n/database",
|
|
||||||
f"{base_dir}/.n8n/workflows",
|
|
||||||
f"{base_dir}/.n8n/credentials"
|
|
||||||
]
|
|
||||||
|
|
||||||
for directory in required_dirs:
|
|
||||||
command = f"mkdir -p {directory}"
|
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
# Write config directly to the config file
|
# Generate encryption key
|
||||||
config_file = f"{base_dir}/.n8n/.n8n/config"
|
encryption_key = f"auto_generated_key_{randomPassword.generate_pass(32)}"
|
||||||
|
self.data['N8N_ENCRYPTION_KEY'] = encryption_key
|
||||||
# Ensure parent directory exists
|
|
||||||
command = f"mkdir -p {base_dir}/.n8n/.n8n"
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
# Write config file
|
|
||||||
with open(config_file, 'w') as f:
|
|
||||||
json.dump(config_content, f, indent=2)
|
|
||||||
|
|
||||||
# Set ownership recursively
|
# Create n8n config with the encryption key
|
||||||
command = f"chown -R 1000:1000 {base_dir}"
|
config_content = {
|
||||||
ProcessUtilities.executioner(command)
|
"encryptionKey": encryption_key,
|
||||||
|
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
||||||
|
"nodes": {},
|
||||||
|
"credentials": {},
|
||||||
|
"settings": {
|
||||||
|
"instanceId": f"n8n_{randomPassword.generate_pass(12)}",
|
||||||
|
"tunnelSubdomain": None,
|
||||||
|
"deployment": "default"
|
||||||
|
},
|
||||||
|
"versionNotifications": {
|
||||||
|
"enabled": False,
|
||||||
|
"endpoint": "https://api.n8n.io/api/v1/versions/notifications.json",
|
||||||
|
"infoUrl": "https://docs.n8n.io/reference/release-notes.html"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Set directory permissions
|
# Create necessary directories
|
||||||
command = f"find {base_dir} -type d -exec chmod 755 {{}} \\;"
|
required_dirs = [
|
||||||
ProcessUtilities.executioner(command)
|
f"{base_dir}/.n8n",
|
||||||
|
f"{base_dir}/.n8n/.n8n",
|
||||||
|
f"{base_dir}/.n8n/database",
|
||||||
|
f"{base_dir}/.n8n/workflows",
|
||||||
|
f"{base_dir}/.n8n/credentials"
|
||||||
|
]
|
||||||
|
|
||||||
# Set file permissions
|
# Create directories and set ownership/permissions
|
||||||
command = f"find {base_dir} -type f -exec chmod 644 {{}} \\;"
|
for directory in required_dirs:
|
||||||
ProcessUtilities.executioner(command)
|
command = f"mkdir -p {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"chown -R 1000:1000 {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"chmod 755 {directory}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
# Create empty .gitignore to prevent permission issues
|
# Write config to a temporary file first
|
||||||
command = f"touch {base_dir}/.n8n/.gitignore"
|
temp_config = f'/home/cyberpanel/{str(randint(1000, 9999))}-config.json'
|
||||||
ProcessUtilities.executioner(command)
|
with open(temp_config, 'w') as f:
|
||||||
command = f"chown 1000:1000 {base_dir}/.n8n/.gitignore"
|
json.dump(config_content, f, indent=2)
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
command = f"chmod 644 {base_dir}/.n8n/.gitignore"
|
# Set proper ownership and permissions on temp file
|
||||||
ProcessUtilities.executioner(command)
|
command = f"chown 1000:1000 {temp_config}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"chmod 644 {temp_config}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Move config to final location
|
||||||
|
config_file = f"{base_dir}/.n8n/.n8n/config"
|
||||||
|
command = f"mv {temp_config} {config_file}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Create empty .gitignore to prevent permission issues
|
||||||
|
command = f"touch {base_dir}/.n8n/.gitignore"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"chown 1000:1000 {base_dir}/.n8n/.gitignore"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"chmod 644 {base_dir}/.n8n/.gitignore"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Final permission check on the entire directory
|
||||||
|
command = f"chown -R 1000:1000 {base_dir}"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"find {base_dir} -type d -exec chmod 755 {{}} \\;"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = f"find {base_dir} -type f -exec chmod 644 {{}} \\;"
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.writeToFile(f'Error in setup_n8n_data_directory: {str(msg)}')
|
||||||
|
raise
|
||||||
|
|
||||||
def DeployN8NContainer(self):
|
def DeployN8NContainer(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user