diff --git a/Dockerfile-app b/Dockerfile similarity index 90% rename from Dockerfile-app rename to Dockerfile index 243d175e7..4d0761ccf 100644 --- a/Dockerfile-app +++ b/Dockerfile @@ -11,8 +11,8 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge && ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \ && ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so \ && docker-php-ext-install -j$(nproc) xml gd ldap mysqli \ - && pecl install timezonedb \ - && docker-php-ext-enable timezonedb \ + && pecl install timezonedb xdebug\ + && docker-php-ext-enable timezonedb xdebug\ && curl https://getcomposer.org/download/1.8.4/composer.phar -o /usr/local/bin/composer \ && chmod +x /usr/local/bin/composer @@ -20,7 +20,7 @@ COPY docker/php.ini /usr/local/etc/php/ COPY . /var/www/html RUN cd /var/www/html \ - && composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --no-suggest --optimize-autoloader \ + && composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-suggest --optimize-autoloader \ && mkdir -p /var/www/html/app/tmp/cache/persistent /var/www/html/app/tmp/cache/models /var/www/html/app/tmp/logs \ && chown www-data:www-data -R /var/www/html/app/tmp/cache \ && ln -sf /dev/stdout /var/www/html/app/tmp/logs/api.log \ diff --git a/Dockerfile-web b/Dockerfile-web deleted file mode 100644 index b19d93955..000000000 --- a/Dockerfile-web +++ /dev/null @@ -1,11 +0,0 @@ -FROM nginx:1.11 - -COPY docker/nginx.conf /etc/nginx/conf.d/default.conf -COPY docker/docker-entrypoint.sh / -COPY app/webroot/ /var/www/html/ - -RUN chmod +x /docker-entrypoint.sh - -ENTRYPOINT ["/docker-entrypoint.sh"] - -CMD ["nginx", "-g", "daemon off;"] diff --git a/app/controllers/components/upgrader.php b/app/controllers/components/upgrader.php index ee4fba216..0ed7db17d 100644 --- a/app/controllers/components/upgrader.php +++ b/app/controllers/components/upgrader.php @@ -25,7 +25,7 @@ public function __construct() $scriptNames = glob(APP.DS.'libs'.DS.'upgrade_scripts/*.php'); sort($scriptNames); foreach ($scriptNames as $script) { - if (basename($script) == 'upgrade_base.php') { + if (basename($script) == 'upgrade_base.php' || basename($script) == 'upgrade_default.php') { continue; } require_once($script); diff --git a/app/controllers/install_controller.php b/app/controllers/install_controller.php index 641eb85c0..827bc46dc 100644 --- a/app/controllers/install_controller.php +++ b/app/controllers/install_controller.php @@ -20,6 +20,7 @@ class InstallController extends Controller public $components = array( 'Session', 'installHelper', + 'Upgrader' ); public $helpers = array('Session', 'Html', 'Js'); public $layout = 'installer'; @@ -158,6 +159,15 @@ function install4() $db = ConnectionManager::getDataSource('default'); $db->cacheSources = false; + // Try to patch the database if needed, note that this database patching + // is only for small changes, not for large version changes + $ret = $this->Upgrader->upgrade(); + if (!$ret) { + $this->Session->setFlash(__('Database patching failed - '.$ret, true)); + $this->redirect(array('action' => 'install4')); + return; + } + $this->createSuperAdmin( $this->data['InstallValidationStep4']['super_admin'], $this->data['InstallValidationStep4']['password'], @@ -178,27 +188,10 @@ function install4() ) ); $this->installHelper->updateSystemParameters($sysparams); - // mark this instance as installed - $f = fopen(TMP.'installed.txt', 'w'); - if (!$f) { - $this->Session->setFlash(sprintf(__('Installation failed, unable to write to %s dir', true), CONFIGS)); - $this->redirect(array('action' => 'install4')); - return; - } - fclose($f); // congratulate the user for a successful install $this->redirect(array('action' => 'install5')); - } /*else { - // Try to patch the database if needed, note that this database patching - // is only for small changes, not for large version changes - $ret = $this->patchDB(); - if ($ret) { - $this->Session->setFlash(__('Database patching failed - '.$ret, true)); - $this->redirect(array('action' => 'install3')); - return; - } - }*/ + } } /** diff --git a/app/libs/upgrade_scripts/upgrade_330.php b/app/libs/upgrade_scripts/upgrade_330.php index 9d0082207..03ff49863 100644 --- a/app/libs/upgrade_scripts/upgrade_330.php +++ b/app/libs/upgrade_scripts/upgrade_330.php @@ -20,9 +20,9 @@ class Upgrade330 extends UpgradeBase */ public function __construct() { - $this->fromVersions = array(null, '3.2.0'); + $this->fromVersions = array(null, '3.1.9', '3.2.0'); $this->toVersion = '3.3.0'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 14; } /** @@ -55,4 +55,4 @@ public function up() return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_331.php b/app/libs/upgrade_scripts/upgrade_331.php index b74e4ae21..d87241aab 100644 --- a/app/libs/upgrade_scripts/upgrade_331.php +++ b/app/libs/upgrade_scripts/upgrade_331.php @@ -22,7 +22,7 @@ public function __construct() { $this->fromVersions = array(null, '3.3.0'); $this->toVersion = '3.3.1'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 15; } /** @@ -55,4 +55,4 @@ public function up() return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_332.php b/app/libs/upgrade_scripts/upgrade_332.php index 91e5dbbf5..57d355d4c 100644 --- a/app/libs/upgrade_scripts/upgrade_332.php +++ b/app/libs/upgrade_scripts/upgrade_332.php @@ -22,7 +22,7 @@ public function __construct() { $this->fromVersions = array(null, '3.3.1'); $this->toVersion = '3.3.2'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 15; } /** @@ -46,4 +46,4 @@ public function up() // nothing to patch return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_334.php b/app/libs/upgrade_scripts/upgrade_334.php index cf45eec3f..a3f2ed507 100644 --- a/app/libs/upgrade_scripts/upgrade_334.php +++ b/app/libs/upgrade_scripts/upgrade_334.php @@ -22,7 +22,7 @@ public function __construct() { $this->fromVersions = array(null, '3.3.2', '3.3.3'); $this->toVersion = '3.3.4'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 15; } /** @@ -55,4 +55,4 @@ public function up() return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_340.php b/app/libs/upgrade_scripts/upgrade_340.php index 3e39e539b..af41b3231 100644 --- a/app/libs/upgrade_scripts/upgrade_340.php +++ b/app/libs/upgrade_scripts/upgrade_340.php @@ -22,7 +22,7 @@ public function __construct() { $this->fromVersions = array(null, '3.3.4', '3.3.5'); $this->toVersion = '3.4.0'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 16; } /** @@ -55,4 +55,4 @@ public function up() return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_344.php b/app/libs/upgrade_scripts/upgrade_344.php index d53c646af..d6119f1c7 100644 --- a/app/libs/upgrade_scripts/upgrade_344.php +++ b/app/libs/upgrade_scripts/upgrade_344.php @@ -22,7 +22,7 @@ public function __construct() { $this->fromVersions = array(null, '3.4.0', '3.4.1', '3.4.2', '3.4.3'); $this->toVersion = '3.4.4'; - $this->dbVersion = Configure::read('DATABASE_VERSION'); + $this->dbVersion = 17; } /** @@ -55,4 +55,4 @@ public function up() return true; } -} \ No newline at end of file +} diff --git a/app/libs/upgrade_scripts/upgrade_base.php b/app/libs/upgrade_scripts/upgrade_base.php index 86fbd8114..7fcab5683 100644 --- a/app/libs/upgrade_scripts/upgrade_base.php +++ b/app/libs/upgrade_scripts/upgrade_base.php @@ -27,6 +27,8 @@ class UpgradeBase public function isUpgradable() { $sysparameter = ClassRegistry::init('SysParameter'); + # make sure to get the value from DB + $sysparameter->reload(); $this->currentVersion = $sysparameter->get('system.version'); return in_array($this->currentVersion, $this->fromVersions); } @@ -66,6 +68,7 @@ public function upgrade() { // because there's no pre-existing database.version entry, // upgrade_310 should properly add this back $sysparameter->setValue('database.version', $this->dbVersion); + $sysparameter->setValue('system.version', $this->toVersion); if (!$sysparameter->get('system.absolute_url')) { $sysparameter->setValue('system.absolute_url', Router::url('/', true)); } diff --git a/docker-compose.yml b/docker-compose.yml index 190fd5f91..0fcc614f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,13 @@ -version: '2' +version: '3' services: db: - image: mariadb:10.1 + image: mariadb:10.4 container_name: ipeer_db environment: - MYSQL_ROOT_PASSWORD=randompassword - MYSQL_DATABASE=ipeer - MYSQL_USER=ipeer - MYSQL_PASSWORD=ipeer - ports: - - "13306:3306" volumes: - ./.data:/var/lib/mysql ports: @@ -18,12 +16,11 @@ services: image: ubcctlt/ipeer-app build: context: . - dockerfile: Dockerfile-app container_name: ipeer_app volumes: - .:/var/www/html - ports: - - "9000:9000" + # uncomment to enable xdebug remote debugging + #- ./docker/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini environment: - IPEER_DB_HOST=db - IPEER_DB_USER=ipeer @@ -39,6 +36,8 @@ services: #- IPEER_AUTH=Ldap #- IPEER_AUTH_LDAP_host=ldap.example.com #- IPEER_AUTH_LDAP_port=636 + # uncomment to enable xdebug remote debugging + #- PHP_IDE_CONFIG=serverName=docker depends_on: - db worker: &worker @@ -48,15 +47,11 @@ services: ports: - "9002:9000" web: - image: ubcctlt/ipeer-web - build: - context: . - dockerfile: Dockerfile-web + image: nginx:1.19-alpine container_name: ipeer_web volumes: - ./app/webroot:/var/www/html - environment: - - NGINX_FASTCGI_PASS=ipeer_app:9000 + - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf ports: - "8080:80" depends_on: @@ -91,15 +86,11 @@ services: - db # for running unit tests web-unittest: - image: ubcctlt/ipeer-web - build: - context: . - dockerfile: Dockerfile-web + image: nginx:1.19-alpine container_name: ipeer_web_unittest volumes: - ./app/webroot:/var/www/html - environment: - - NGINX_FASTCGI_PASS=ipeer_app_unittest:9000 + - ./docker/nginx-unittest.conf:/etc/nginx/conf.d/default.conf ports: - "8081:80" depends_on: diff --git a/docker/nginx-unittest.conf b/docker/nginx-unittest.conf new file mode 100644 index 000000000..0d884da42 --- /dev/null +++ b/docker/nginx-unittest.conf @@ -0,0 +1,17 @@ +server { + listen 80; + + # this path MUST be exactly as docker-compose.fpm.volumes, + # even if it doesn't exists in this dock. + root /var/www/html; + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ ^/.+\.php(/|$) { + fastcgi_pass ipeer_app_unittest:9000; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } +} diff --git a/docker/nginx.conf b/docker/nginx.conf index 403842bdd..3cf842781 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -10,7 +10,7 @@ server { } location ~ ^/.+\.php(/|$) { - fastcgi_pass NGINX_FASTCGI_PASS; + fastcgi_pass ipeer_app:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } diff --git a/docker/xdebug.ini b/docker/xdebug.ini new file mode 100644 index 000000000..80522f581 --- /dev/null +++ b/docker/xdebug.ini @@ -0,0 +1,20 @@ +; This file is intended to supplement the auto-generated "docker-php-ext-xdebug.ini" that gets created by the +; "docker-php-ext-enable xdebug" command. That ini file will contain the path to the dynamically built extension file +; (which is why they should remain separate). + +[XDebug] +; Allow remote hosts to enable debugging, in this case connecting back to the automatically maintained DNS +; name referencing our workstation: host.docker.internal +xdebug.remote_enable = true +xdebug.remote_host = host.docker.internal +xdebug.remote_port = 9000 +xdebug.remote_handler = dbgp + +; Profiling (enable via cookie or GET/POST variable: XDEBUG_PROFILE=1). +xdebug.profiler_enable = 0 +xdebug.profiler_enable_trigger = 1 +xdebug.profiler_output_dir = /tmp/xdebug-profiling/ + +; var_dump() settings. +xdebug.overload_var_dump = 1 +xdebug.cli_color = 1 diff --git a/readme.md b/readme.md index 9c3d94e5c..e0df479a5 100644 --- a/readme.md +++ b/readme.md @@ -48,7 +48,6 @@ Running with Docker Note: if you are planning to do development, you can skip this step. ``` docker pull ubcctlt/ipeer-app -docker pull ubcctlt/ipeer-web ``` #### Edit docker-compose.yml