From 849ee28b60e40cd399885d3cba002de5deff5a99 Mon Sep 17 00:00:00 2001 From: Hardware Date: Sun, 17 Jul 2016 11:35:13 +0200 Subject: [PATCH] refactor(): persist state of the forum --- Dockerfile | 24 +++++++++---- README.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.sql | 9 +++++ nginx.conf | 2 +- startup | 58 ++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 README.md create mode 100644 config.sql create mode 100644 startup diff --git a/Dockerfile b/Dockerfile index 0068e76..75e0e99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,13 @@ FROM xataz/alpine:3.4 MAINTAINER xataz MAINTAINER hardware -ENV GID=991 UID=991 +ARG VERSION=v0.1.0-beta.5 + +ENV GID=991 \ + UID=991 \ + DB_HOST=mariadb \ + DB_USER=flarum \ + DB_NAME=flarum RUN echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ && export BUILD_DEPS="git" \ @@ -10,6 +16,7 @@ RUN echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/r nginx \ curl \ supervisor \ + mariadb-client \ php7-phar@testing \ php7-fpm@testing \ php7-curl@testing \ @@ -26,16 +33,19 @@ RUN echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/r && curl -s http://getcomposer.org/installer | php \ && mv /tmp/composer.phar /usr/bin/composer \ && chmod +x /usr/bin/composer \ - && mkdir /flarum \ + && mkdir -p /flarum /usr/src/flarum \ && addgroup -g ${GID} flarum && adduser -h /flarum -s /bin/sh -D -G flarum -u ${UID} flarum \ - && chown flarum:flarum /flarum \ - && su-exec flarum:flarum composer create-project flarum/flarum /flarum/app --stability=beta \ - && composer clear-cache \ - && rm -rf /flarum/.composer/cache/* + && chown flarum:flarum /flarum /usr/src/flarum \ + && su-exec flarum:flarum composer create-project flarum/flarum /usr/src/flarum $VERSION --stability=beta \ + && composer clear-cache +COPY config.sql /usr/src/flarum/config.sql COPY nginx.conf /etc/nginx/nginx.conf COPY php-fpm.conf /etc/php7/php-fpm.conf COPY supervisord.conf /etc/supervisor/supervisord.conf +COPY startup /usr/local/bin/startup +RUN chmod +x /usr/local/bin/startup +VOLUME /flarum EXPOSE 8080 -CMD ["/usr/bin/tini","--","supervisord","-c","/etc/supervisor/supervisord.conf"] +CMD ["/usr/bin/tini","--","startup"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..5125b22 --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# mondedie/flarum + +![logo](https://i.imgur.com/Bjrtbsc.png "logo") + +### What is this ? + +Flarum is the next-generation forum software that makes online discussion fun. It's simple, fast, and free. + +### Features + +- Based on Alpine Linux 3.4 with **nginx** and **PHP 7** +- Latest Flarum Beta (v0.1.0-beta.5) +- MySQL/Mariadb driver + +### Build-time variables + +- **VERSION** : Version of flarum (default *v0.1.0-beta.5*) + +### Environment variables + +- **GID** = vmail user id (*optional*, default: 991) +- **UID** = vmail user id (*optional*, default: 991) +- **FORUM_URL** = Forum URL (**required**) +- **DB_HOST** = MariaDB instance ip/hostname (*optional*, default: mariadb) +- **DB_USER** = MariaDB database username (*optional*, default: flarum) +- **DB_NAME** = MariaDB database name (*optional*, default: flarum) +- **DB_PASS** = MariaDB database password (**required**) +- **MAIL_FROM** = Mail 'from address' (*optional*, default: null) +- **MAIL_HOST** = Mail server FQDN (*optional*, default: null) +- **MAIL_PORT** = Mail server smtp port (*optional*, default: null) +- **MAIL_ENCR** = Encryption protocol (*optional*, default: null) +- **MAIL_USER** = Username (*optional*, default: null) +- **MAIL_PASS** = Password (*optional*, default: null) + +#### Mail settings example : + +``` +MAIL_FROM = noreply@domain.tld +MAIL_HOST = mail.domain.tld +MAIL_PORT = 25 or 465 or 587 +MAIL_ENCR = ssl (465) or tls (587) +MAIL_USER = contact@domain.tld +MAIL_PASS = xxxxxxxx +``` + +### Volume + +* /flarum : Flarum directory + +### Docker-compose + +#### Docker-compose.yml + +``` +flarum: + image: flarum + container_name: mondedie/flarum + links: + - mariadb:mariadb + environment: + - DB_PASS=yyyyyyyy + - FORUM_URL=https://forum.domain.tld/ + - MAIL_FROM=noreply@domain.tld + - MAIL_HOST=mail.domain.tld + - MAIL_PORT=465 + - MAIL_USER=noreply@domain.tld + - MAIL_PASS=zzzzzzzz + - MAIL_ENCR=ssl + volumes: + - /mnt/docker/flarum:/flarum + +mariadb: + image: mariadb:10.1 + container_name: mariadb + volumes: + - /mnt/docker/mysql/db:/var/lib/mysql + environment: + - MYSQL_ROOT_PASSWORD=xxxxxxxx + - MYSQL_DATABASE=flarum + - MYSQL_USER=flarum + - MYSQL_PASSWORD=yyyyyyyy + +``` + +#### Run ! + +``` +docker-compose up -d +``` + +### Default account + +* **Username** : *admin* +* **Password** : *password* + +### Configuration file + +The main configuration file is located here : **/mnt/docker/flarum/config.php** diff --git a/config.sql b/config.sql new file mode 100644 index 0000000..19a0d4e --- /dev/null +++ b/config.sql @@ -0,0 +1,9 @@ +INSERT INTO `flarum`.`settings`(`key`,`value`) VALUES + ('mail_host','{{ MAIL_HOST }}'), + ('mail_port','{{ MAIL_PORT }}'), + ('mail_username','{{ MAIL_USER }}'), + ('mail_password','{{ MAIL_PASS }}'), + ('mail_encryption','{{ MAIL_ENCR }}'); + +UPDATE `flarum`.`settings` SET `value`='smtp' WHERE `key`='mail_driver'; +UPDATE `flarum`.`settings` SET `value`='{{ MAIL_FROM }}' WHERE `key`='mail_from'; diff --git a/nginx.conf b/nginx.conf index ab9b74e..e5ce4fe 100644 --- a/nginx.conf +++ b/nginx.conf @@ -48,7 +48,7 @@ http { server { listen 8080; - root /flarum/app; + root /flarum; index index.php; access_log /var/log/nginx/access.log; diff --git a/startup b/startup new file mode 100644 index 0000000..9d845e0 --- /dev/null +++ b/startup @@ -0,0 +1,58 @@ +#!/bin/sh + +if [ -z "$DB_PASS" ]; then + echo "[ERROR] Mariadb database password must be set !" + exit 1 +fi + +if [ -z "$FORUM_URL" ]; then + echo "[ERROR] Forum url must be set !" + exit 1 +fi + +if [ ! -e '/flarum/config.php' ]; then + +cat > /usr/src/flarum/config.yml < \$app->make('flarum.config')\]|['config' => \$app->isInstalled() ? \$app->make('flarum.config') : []]|g" /usr/src/flarum/vendor/flarum/core/src/Console/Server.php + +# Copy flarum src to final dir +mv /usr/src/flarum/* /flarum && cd /flarum + +# Install flarum (migrate database + assets) +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, launch app..." +fi + +# Set permissions +chown -R flarum:flarum /flarum + +# RUN ! +supervisord -c /etc/supervisor/supervisord.conf