From 57f16dae3f429d797fb0fb2d8ff425551b4871ea Mon Sep 17 00:00:00 2001 From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr> Date: Thu, 7 Feb 2019 17:18:58 +0100 Subject: [PATCH] Remise en ordre de bataille (doc, docker, etc.) du projet. --- Dockerfile | 37 +++++++++++++++ README.md | 45 +++++++++++++++---- composer.json | 5 +++ composer.lock | 8 ++-- config/application.config.php | 13 ++++-- config/autoload/.gitignore | 1 + config/autoload/README.md | 8 ---- config/autoload/local.php.dist | 12 ++--- data/.gitignore | 1 + docker-compose.yml | 13 ++++++ docker/apache-ports.conf | 2 + docker/apache-site-ssl.conf | 30 +++++++++++++ docker/apache-site.conf | 13 ++++++ docker/fpm/pool.d/app.conf | 24 ++++++++++ docker/php.conf | 30 +++++++++++++ .../view/application/index/index.phtml | 40 +++++++---------- public/.htaccess | 10 ++--- 17 files changed, 232 insertions(+), 60 deletions(-) create mode 100644 Dockerfile create mode 100644 config/autoload/.gitignore delete mode 100755 config/autoload/README.md mode change 100755 => 100644 config/autoload/local.php.dist create mode 100644 data/.gitignore create mode 100644 docker-compose.yml create mode 100644 docker/apache-ports.conf create mode 100644 docker/apache-site-ssl.conf create mode 100644 docker/apache-site.conf create mode 100644 docker/fpm/pool.d/app.conf create mode 100644 docker/php.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a58511 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +########################################################################################### +# +# Image pour le dev. +# +########################################################################################### + +FROM unicaen-dev-php7.0-apache + +LABEL maintainer="Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>" + +ENV APACHE_CONF_DIR=/etc/apache2 \ + PHP_CONF_DIR=/etc/php/7.0 + +## Installation de packages requis. +RUN apt-get install -y \ + sqlite3 \ + php7.0-pdo-sqlite + +# Nettoyage +RUN apt-get autoremove -y && apt-get clean && rm -rf /tmp/* /var/tmp/* + +# Symlink apache access and error logs to stdout/stderr so Docker logs shows them +RUN ln -sf /dev/stdout /var/log/apache2/access.log +RUN ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log +RUN ln -sf /dev/stderr /var/log/apache2/error.log + +# Config PHP. +ADD docker/php.conf ${PHP_CONF_DIR}/fpm/conf.d/webapp.ini + +# Configuration Apache et FPM +ADD docker/apache-ports.conf ${APACHE_CONF_DIR}/ports.conf +ADD docker/apache-site.conf ${APACHE_CONF_DIR}/sites-available/webapp.conf +ADD docker/apache-site-ssl.conf ${APACHE_CONF_DIR}/sites-available/webapp-ssl.conf +ADD docker/fpm/pool.d/app.conf ${PHP_CONF_DIR}/fpm/pool.d/webapp.conf + +RUN a2ensite webapp webapp-ssl && \ + service php7.0-fpm reload diff --git a/README.md b/README.md index 4fcdf8d..d60a58e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,44 @@ # Squelette d'application Unicaen + +## Build et lancement du container Docker + + $ docker-compose up --build -d + +## Installation des dépendances PHP : + + $ docker-compose run skeleton-application composer install + +## Base données de démonstration + +Vérifiez que la base de données de démo existe dans le module 'Demo' : + + $ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite ".schema" + +Interrogez la table `user` pour vérifier la présence de l'utilisateur local `demo`, exemple : + + $ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite "select * from user;" + ## Configuration du projet - Renommez `config/autoload/local.php.dist` en `local.php`. - A l'intérieur du fichier, remplacez false par true pour afficher tous les messages d'erreur. - -- Copiez dans votre dossier `config/autoload` les fichiers de configuration locaux et globaux - de UnicaenApp, UnicaenAuth et UnicaenCode : + +- Copiez dans votre dossier `config/autoload` les fichiers de configuration locaux et globaux `.dist` + des bibliothèques utilisées sans leur extension `.dist` : ```bash -cp vendor/unicaen/app/config/*.dist config/autoload/ -cp vendor/unicaen/auth/config/*.dist config/autoload/ -cp vendor/unicaen/code/config/*.dist config/autoload/ +cp vendor/unicaen/app/config/unicaen-app.global.php.dist config/autoload/unicaen-app.global.php +cp vendor/unicaen/app/config/unicaen-app.local.php.dist config/autoload/unicaen-app.local.php +cp vendor/unicaen/auth/config/unicaen-auth.global.php.dist config/autoload/unicaen-auth.global.php +cp vendor/unicaen/auth/config/unicaen-auth.local.php.dist config/autoload/unicaen-auth.local.php +cp vendor/unicaen/code/config/unicaen-code.global.php.dist config/autoload/unicaen-code.global.php ``` -- Reportez-vous aux docs des modules Personnalisez ces fichiers de configuration locaux et globaux selon vos besoins. - \ No newline at end of file +- Le cas échéant, reportez-vous aux docs des modules concernés pour adapter ces fichiers de configuration à vos besoins : + - [unicaen/app](https://git.unicaen.fr/lib/unicaen/app) + - [unicaen/auth](https://git.unicaen.fr/lib/unicaen/auth) + - [unicaen/code](https://git.unicaen.fr/lib/unicaen/code) + +## Test de l'application + +Théoriquement, l'application devrait être accessible à l'adresse [htpps://localhost:8843](htpps://localhost:8843). +Le port utilisé dépend des redirections configurées dans le fichier [docker-compose.yml](docker-compose.yml). diff --git a/composer.json b/composer.json index 20071d8..1aff7fd 100755 --- a/composer.json +++ b/composer.json @@ -17,5 +17,10 @@ "zendframework/zend-test": ">=2.3", "phpunit/PHPUnit": ">=3.7", "zendframework/zend-developer-tools": ">=1.0" + }, + "scripts": { + "post-install-cmd": [ + "mkdir -p data/DoctrineORMModule/Proxy ; chmod -R 777 data/DoctrineORMModule/Proxy" + ] } } \ No newline at end of file diff --git a/composer.lock b/composer.lock index 25573c9..3a1d374 100644 --- a/composer.lock +++ b/composer.lock @@ -1522,7 +1522,7 @@ "source": { "type": "git", "url": "https://git.unicaen.fr/lib/unicaen/app.git", - "reference": "bc1f9f3da92257804b0cb6b93a105933195a5a9b" + "reference": "fa7e14bbd80206ab70ec1327dfd4c5b9a01ccee2" }, "require": { "doctrine/doctrine-orm-module": ">=0.7", @@ -1565,7 +1565,7 @@ ] }, "description": "Module de base des applications unicaen", - "time": "2019-02-06T11:21:28+00:00" + "time": "2019-02-07T13:34:05+00:00" }, { "name": "unicaen/auth", @@ -1573,7 +1573,7 @@ "source": { "type": "git", "url": "https://git.unicaen.fr/lib/unicaen/auth.git", - "reference": "d80ab1b78e36470e66eb0b1839469121a2ca3cab" + "reference": "bd13ecebdc85fa069d291dbb622f989a18a84624" }, "require": { "jasig/phpcas": ">=1.3.3", @@ -1596,7 +1596,7 @@ ] }, "description": "Module d'authentification pour les applications Unicaen", - "time": "2019-02-06T13:20:50+00:00" + "time": "2019-02-07T14:26:43+00:00" }, { "name": "unicaen/bjy-authorize", diff --git a/config/application.config.php b/config/application.config.php index 71450e2..ff9e902 100755 --- a/config/application.config.php +++ b/config/application.config.php @@ -1,10 +1,17 @@ <?php $modules = [ + 'ZfcBase', + 'DoctrineModule', + 'DoctrineORMModule', + 'ZfcUser', + 'ZfcUserDoctrineORM', + 'BjyAuthorize', + 'AssetManager', + 'UnicaenApp', + 'UnicaenAuth', 'Application', - 'ZfcBase', 'DoctrineModule', 'DoctrineORMModule', 'ZfcUser', 'ZfcUserDoctrineORM', - 'BjyAuthorize', 'AssetManager', - 'UnicaenApp', 'UnicaenAuth', + 'Demo', ]; if ( 'development' == getenv('APPLICATION_ENV') ?: 'production' ) { diff --git a/config/autoload/.gitignore b/config/autoload/.gitignore new file mode 100644 index 0000000..8962df0 --- /dev/null +++ b/config/autoload/.gitignore @@ -0,0 +1 @@ +*local.php diff --git a/config/autoload/README.md b/config/autoload/README.md deleted file mode 100755 index 4e504db..0000000 --- a/config/autoload/README.md +++ /dev/null @@ -1,8 +0,0 @@ -About this directory: -===================== - -By default, this application is configured to load all configs in -`./config/autoload/{,*.}{global,local}.php`. Doing this provides a -location for a developer to drop in configuration override files provided by -modules, as well as cleanly provide individual, application-wide config files -for things like database connections, etc. diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist old mode 100755 new mode 100644 index ebbe6fa..2a0cce1 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -1,7 +1,7 @@ <?php -return array( - 'view_manager' => array( - 'display_not_found_reason' => false, - 'display_exceptions' => false, - ), -); +return [ + 'view_manager' => [ + 'display_not_found_reason' => true, + 'display_exceptions' => true, + ], +]; diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..ae8c28a --- /dev/null +++ b/data/.gitignore @@ -0,0 +1 @@ +DoctrineORMModule/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fcc82bf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '2' + +services: + skeleton-application: + container_name: skeleton-application-container + build: + context: . + ports: + - "8880:80" + - "8843:443" + volumes: + - .:/var/www/webapp + working_dir: /var/www/webapp diff --git a/docker/apache-ports.conf b/docker/apache-ports.conf new file mode 100644 index 0000000..24c3bb2 --- /dev/null +++ b/docker/apache-ports.conf @@ -0,0 +1,2 @@ +Listen 80 +Listen 443 diff --git a/docker/apache-site-ssl.conf b/docker/apache-site-ssl.conf new file mode 100644 index 0000000..ca15061 --- /dev/null +++ b/docker/apache-site-ssl.conf @@ -0,0 +1,30 @@ +<VirtualHost *:443> + ServerName localhost + DocumentRoot /var/www/webapp/public + + SetEnv APPLICATION_ENV "development" + + RewriteEngine On + + <Directory /var/www/webapp/public> + DirectoryIndex index.php + AllowOverride All + Require all granted + </Directory> + + <IfModule proxy_fcgi_module> + <FilesMatch ".+\.ph(ar|p|tml)$"> + SetHandler "proxy:unix:/var/run/php7.0-fpm-webapp.sock|fcgi://localhost/" + </FilesMatch> + </IfModule> + + SSLEngine on + SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem + SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key + + Header always set Strict-Transport-Security "max-age=15768000; includeSubdomains;" + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + #LogLevel debug +</VirtualHost> diff --git a/docker/apache-site.conf b/docker/apache-site.conf new file mode 100644 index 0000000..410da61 --- /dev/null +++ b/docker/apache-site.conf @@ -0,0 +1,13 @@ +<VirtualHost *:80> + ServerName localhost + DocumentRoot /var/www/webapp/public + + RewriteEngine On + + Header always set Strict-Transport-Security "max-age=15768000; includeSubdomains;" + + ### Redirection en HTTPS + RewriteCond %{SERVER_PORT} !^443$ + RewriteRule ^/(.*) https://%{SERVER_NAME}:443/$1 [L,R] + +</VirtualHost> \ No newline at end of file diff --git a/docker/fpm/pool.d/app.conf b/docker/fpm/pool.d/app.conf new file mode 100644 index 0000000..33ec134 --- /dev/null +++ b/docker/fpm/pool.d/app.conf @@ -0,0 +1,24 @@ +[webapp] + +user = www-data +group = www-data + +listen = /var/run/php7.0-fpm-webapp.sock +listen.owner = www-data +listen.group = www-data + +; mandatory values +; Soit: +; pm = dynamic +; pm.max_children = 5 +; pm.start_servers = 2 +; pm.min_spare_servers = 1 +; pm.max_spare_servers = 3 +; Soit: +pm = ondemand +pm.max_children = 35 +pm.process_idle_timeout = 10s +pm.max_requests = 500 + +request_slowlog_timeout = 30 +slowlog = /var/log/php5-fpm.slow.log diff --git a/docker/php.conf b/docker/php.conf new file mode 100644 index 0000000..e2c35fd --- /dev/null +++ b/docker/php.conf @@ -0,0 +1,30 @@ +date.timezone = Europe/Paris + +short_open_tag = Off +expose_php = Off + +log_errors = On +display_startup_errors = On +display_errors = On +error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE + +max_execution_time = 120 + +# NB: ne peut-être supérieur au memory_limit du php.ini +memory_limit = 256M + +# NB: post_max_size > upload_max_filesize +upload_max_filesize = 51M +post_max_size = 52M + +opcache.enable = 0 + +xdebug.remote_enable = 1 +xdebug.remote_connect_back = 1 +xdebug.profiler_enable_trigger = 1 + +xdebug.collect_params = 2 +xdebug.var_display_max_children = 1024 +xdebug.var_display_max_data = -1 +xdebug.max_nesting_level = 256 +# Attention: trop diminuer 'max_nesting_level' peut causer une erreur 'Maximum function nesting level of x reached' diff --git a/module/Application/view/application/index/index.phtml b/module/Application/view/application/index/index.phtml index 3ead921..ef9738b 100755 --- a/module/Application/view/application/index/index.phtml +++ b/module/Application/view/application/index/index.phtml @@ -1,25 +1,19 @@ -<div class="hero-unit"> +<div class="jumbotron"> <h1><?php echo sprintf($this->translate("Bienvenue dans le squelette d'application Unicaen")) ?></h1> - <p><?php echo sprintf($this->translate("Félicitations! Vous avez insallé avec succès le squelette d'application Unicaen propulsé par %sZend Framework 2%s. La version du framework utilisée est la %s."), '<a href="https://github.com/zendframework/ZendSkeletonApplication" target="_blank">', '</a>', \Zend\Version\Version::VERSION) ?></p> - <p><a class="btn btn-success btn-large" href="<?php echo $this->url('zfcuser/login') ?>"><?php echo $this->translate('Connectez-vous...') ?></a></p> -</div> - -<div class="row"> - <div class="span4"> - <h2><?php echo $this->translate('Follow Development') ?></h2> - <p><?php echo sprintf($this->translate('Zend Framework 2 is under active development. If you are interested in following the development of ZF2, there is a special ZF2 portal on the official Zend Framework website which provides links to the ZF2 %swiki%s, %sdev blog%s, %sissue tracker%s, and much more. This is a great resource for staying up to date with the latest developments!'), '<a href="http://framework.zend.com/wiki/display/ZFDEV2/Home">', '</a>', '<a href="http://framework.zend.com/zf2/blog">', '</a>', '<a href="https://github.com/zendframework/zf2/issues">', '</a>') ?></p> - <p><a class="btn btn-success" href="http://framework.zend.com" target="_blank"><?php echo $this->translate('ZF2 Development Portal') ?> »</a></p> - </div> - - <div class="span4"> - <h2><?php echo $this->translate('Discover Modules') ?></h2> - <p><?php echo sprintf($this->translate('The community is working on developing a community site to serve as a repository and gallery for ZF2 modules. The project is available %son GitHub%s. The site is currently live and currently contains a list of some of the modules already available for ZF2.'), '<a href="https://github.com/zendframework/modules.zendframework.com">', '</a>') ?></p> - <p><a class="btn btn-success" href="http://modules.zendframework.com/" target="_blank"><?php echo $this->translate('Explore ZF2 Modules') ?> »</a></p> - </div> - - <div class="span4"> - <h2><?php echo $this->translate('Help & Support') ?></h2> - <p><?php echo sprintf($this->translate('If you need any help or support while developing with ZF2, you may reach us via IRC: %s#zftalk on Freenode%s. We\'d love to hear any questions or feedback you may have regarding the beta releases. Alternatively, you may subscribe and post questions to the %smailing lists%s.'), '<a href="irc://irc.freenode.net/zftalk">', '</a>', '<a href="http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists">', '</a>') ?></p> - <p><a class="btn btn-success" href="http://webchat.freenode.net?channels=zftalk" target="_blank"><?php echo $this->translate('Ping us on IRC') ?> »</a></p> - </div> + <p> + Félicitations! Vous avez insallé avec succès le squelette d'application Unicaen. <br> + La version du framework utilisée est la <?php echo \Zend\Version\Version::VERSION ?> + </p> + <?php if (!$this->identity()): ?> + <p class="text-danger"> + <strong> + <?php echo $this->translate("Vous n'êtes pas connecté-e."); ?> + </strong> + </p> + <p> + <a class="btn btn-success btn-lg" href="<?php echo $this->url('zfcuser/login') ?>"> + <?php echo $this->translate('Connectez-vous...') ?> + </a> + </p> + <?php endif ?> </div> diff --git a/public/.htaccess b/public/.htaccess index d869001..ec20b48 100755 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,20 +1,16 @@ RewriteEngine On -RewriteBase /unicaen-skeleton-application # The following rule tells Apache that if the requested filename # exists, simply serve it. RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] -# The following rewrites all other queries to index.php. The +# The following rewrites all other queries to index.php. The # condition ensures that if you are using Apache aliases to do -# mass virtual hosting, the base path will be prepended to +# mass virtual hosting, the base path will be prepended to # allow proper resolution of the index.php file; it will work -# in non-aliased environments as well, providing a safe, one-size +# in non-aliased environments as well, providing a safe, one-size # fits all solution. RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ RewriteRule ^(.*) - [E=BASE:%1] RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] - -# development par défaut, à rechanger ensuite -SetEnv APPLICATION_ENV "development" \ No newline at end of file -- GitLab