refactor(): persist state of the forum

pull/3/head
Hardware 2016-07-17 11:35:13 +02:00
parent 6f1bb34076
commit 849ee28b60
No known key found for this signature in database
GPG Key ID: EC6DF6F90263EDEA
5 changed files with 183 additions and 8 deletions

View File

@ -2,7 +2,13 @@ FROM xataz/alpine:3.4
MAINTAINER xataz <https://github.com/xataz> MAINTAINER xataz <https://github.com/xataz>
MAINTAINER hardware <https://github.com/hardware> MAINTAINER hardware <https://github.com/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 \ RUN echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& export BUILD_DEPS="git" \ && export BUILD_DEPS="git" \
@ -10,6 +16,7 @@ RUN echo "@testing https://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/r
nginx \ nginx \
curl \ curl \
supervisor \ supervisor \
mariadb-client \
php7-phar@testing \ php7-phar@testing \
php7-fpm@testing \ php7-fpm@testing \
php7-curl@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 \ && curl -s http://getcomposer.org/installer | php \
&& mv /tmp/composer.phar /usr/bin/composer \ && mv /tmp/composer.phar /usr/bin/composer \
&& chmod +x /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 \ && addgroup -g ${GID} flarum && adduser -h /flarum -s /bin/sh -D -G flarum -u ${UID} flarum \
&& chown flarum:flarum /flarum \ && chown flarum:flarum /flarum /usr/src/flarum \
&& su-exec flarum:flarum composer create-project flarum/flarum /flarum/app --stability=beta \ && su-exec flarum:flarum composer create-project flarum/flarum /usr/src/flarum $VERSION --stability=beta \
&& composer clear-cache \ && composer clear-cache
&& rm -rf /flarum/.composer/cache/*
COPY config.sql /usr/src/flarum/config.sql
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
COPY php-fpm.conf /etc/php7/php-fpm.conf COPY php-fpm.conf /etc/php7/php-fpm.conf
COPY supervisord.conf /etc/supervisor/supervisord.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 EXPOSE 8080
CMD ["/usr/bin/tini","--","supervisord","-c","/etc/supervisor/supervisord.conf"] CMD ["/usr/bin/tini","--","startup"]

98
README.md Normal file
View File

@ -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**

9
config.sql Normal file
View File

@ -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';

View File

@ -48,7 +48,7 @@ http {
server { server {
listen 8080; listen 8080;
root /flarum/app; root /flarum;
index index.php; index index.php;
access_log /var/log/nginx/access.log; access_log /var/log/nginx/access.log;

58
startup Normal file
View File

@ -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 <<EOF
databaseConfiguration:
driver: mysql
host: ${DB_HOST}
database: ${DB_NAME}
username: ${DB_USER}
password: ${DB_PASS}
baseUrl: ${FORUM_URL}
EOF
# 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" /usr/src/flarum/config.sql
# Fix installer, wait fix in beta 6
# PHP Fatal error: Uncaught ReflectionException: Class flarum.config does not
# exist in /flarum/vendor/illuminate/container/Container.php
# https://github.com/flarum/core/commit/7192c4391bee006ccc2de3db6caa89803d72d130
sed -i -e 's|InfoCommand::class,||g' \
-e "s|\['config' => \$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