From 766c5a6d030561c1518cf7ba85ed94f69b3e1a04 Mon Sep 17 00:00:00 2001 From: Hardware Date: Sat, 23 Jul 2016 08:44:00 +0200 Subject: [PATCH] fix(): better management of persistent data :ok_hand: --- Dockerfile | 2 +- README.md | 8 ++---- nginx.conf | 2 +- startup | 75 +++++++++++++++++++++++++++++------------------- supervisord.conf | 2 ++ 5 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index 58a3e30..dbb8b0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,6 @@ COPY startup /usr/local/bin/startup RUN chmod +x /usr/local/bin/startup -VOLUME /flarum/www +VOLUME /flarum/app/assets EXPOSE 8080 CMD ["/usr/bin/tini","--","startup"] diff --git a/README.md b/README.md index 009c329..14aa9b2 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Flarum is the next-generation forum software that makes online discussion fun. I ### Volume -* /flarum/www : Flarum directory +* /flarum/app/assets : Flarum assets directory ## Installation @@ -91,7 +91,7 @@ flarum: links: - mariadb:mariadb volumes: - - /mnt/docker/flarum:/flarum/www + - /mnt/docker/flarum:/flarum/app/assets mariadb: image: mariadb:10.1 @@ -122,10 +122,6 @@ docker-compose up -d * **Username** : *admin* * **Password** : *password* -### Configuration file - -The main configuration file is located here : **/mnt/docker/flarum/app/config.php** - ### Screenshot ![flarum](https://i.imgur.com/teqg3od.pngP) diff --git a/nginx.conf b/nginx.conf index e77ddf3..ab9b74e 100644 --- a/nginx.conf +++ b/nginx.conf @@ -48,7 +48,7 @@ http { server { listen 8080; - root /flarum/www/app; + root /flarum/app; index index.php; access_log /var/log/nginx/access.log; diff --git a/startup b/startup index f1807cc..e5e95a9 100644 --- a/startup +++ b/startup @@ -21,12 +21,9 @@ if [ -z "$FORUM_URL" ]; then exit 1 fi -# if no installation was performed before -if [ ! -e '/flarum/www/app/config.php' ]; then - cd /flarum/app/ -# Flarum settings +# Installation settings cat > config.yml < \$app->make('flarum.config')\]|['config' => \$app->isInstalled() ? \$app->make('flarum.config') : []]|g" vendor/flarum/core/src/Console/Server.php # Set permissions -chown -R flarum:flarum /flarum/app +chown -R flarum:flarum . -# Install flarum (migrate database + assets) -su-exec flarum:flarum php flarum install --file config.yml +# if no installation was performed before +if [ ! -e 'assets/rev-manifest.json' ]; then -# Define flarum settings in database -mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" < config.sql + # Mail settings + sed -i -e "s|{{ MAIL_FROM }}|${MAIL_FROM}|g" \ + -e "s|{{ MAIL_HOST }}|${MAIL_HOST}|g" \ + -e "s|{{ MAIL_PORT }}|${MAIL_PORT}|g" \ + -e "s|{{ MAIL_USER }}|${MAIL_USER}|g" \ + -e "s|{{ MAIL_PASS }}|${MAIL_PASS}|g" \ + -e "s|{{ MAIL_ENCR }}|${MAIL_ENCR}|g" config.sql + + # Install flarum + su-exec flarum:flarum php flarum install --file config.yml + + # Define flarum settings in database + mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" < config.sql + +else + + echo "[INFO] Flarum already installed, init app..." + + # Disable already done steps during installation + # ---------------------------------------------- + # + # See : flarum/core/src/Install/Console/DefaultsDataProvider.php + # flarum/core/src/Install/Console/InstallCommand.php + # + # runMigrations() = Database migration (Flarum\Database\Migrator) + # writeSettings() = Writing default flarum settings (Flarum\Settings\SettingsRepositoryInterface) + # seedGroups() = Create default groups + # seedPermissions() = Create default permissions + # createAdminUser() = Create default admin user + sed -i -e '/$this->runMigrations();/ s/^/#/' \ + -e '/$this->writeSettings();/ s/^/#/' \ + -e '/$this->seedGroups();/ s/^/#/' \ + -e '/$this->seedPermissions();/ s/^/#/' \ + -e '/$this->createAdminUser();/ s/^/#/' vendor/flarum/core/src/Install/Console/InstallCommand.php + + # Init flarum (without steps above) + su-exec flarum:flarum php flarum install --file config.yml + + echo "[INFO] Init done, launch flarum..." + +fi # Removing installation files rm -f config.sql config.yml -# Moving sources to the final web directory -cd / && mv /flarum/app /flarum/www - -else - echo "[INFO] Flarum already installed, launch app..." - - # Removing the source directory - rm -rf /flarum/app -fi - -# Set web directory permissions -chown -R flarum:flarum /flarum/www - # RUN ! exec supervisord -c /etc/supervisor/supervisord.conf diff --git a/supervisord.conf b/supervisord.conf index f2cd4b1..a65aaf9 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -1,4 +1,6 @@ [supervisord] +logfile = /tmp/supervisord.log +pidfile = /tmp/supervisord.pid nodaemon=true [program:php-fpm]