Skip to content

Commit

Permalink
Fix fresh installation and simplify Dockerfile and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
xcompass committed Jun 24, 2020
1 parent 6521608 commit 95c85f6
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Dockerfile-app → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ 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

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 \
Expand Down
11 changes: 0 additions & 11 deletions Dockerfile-web

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/components/upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 11 additions & 18 deletions app/controllers/install_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class InstallController extends Controller
public $components = array(
'Session',
'installHelper',
'Upgrader'
);
public $helpers = array('Session', 'Html', 'Js');
public $layout = 'installer';
Expand Down Expand Up @@ -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'],
Expand All @@ -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;
}
}*/
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/libs/upgrade_scripts/upgrade_330.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -55,4 +55,4 @@ public function up()

return true;
}
}
}
4 changes: 2 additions & 2 deletions app/libs/upgrade_scripts/upgrade_331.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -55,4 +55,4 @@ public function up()

return true;
}
}
}
4 changes: 2 additions & 2 deletions app/libs/upgrade_scripts/upgrade_332.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -46,4 +46,4 @@ public function up()
// nothing to patch
return true;
}
}
}
4 changes: 2 additions & 2 deletions app/libs/upgrade_scripts/upgrade_334.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -55,4 +55,4 @@ public function up()

return true;
}
}
}
4 changes: 2 additions & 2 deletions app/libs/upgrade_scripts/upgrade_340.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -55,4 +55,4 @@ public function up()

return true;
}
}
}
4 changes: 2 additions & 2 deletions app/libs/upgrade_scripts/upgrade_344.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -55,4 +55,4 @@ public function up()

return true;
}
}
}
3 changes: 3 additions & 0 deletions app/libs/upgrade_scripts/upgrade_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
}
Expand Down
29 changes: 10 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions docker/nginx-unittest.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions docker/xdebug.ini
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95c85f6

Please sign in to comment.