Skip to content

Commit 0ad0afc

Browse files
author
Dmytro Lukianenko
committed
create docker image dmi3yy/evolution-cms
1 parent eb86dd7 commit 0ad0afc

File tree

1 file changed

+96
-24
lines changed

1 file changed

+96
-24
lines changed

docker/entrypoint.sh

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,69 @@ if [ -n "$DB_HOST" ] && [ "$DB_HOST" != "localhost" ]; then
4545
timeout 30 sh -c 'until nc -z $0 $1; do sleep 1; done' "$DB_HOST" "${DB_PORT:-5432}" || echo "Database wait timeout"
4646
fi
4747

48+
# Function to create database config file from ENV variables
49+
create_db_config() {
50+
echo "📝 Creating database configuration file..."
51+
52+
# Map database type
53+
case "$DB_CONNECTION" in
54+
"pgsql"|"postgresql")
55+
DB_TYPE="pgsql"
56+
DB_PORT_DEFAULT="5432"
57+
DB_CHARSET="utf8"
58+
DB_COLLATION="utf8"
59+
DB_ENGINE=""
60+
;;
61+
"mysql"|"mariadb")
62+
DB_TYPE="mysql"
63+
DB_PORT_DEFAULT="3306"
64+
DB_CHARSET="utf8mb4"
65+
DB_COLLATION="utf8mb4_unicode_520_ci"
66+
DB_ENGINE=", 'innodb'"
67+
;;
68+
*)
69+
DB_TYPE="mysql"
70+
DB_PORT_DEFAULT="3306"
71+
DB_CHARSET="utf8mb4"
72+
DB_COLLATION="utf8mb4_unicode_520_ci"
73+
DB_ENGINE=", 'innodb'"
74+
echo "⚠️ Unknown DB_CONNECTION '$DB_CONNECTION', defaulting to mysql"
75+
;;
76+
esac
77+
78+
# Use default port if not set
79+
DB_PORT="${DB_PORT:-$DB_PORT_DEFAULT}"
80+
81+
# Create config directory if it doesn't exist
82+
mkdir -p /var/www/html/core/config/database/connections
83+
84+
# Create database config file
85+
cat > /var/www/html/core/config/database/connections/default.php <<EOF
86+
<?php
87+
return [
88+
'driver' => env('DB_TYPE', '${DB_TYPE}'),
89+
'host' => env('DB_HOST', '${DB_HOST}'),
90+
'port' => env('DB_PORT', '${DB_PORT}'),
91+
'database' => env('DB_DATABASE', '${DB_DATABASE}'),
92+
'username' => env('DB_USERNAME', '${DB_USERNAME}'),
93+
'password' => env('DB_PASSWORD', '${DB_PASSWORD}'),
94+
'unix_socket' => env('DB_SOCKET', ''),
95+
'charset' => env('DB_CHARSET', '${DB_CHARSET}'),
96+
'collation' => env('DB_COLLATION', '${DB_COLLATION}'),
97+
'prefix' => env('DB_PREFIX', '${EVO_TABLE_PREFIX:-evo_}'),
98+
'method' => env('DB_METHOD', 'SET CHARACTER SET'),
99+
'strict' => env('DB_STRICT', false),
100+
'engine' => env('DB_ENGINE'${DB_ENGINE}),
101+
'options' => [
102+
PDO::ATTR_STRINGIFY_FETCHES => true,
103+
]
104+
];
105+
EOF
106+
107+
chmod 0644 /var/www/html/core/config/database/connections/default.php
108+
echo "✅ Database configuration file created"
109+
}
110+
48111
# Auto-install Evolution CMS if not already installed
49112
if [ "$EVO_AUTO_INSTALL" = "true" ] && [ ! -f "/var/www/html/config.php" ]; then
50113
echo "🚀 Evolution CMS not found, starting auto-installation..."
@@ -69,6 +132,11 @@ if [ "$EVO_AUTO_INSTALL" = "true" ] && [ ! -f "/var/www/html/config.php" ]; then
69132
;;
70133
esac
71134

135+
# For update mode (typeInstall=2), create config file first
136+
if [ "${EVO_INSTALL_TYPE}" = "2" ]; then
137+
create_db_config
138+
fi
139+
72140
# Run CLI installer
73141
php cli-install.php \
74142
--typeInstall="${EVO_INSTALL_TYPE}" \
@@ -86,37 +154,41 @@ if [ "$EVO_AUTO_INSTALL" = "true" ] && [ ! -f "/var/www/html/config.php" ]; then
86154
--removeInstall="${EVO_REMOVE_INSTALL}"
87155

88156
if [ $? -eq 0 ]; then
89-
echo "✅ Evolution CMS installed successfully!"
90-
91-
# Post-installation setup
92-
cd /var/www/html/core/
93-
94-
# Create main package if MAIN_PACKAGE_NAME is set
95-
if [ -n "$EVO_MAIN_PACKAGE_NAME" ]; then
96-
echo "📦 Creating main package: $EVO_MAIN_PACKAGE_NAME"
97-
php artisan package:create "$EVO_MAIN_PACKAGE_NAME"
98-
# Normalize package name to StudlyCase (first letter uppercase)
99-
EVO_MAIN_PACKAGE_STUDLY=$(printf "%s" "$EVO_MAIN_PACKAGE_NAME" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')
100-
# Write exact PHP string with double quotes and escaped backslashes
101-
cat > custom/config/cms/settings/ControllerNamespace.php <<PHP
157+
if [ "${EVO_INSTALL_TYPE}" = "2" ]; then
158+
echo "✅ Evolution CMS updated successfully!"
159+
else
160+
echo "✅ Evolution CMS installed successfully!"
161+
162+
# Post-installation setup (only for fresh install, not for update)
163+
cd /var/www/html/core/
164+
165+
# Create main package if MAIN_PACKAGE_NAME is set
166+
if [ -n "$EVO_MAIN_PACKAGE_NAME" ]; then
167+
echo "📦 Creating main package: $EVO_MAIN_PACKAGE_NAME"
168+
php artisan package:create "$EVO_MAIN_PACKAGE_NAME"
169+
# Normalize package name to StudlyCase (first letter uppercase)
170+
EVO_MAIN_PACKAGE_STUDLY=$(printf "%s" "$EVO_MAIN_PACKAGE_NAME" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')
171+
# Write exact PHP string with double quotes and escaped backslashes
172+
cat > custom/config/cms/settings/ControllerNamespace.php <<PHP
102173
<?php return "EvolutionCMS\\\\$EVO_MAIN_PACKAGE_STUDLY\\\\Controllers\\\\";
103174
PHP
175+
fi
176+
177+
# Install TinyMCE5 if enabled
178+
if [ "$EVO_INSTALL_TINYMCE" = "true" ]; then
179+
echo "📝 Installing TinyMCE5..."
180+
php artisan extras extras TinyMCE5 master || echo "⚠️ TinyMCE5 installation failed"
181+
echo '<?php return "TinyMCE5"; ?>' > custom/config/cms/settings/which_editor.php || true
182+
fi
183+
184+
echo "🎉 Evolution CMS setup completed!"
104185
fi
105186

106-
# Install TinyMCE5 if enabled
107-
if [ "$EVO_INSTALL_TINYMCE" = "true" ]; then
108-
echo "📝 Installing TinyMCE5..."
109-
php artisan extras extras TinyMCE5 master || echo "⚠️ TinyMCE5 installation failed"
110-
echo '<?php return "TinyMCE5"; ?>' > custom/config/cms/settings/which_editor.php || true
111-
fi
112-
113-
# Set final permissions
187+
# Set final permissions (for both install and update)
114188
cd /var/www/html/
115189
chown -R www-data:www-data . || true
116-
117-
echo "🎉 Evolution CMS setup completed!"
118190
else
119-
echo "❌ Evolution CMS installation failed!"
191+
echo "❌ Evolution CMS installation/update failed!"
120192
exit 1
121193
fi
122194
else

0 commit comments

Comments
 (0)