fix: rewrite init.sh - create config.php directly, fix envtemplate perms
Some checks failed
Docker Build & Push SugarCRM 6.5 CE / build-and-push (push) Failing after 1m6s

This commit is contained in:
root
2026-05-24 14:57:31 +02:00
parent 3d617b4220
commit 043e33e643
2 changed files with 132 additions and 71 deletions

View File

@@ -42,7 +42,7 @@ RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
COPY config_override.php.pyt /usr/local/src/config_override.php.pyt
COPY envtemplate.py /usr/local/bin/envtemplate.py
COPY init.sh /usr/local/bin/init.sh
RUN chmod u+x /usr/local/bin/init.sh
RUN chmod +x /usr/local/bin/envtemplate.py /usr/local/bin/init.sh
# Cron
COPY crons.conf /root/crons.conf

189
init.sh
View File

@@ -1,9 +1,9 @@
#!/bin/sh
# SugarCRM 6.5 CE Docker Entrypoint
# ==================================
# Pitfalls documented (see README.md Technical Notes)
# Creates config.php directly (bypasses broken silent installer)
# Resolve DB connection from env/linked container
# Resolve DB connection from env
if [ -z "$DB_HOST_NAME" ]; then
export DB_HOST_NAME=${DB_PORT_3306_TCP_ADDR:-db}
fi
@@ -20,14 +20,15 @@ if [ -z "$DATABASE_NAME" ]; then
export DATABASE_NAME=${DB_ENV_MYSQL_DATABASE:-sugarcrm}
fi
/usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php
# Generate config_override.php from template (ignore perm error)
/usr/local/bin/envtemplate.py -i /usr/local/src/config_override.php.pyt -o /var/www/html/config_override.php 2>/dev/null || true
# Start Apache in background for silent install via HTTP
# Start Apache
echo "Starting Apache (background)..."
apachectl -DFOREGROUND &
APACHE_PID=$!
# Wait for Apache to be ready
# Wait for Apache
echo "Waiting for Apache..."
for i in $(seq 1 30); do
if curl -s http://localhost/ >/dev/null 2>&1; then
@@ -37,41 +38,7 @@ for i in $(seq 1 30); do
sleep 1
done
# Run silent install if not already installed
if [ ! -f /var/www/html/config.php ]; then
echo "Running SugarCRM Silent Install..."
cat > /var/www/html/config_si.php << SIEOF
<?php
\$sugar_config_si = array(
'setup_db_host_name' => 'DB_HOST',
'setup_db_database_name' => 'DB_NAME',
'setup_db_admin_user_name' => 'DB_USER',
'setup_db_admin_password' => 'DB_PASS',
'setup_db_type' => 'mysql',
'setup_db_port_num' => 'DB_PORT',
'setup_db_drop_tables' => false,
'setup_db_create_database' => false,
'setup_db_create_sugarsales_user' => false,
'setup_license_key' => 'free',
'setup_license_accept' => true,
'setup_site_url' => 'http://localhost:2080',
'setup_system_name' => 'SugarCRM 6.5 CE',
'setup_site_admin_user_name' => 'admin',
'setup_site_admin_password' => 'admin123',
'setup_site_admin_password_retype' => 'admin123',
'demoData' => 'no',
'dbUSRData' => 'create',
);
SIEOF
sed -i "s/DB_HOST/$DB_HOST_NAME/g" /var/www/html/config_si.php
sed -i "s/DB_NAME/$DATABASE_NAME/g" /var/www/html/config_si.php
sed -i "s/DB_USER/$DB_USER_NAME/g" /var/www/html/config_si.php
sed -i "s/DB_PASS/$DB_PASSWORD/g" /var/www/html/config_si.php
sed -i "s/DB_PORT/$DB_TCP_PORT/g" /var/www/html/config_si.php
# Wait for MySQL (using PHP socket check - no mysqladmin in container)
# Wait for MySQL
echo "Waiting for MySQL..."
for i in $(seq 1 30); do
if php -r "\$c=@mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT','$DB_USER_NAME','$DB_PASSWORD');if(\$c){mysql_close(\$c);exit(0);}exit(1);" 2>/dev/null; then
@@ -81,47 +48,141 @@ SIEOF
sleep 2
done
# Run silent install via HTTP
echo "Executing silent install..."
curl -s "http://localhost/install.php?goto=SilentInstall&cli=true" > /dev/null 2>&1
# Create config.php directly if not exists or empty
CONFIG_PHP=/var/www/html/config.php
if [ ! -s "$CONFIG_PHP" ]; then
echo "Creating config.php directly..."
if [ -f /var/www/html/config.php ]; then
echo "Silent install complete"
cat > "$CONFIG_PHP" << CONFIGEOF
<?php
// SugarCRM 6.5 CE Configuration
// Auto-generated by Docker entrypoint
\$sugar_config = array(
'adminwizard' => array('completed' => true),
'dbconfig' => array(
'db_host_name' => '$DB_HOST_NAME',
'db_host_instance' => 'SQLEXPRESS',
'db_user_name' => '$DB_USER_NAME',
'db_password' => '$DB_PASSWORD',
'db_name' => '$DATABASE_NAME',
'db_type' => 'mysql',
'db_port' => '$DB_TCP_PORT',
'db_manager' => 'MysqlManager',
),
'dbconfigoption' => array(
'persistent' => true,
'autofree' => false,
'debug' => 0,
'ssl' => false,
),
'default_currency_iso4217' => 'EUR',
'default_currency_name' => 'Euro',
'default_currency_symbol' => '€',
'default_date_format' => 'd.m.Y',
'default_time_format' => 'H:i',
'default_language' => 'en_us',
'default_theme' => 'Sugar',
'default_module_favicon' => false,
'default_charset' => 'UTF-8',
'default_number_grouping_seperator' => '.',
'default_decimal_seperator' => ',',
'disable_export' => false,
'disable_vcr' => false,
'dump_slow_queries' => false,
'email_default_client' => 'sugar',
'email_default_editor' => 'plain',
'export_delimiter' => ',',
'history_max_viewed' => 50,
'installer_locked' => true,
'languages' => array('en_us' => 'English (US)'),
'list_max_entries_per_page' => 20,
'lock_default_user_name' => 'admin',
'lock_default_user_password' => 'admin123',
'passwordsetting' => array(
'minpwdlength' => '',
'oneupper' => '',
'onelower' => '',
'onenumber' => '',
'onespecial' => '',
'systemgenerated' => '0',
'forgotpasswordON' => '1',
'linkexpiration' => '1',
'linkexpirationtime' => '24',
'linkexpirationtype' => '1',
'userexpiration' => '0',
'userexpirationtime' => '',
'userexpirationtype' => '1',
'userexpirationlogin' => '',
'lockoutexpiration' => '0',
'lockoutexpirationtime' => '',
'lockoutexpirationtype' => '1',
'lockoutexpirationlogin' => '',
),
'resource_management' => array(
'special_query_limit' => 50000,
'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
'default_limit' => 1000,
),
'site_url' => 'http://localhost:2080',
'site_url_is_set' => true,
'sugar_version' => '6.5.26',
'sugarbeet' => false,
'translation_string_prefix' => false,
'unique_key' => '$(date +%s)$(head -c 8 /dev/urandom | md5sum | cut -c1-8)',
'upload_maxsize' => 30000000,
'verify_client_ip' => false,
'logger' => array(
'level' => 'fatal',
'file' => array(
'ext' => '.log',
'name' => 'sugarcrm',
'dateFormat' => '%c',
'maxSize' => '10MB',
'dirPerm' => 0770,
'filePerm' => 0660,
),
),
'cache_dir' => 'cache/',
);
require_once('include/SugarObjects/VardefManager.php');
require_once('modules/Administration/Administration.php');
CONFIGEOF
# Fix: installer_locked=true to prevent AdminWizard blocking API
sed -i "s/'installer_locked' => false/'installer_locked' => true/" /var/www/html/config.php 2>/dev/null || true
# Verify config.php has content
if [ -s "$CONFIG_PHP" ]; then
echo "config.php created successfully ($(wc -l < "$CONFIG_PHP") lines)"
# Skip Admin Wizard in config.php
sed -i "/'site_url' =>/a\\
'adminwizard' => array('completed' => true)," /var/www/html/config.php 2>/dev/null || true
# Ensure installer_locked is true
sed -i "s/'installer_locked' => *false/'installer_locked' => true/" "$CONFIG_PHP" 2>/dev/null || true
if ! grep -q "installer_locked" "$CONFIG_PHP"; then
echo " 'installer_locked' => true," >> "$CONFIG_PHP"
fi
# Skip Admin Wizard in database (pitfall: needed for API access after restart)
# Insert adminwizard into DB for API access
php -r "
\$c = @mysql_connect('$DB_HOST_NAME:$DB_TCP_PORT', '$DB_USER_NAME', '$DB_PASSWORD');
if (\$c) {
mysql_select_db('$DATABASE_NAME', \$c);
mysql_query(\"INSERT INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c);
mysql_query(\"INSERT IGNORE INTO config (category, name, value) VALUES ('system', 'adminwizard', '{\\\"completed\\\":true}')\", \$c);
mysql_close(\$c);
}
" 2>/dev/null || true
echo "Admin Wizard disabled"
else
echo "WARNING: config.php was not created! Check install."
echo "ERROR: config.php is empty!"
fi
else
echo "SugarCRM already installed"
echo "SugarCRM already configured ($(wc -l < "$CONFIG_PHP") lines)"
# Ensure installer_locked is true (idempotent restart fix)
if grep -q "'installer_locked' => false" /var/www/html/config.php 2>/dev/null; then
sed -i "s/'installer_locked' => false/'installer_locked' => true/" /var/www/html/config.php
# Ensure installer_locked is true
if grep -q "'installer_locked' => false" "$CONFIG_PHP" 2>/dev/null; then
sed -i "s/'installer_locked' => false/'installer_locked' => true/" "$CONFIG_PHP"
echo "Fixed installer_locked"
fi
# Ensure Admin Wizard remains disabled
if ! grep -q adminwizard /var/www/html/config.php 2>/dev/null; then
sed -i "/sugar_config\['site_url'\]/a\\
\$sugar_config['adminwizard'] = array('completed' => true);" /var/www/html/config.php 2>/dev/null || true
# Ensure adminwizard is in config
if ! grep -q adminwizard "$CONFIG_PHP" 2>/dev/null; then
sed -i "/'site_url' =>/a\\
'adminwizard' => array('completed' => true)," "$CONFIG_PHP" 2>/dev/null || true
echo "Admin Wizard disabled"
fi
fi
@@ -131,7 +192,7 @@ rm -f /var/www/html/config_si.php
# Start cron
/usr/sbin/cron
echo "Setup complete. SugarCRM 6.5.26 CE ready."
# Bring Apache to foreground
echo "Setup complete. SugarCRM 6.5.26 CE ready."
wait $APACHE_PID