commit a27c44c92cad88a16eadc6a64aa6a82e709c7390 Author: Raoul Snyman Date: Sat Aug 5 10:42:27 2023 -0700 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..13369bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM php:cli AS build + +WORKDIR /flarum/app + +RUN apt-get update && apt-get install -y git zip unzip p7zip +RUN cd /tmp \ + && curl --progress-bar http://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + && chmod +x /usr/local/bin/composer +RUN composer create-project flarum/flarum /flarum/app + + +FROM php:apache + +WORKDIR /flarum/app + +ENV APACHE_DOCUMENT_ROOT /flarum/app/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf +RUN sed -ri -e 's!AllowOverride [Nn]one!AllowOverride All!' /etc/apache2/sites-available/*.conf +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" +RUN a2enmod rewrite + +RUN apt-get update \ + && apt-get install -y gettext libfreetype-dev libjpeg62-turbo-dev libpng-dev libpq5 libpq-dev mariadb-client libyaml-0-2 libyaml-dev \ + && pecl install yaml \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-configure pgsql --with-pgsql=/usr/local/pgsql \ + && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \ + && docker-php-ext-enable gd pdo pdo_mysql pdo_pgsql pgsql yaml \ + && apt-get autoremove --purge -y libpq-dev libyaml-dev \ + && apt-get clean + +COPY docker/make_config.php /flarum/make_config.php +COPY docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY --from=build /flarum/app /flarum/app +RUN chown -R www-data:www-data /flarum +RUN chmod a+x /usr/local/bin/docker-entrypoint.sh + +VOLUME /flarum/app/extensions /flarum/app/public/assets /flarum/app/storage/logs +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1dd5de7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' +services: + flarum: + build: . + environment: + MYSQL_DATABASE: flarum + MYSQL_USER: flarum + MYSQL_PASSWORD: flarum + MYSQL_HOST: mysql + SITE_URL: http://192.168.88.51:8000 + ADMIN_USER: raoul + ADMIN_PASSWORD: omigosh + ADMIN_EMAIL: raoul@snyman.info + MAIL_DRIVER: smtp + MAIL_HOST: mail.snyman.info + MAIL_PORT: 465 + MAIL_ENCRYPTION: ssl + MAIL_USERNAME: raoul@snyman.info + MAIL_PASSWORD: secret + ports: + - "8000:80" + depends_on: + - mysql + mysql: + image: mysql + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: flarum + MYSQL_USER: flarum + MYSQL_PASSWORD: flarum diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000..190fab9 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -e + +# Wait for MySQL/MariaDB +MAX_RETRY=45 +RETRY=1 +while ! mysql --protocol TCP -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "show databases;" > /dev/null 2>&1; do + sleep 1 + RETRY=`expr $RETRY + 1` + if [ $RETRY -gt $MAX_RETRY ]; then + >&2 echo "We have been waiting for MySQL too long already; failing." + exit 1 + fi; +done + +# Set up Flarum +if [[ -e '/flarum/app/public/assets/.installed.lock' ]]; then + # If Flarum has already been installed, just create a config file + echo "Creating config file..." + cat << EOF > /flarum/app/config.php + ${DEBUG:-false}, + 'offline' => false, + 'database' => array ( + 'driver' => 'mysql', + 'host' => '${MYSQL_HOST:-mysql}', + 'port' => '${MYSQL_PORT:-3306}', + 'database' => '${MYSQL_DATABASE:-flarum}', + 'username' => '${MYSQL_USER:-flarum}', + 'password' => '${MYSQL_PASSWORD:-flarum}', + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => false, + ), + 'url' => '${SITE_URL:-http://localhost}', + 'paths' => array ( + 'api' => 'api', + 'admin' => 'admin', + ), +); +EOF +else + # Else build the config template and run the command line installer + cd /flarum + php make_config.php + cd /flarum/app + php flarum install -f /flarum/config.yaml + rm -f /flarum/config.yaml + touch /flarum/app/public/assets/.installed.lock +fi + +# first arg is `-f` or `--some-option` +if [[ "${1#-}" != "$1" ]]; then + set -- apache2-foreground "$@" +fi + +exec "$@" diff --git a/docker/make_config.php b/docker/make_config.php new file mode 100644 index 0000000..60e08f8 --- /dev/null +++ b/docker/make_config.php @@ -0,0 +1,58 @@ + 'mysql', + 'host' => get_env('MYSQL_HOST', 'mysql'), + 'port' => get_env('MYSQL_PORT', 3306), + 'database' => get_env('MYSQL_DATABASE', 'flarum'), + 'username' => get_env('MYSQL_USER', 'flarum'), + 'password' => get_env('MYSQL_PASSWORD', 'flarum'), +); + +# Site URL +$config['baseUrl'] = get_env('SITE_URL', 'http://localhost'); + +# Admin user +if (get_env('ADMIN_PASSWORD')) { + $config['adminUser'] = array( + 'username' => get_env('ADMIN_USER', 'admin'), + 'password' => get_env('ADMIN_PASSWORD', 'password'), + 'email' => get_env('ADMIN_EMAIL', 'admin@example.com'), + ); +} + +# Other settings +$config['settings'] = array( + 'forum_title' => get_env('FORUM_TITLE', 'A new Flarum forum'), + 'forum_description' => get_env('FORUM_DESCRIPTION', ''), + 'mail_driver' => get_env('MAIL_DRIVER', 'mail'), + 'mail_from' => get_env('MAIL_FROM', 'noreply@localhost'), + 'mail_host' => get_env('MAIL_HOST', 'localhost'), + 'mail_port' => get_env('MAIL_PORT', '25'), + 'mail_encryption' => get_env('MAIL_ENCRYPTION', ''), // "tls" or "ssl" + 'mail_username' => get_env('MAIL_USERNAME'), // required + 'mail_password' => get_env('MAIL_PASSWORD'), // required + 'theme_colored_header' => get_env('THEME_COLORED_HEADER', '0'), + 'theme_dark_mode' => get_env('THEME_DARK_MODE', '0'), + 'theme_primary_color' => get_env('THEME_PRIMARY_COLOR', '#4D698E'), + 'theme_secondary_color' => get_env('THEME_SECONDARY_COLOR', '#4D698E'), + 'welcome_message' => get_env('WELCOME_MESSAGE', 'Enjoy your new forum! Hop over to discuss.flarum.org if you have any questions, or to join our community!'), + 'welcome_title' => get_env('WELCOME_TITLE', 'Welcome to Flarum'), +); + +yaml_emit_file('./config.yaml', $config);