From 0700d32a6ffc3e482bb002b538bda7c6e91ca691 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 9 Jun 2018 13:52:13 +0200 Subject: [PATCH 01/23] Add an apache build --- Dockerfile.apache | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Dockerfile.apache diff --git a/Dockerfile.apache b/Dockerfile.apache new file mode 100644 index 000000000..5cc31d739 --- /dev/null +++ b/Dockerfile.apache @@ -0,0 +1,31 @@ +FROM php:7-apache + +ARG COMPOSER_VERSION="1.6.5" +ARG COMPOSER_CHECKSUM="67bebe9df9866a795078bb2cf21798d8b0214f2e0b2fd81f2e907a8ef0be3434" + +RUN apt-get update \ + && apt-get install -y --no-install-recommends libmagickwand-dev git \ + && docker-php-ext-install pdo_mysql pcntl \ + && pecl install imagick \ + && docker-php-ext-enable imagick pcntl imagick \ + && curl -LsS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar -o /tmp/composer.phar \ + && echo "${COMPOSER_CHECKSUM} /tmp/composer.phar" | sha256sum -c - \ + && install -m0755 -o root -g root /tmp/composer.phar /usr/bin/composer.phar \ + && ln -sf /usr/bin/composer.phar /usr/bin/composer \ + && rm /tmp/composer.phar + +COPY . /var/www/html/ + +WORKDIR /var/www/html +RUN install -d -m0755 -o www-data -g www-data \ + /var/www/html/storage \ + /var/www/html/storage/framework \ + /var/www/html/storage/logs \ + /var/www/html/storage/framework/sessions \ + /var/www/html/storage/framework/views \ + /var/www/html/storage/framework/cache && \ + composer install --prefer-source --no-interaction + +VOLUME ["/var/www/html"] + +ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" From d76851732a91256026cabf3dd2dca7e7debea820 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 9 Jun 2018 15:18:44 +0200 Subject: [PATCH 02/23] Set a proper path for public documents --- Dockerfile.apache | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile.apache b/Dockerfile.apache index 5cc31d739..e41ffd1b2 100644 --- a/Dockerfile.apache +++ b/Dockerfile.apache @@ -14,18 +14,19 @@ RUN apt-get update \ && ln -sf /usr/bin/composer.phar /usr/bin/composer \ && rm /tmp/composer.phar -COPY . /var/www/html/ +COPY . /var/www/ -WORKDIR /var/www/html +WORKDIR /var/www/ RUN install -d -m0755 -o www-data -g www-data \ - /var/www/html/storage \ - /var/www/html/storage/framework \ - /var/www/html/storage/logs \ - /var/www/html/storage/framework/sessions \ - /var/www/html/storage/framework/views \ - /var/www/html/storage/framework/cache && \ - composer install --prefer-source --no-interaction + /var/www/storage \ + /var/www/storage/framework \ + /var/www/storage/logs \ + /var/www/storage/framework/sessions \ + /var/www/storage/framework/views \ + /var/www/storage/framework/cache \ + && composer install --prefer-source --no-interaction \ + && rm -rf html && mv public html -VOLUME ["/var/www/html"] +VOLUME ["/var/www/storage"] ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" From b005b3a22cf73f74650660fb4603cabfe96ffc0a Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 9 Jun 2018 17:41:26 +0200 Subject: [PATCH 03/23] Link html to public instead of renaming --- Dockerfile.apache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.apache b/Dockerfile.apache index e41ffd1b2..7b00d420e 100644 --- a/Dockerfile.apache +++ b/Dockerfile.apache @@ -25,7 +25,7 @@ RUN install -d -m0755 -o www-data -g www-data \ /var/www/storage/framework/views \ /var/www/storage/framework/cache \ && composer install --prefer-source --no-interaction \ - && rm -rf html && mv public html + && rm -rf html && ln -s public html VOLUME ["/var/www/storage"] From be13d1aa980934919a76b8226ea8a5f5701c05a5 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 9 Jun 2018 17:45:57 +0200 Subject: [PATCH 04/23] Enable apache rewrite mod --- Dockerfile.apache | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile.apache b/Dockerfile.apache index 7b00d420e..bc26b7e54 100644 --- a/Dockerfile.apache +++ b/Dockerfile.apache @@ -8,6 +8,7 @@ RUN apt-get update \ && docker-php-ext-install pdo_mysql pcntl \ && pecl install imagick \ && docker-php-ext-enable imagick pcntl imagick \ + && a2enmod rewrite \ && curl -LsS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar -o /tmp/composer.phar \ && echo "${COMPOSER_CHECKSUM} /tmp/composer.phar" | sha256sum -c - \ && install -m0755 -o root -g root /tmp/composer.phar /usr/bin/composer.phar \ From 1af0b8abbb0da9eaf5a78467d581e9563bbef984 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sun, 10 Jun 2018 20:06:22 +0200 Subject: [PATCH 05/23] Configure trust proxies --- config/trustproxies.php | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 config/trustproxies.php diff --git a/config/trustproxies.php b/config/trustproxies.php new file mode 100644 index 000000000..44ddf94a8 --- /dev/null +++ b/config/trustproxies.php @@ -0,0 +1,56 @@ +getClientIp() + * always gets the originating client IP, no matter + * how many proxies that client's request has + * subsequently passed through. + */ + 'proxies' => explode(env('TRUST_PROXIES', ''), ','), + + /* + * Default Header Names + * + * Change these if the proxy does + * not send the default header names. + * + * Note that headers such as X-Forwarded-For + * are transformed to HTTP_X_FORWARDED_FOR format. + * + * The following are Symfony defaults, found in + * \Symfony\Component\HttpFoundation\Request::$trustedHeaders + * + * You may optionally set headers to 'null' here if you'd like + * for them to be considered untrusted instead. Ex: + * + * Illuminate\Http\Request::HEADER_CLIENT_HOST => null, + * + * WARNING: If you're using AWS Elastic Load Balancing or Heroku, + * the FORWARDED and X_FORWARDED_HOST headers should be set to null + * as they are currently unsupported there. + */ + 'headers' => [ + (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => 'FORWARDED', + Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', + Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', + Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', + Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', + ] +]; From eddeb5e7886793a9d4c6268338695445f09c7acc Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Tue, 12 Jun 2018 20:49:52 +0200 Subject: [PATCH 06/23] Improve the support for a trust proxy --- config/trustedproxy.php | 27 ++++++++++++++++++++ config/trustproxies.php | 56 ----------------------------------------- 2 files changed, 27 insertions(+), 56 deletions(-) create mode 100644 config/trustedproxy.php delete mode 100644 config/trustproxies.php diff --git a/config/trustedproxy.php b/config/trustedproxy.php new file mode 100644 index 000000000..c1760266c --- /dev/null +++ b/config/trustedproxy.php @@ -0,0 +1,27 @@ +getClientIp() + * always gets the originating client IP, no matter + * how many proxies that client's request has + * subsequently passed through. + */ + 'proxies' => explode(env('TRUST_PROXIES', ''), ','), +]; diff --git a/config/trustproxies.php b/config/trustproxies.php deleted file mode 100644 index 44ddf94a8..000000000 --- a/config/trustproxies.php +++ /dev/null @@ -1,56 +0,0 @@ -getClientIp() - * always gets the originating client IP, no matter - * how many proxies that client's request has - * subsequently passed through. - */ - 'proxies' => explode(env('TRUST_PROXIES', ''), ','), - - /* - * Default Header Names - * - * Change these if the proxy does - * not send the default header names. - * - * Note that headers such as X-Forwarded-For - * are transformed to HTTP_X_FORWARDED_FOR format. - * - * The following are Symfony defaults, found in - * \Symfony\Component\HttpFoundation\Request::$trustedHeaders - * - * You may optionally set headers to 'null' here if you'd like - * for them to be considered untrusted instead. Ex: - * - * Illuminate\Http\Request::HEADER_CLIENT_HOST => null, - * - * WARNING: If you're using AWS Elastic Load Balancing or Heroku, - * the FORWARDED and X_FORWARDED_HOST headers should be set to null - * as they are currently unsupported there. - */ - 'headers' => [ - (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => 'FORWARDED', - Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', - Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', - Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', - Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', - ] -]; From b412616c285cd0258c469956d38aaf52670034dc Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Tue, 12 Jun 2018 20:56:42 +0200 Subject: [PATCH 07/23] Add a start script and automatically migrate the db --- Dockerfile.apache => docker/Dockerfile.apache | 2 ++ Dockerfile => docker/Dockerfile.fpm | 0 docker/start.sh | 6 ++++++ 3 files changed, 8 insertions(+) rename Dockerfile.apache => docker/Dockerfile.apache (97%) rename Dockerfile => docker/Dockerfile.fpm (100%) create mode 100755 docker/start.sh diff --git a/Dockerfile.apache b/docker/Dockerfile.apache similarity index 97% rename from Dockerfile.apache rename to docker/Dockerfile.apache index bc26b7e54..8450d7792 100644 --- a/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -31,3 +31,5 @@ RUN install -d -m0755 -o www-data -g www-data \ VOLUME ["/var/www/storage"] ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" + +CMD /var/www/docker/start.sh diff --git a/Dockerfile b/docker/Dockerfile.fpm similarity index 100% rename from Dockerfile rename to docker/Dockerfile.fpm diff --git a/docker/start.sh b/docker/start.sh new file mode 100755 index 000000000..bbf6327be --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +mkdir -p storage/framework/{cache,sessions,views,logs} +php artisan migrate + +exec apache2-foreground From 91a8f919de189554baf753f0ca1182f34da03665 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Tue, 12 Jun 2018 21:48:14 +0200 Subject: [PATCH 08/23] Fix a typo in the proxy configuration --- config/trustedproxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/trustedproxy.php b/config/trustedproxy.php index c1760266c..0a0776ada 100644 --- a/config/trustedproxy.php +++ b/config/trustedproxy.php @@ -23,5 +23,5 @@ return [ * how many proxies that client's request has * subsequently passed through. */ - 'proxies' => explode(env('TRUST_PROXIES', ''), ','), + 'proxies' => explode(',', env('TRUST_PROXIES', '')), ]; From 9cc3406a12285d60e546efaaca031c24b6ef248b Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Tue, 12 Jun 2018 22:48:43 +0200 Subject: [PATCH 09/23] Create missing directories in storage --- docker/start.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/start.sh b/docker/start.sh index bbf6327be..962bcb6f7 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,6 +1,8 @@ #!/bin/sh -mkdir -p storage/framework/{cache,sessions,views,logs} +mkdir -p storage/app/public/avatars +mkdir -p storage/{debugbar,logs} +mkdir -p storage/framework/{cache,sessions,views,testing} php artisan migrate exec apache2-foreground From ecd867fa304d7feed22f83202e64a341be5be63b Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 09:02:46 +0200 Subject: [PATCH 10/23] Add a Dockerfile symlink for automated builds --- Dockerfile | 1 + 1 file changed, 1 insertion(+) create mode 120000 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 120000 index 000000000..098369ddb --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +docker/Dockerfile.apache \ No newline at end of file From 964b8e5d6365582bb6fbbe12edb910c8029d0a03 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 09:50:38 +0200 Subject: [PATCH 11/23] Handle storage folder creation properly --- docker/Dockerfile.apache | 8 +++++--- docker/start.sh | 8 +++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 8450d7792..9839ad303 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -5,7 +5,7 @@ ARG COMPOSER_CHECKSUM="67bebe9df9866a795078bb2cf21798d8b0214f2e0b2fd81f2e907a8ef RUN apt-get update \ && apt-get install -y --no-install-recommends libmagickwand-dev git \ - && docker-php-ext-install pdo_mysql pcntl \ + && docker-php-ext-install pdo_mysql pcntl gd \ && pecl install imagick \ && docker-php-ext-enable imagick pcntl imagick \ && a2enmod rewrite \ @@ -15,6 +15,8 @@ RUN apt-get update \ && ln -sf /usr/bin/composer.phar /usr/bin/composer \ && rm /tmp/composer.phar +ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" + COPY . /var/www/ WORKDIR /var/www/ @@ -25,11 +27,11 @@ RUN install -d -m0755 -o www-data -g www-data \ /var/www/storage/framework/sessions \ /var/www/storage/framework/views \ /var/www/storage/framework/cache \ + && cp -r storage storage.skel \ + && cp docker/env .env \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html VOLUME ["/var/www/storage"] -ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" - CMD /var/www/docker/start.sh diff --git a/docker/start.sh b/docker/start.sh index 962bcb6f7..5925d3f28 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,8 +1,6 @@ -#!/bin/sh +#!/bin/bash -mkdir -p storage/app/public/avatars -mkdir -p storage/{debugbar,logs} -mkdir -p storage/framework/{cache,sessions,views,testing} -php artisan migrate +cp -r storage.skel/* storage/ +php artisan migrate --force exec apache2-foreground From b956675977ef8bd8ab9642b3ed16a84ea45dd0ad Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 09:58:56 +0200 Subject: [PATCH 12/23] Add missing env file --- docker/env | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docker/env diff --git a/docker/env b/docker/env new file mode 100644 index 000000000..03a4edb9f --- /dev/null +++ b/docker/env @@ -0,0 +1,49 @@ +APP_NAME="${APP_NAME}" +APP_ENV=local +APP_KEY="${APP_KEY}" +APP_DEBUG=false +APP_URL=${APP_URL} + +LOG_CHANNEL=stack + +DB_CONNECTION=mysql +DB_HOST=${DB_HOST} +DB_PORT=3306 +DB_DATABASE="${DB_DATABASE}" +DB_USERNAME="${DB_USERNAME}" +DB_PASSWORD="${DB_PASSWORD}" + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +SESSION_LIFETIME=120 +QUEUE_DRIVER=sync + +REDIS_HOST="${REDIS_HOST}" +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=${MAIL_HOST} +MAIL_PORT="${MAIL_PORT}" +MAIL_USERNAME="${MAIL_USERNAME}" +MAIL_PASSWORD="${MAIL_PASSWORD}" +MAIL_ENCRYPTION="${MAIL_ENCRYPTION}" + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +SESSION_DOMAIN="${SESSION_DOMAIN}" +SESSION_SECURE_COOKIE=true +API_BASE="/api/1/" +API_SEARCH="/api/search" + +OPEN_REGISTRATION=true + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +MIX_APP_URL="${APP_URL}" +MIX_API_BASE="${API_BASE}" +MIX_API_SEARCH="${API_SEARCH}" From 862e9231d1d8ca05a86164c6649332edc6e646c5 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 10:35:38 +0200 Subject: [PATCH 13/23] Use the storage structure from git --- .dockerignore | 1 - docker/Dockerfile.apache | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index e47e3356b..559772097 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -storage data Dockerfile docker-compose*.yml diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 9839ad303..0a95c2f81 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -20,13 +20,8 @@ ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" COPY . /var/www/ WORKDIR /var/www/ -RUN install -d -m0755 -o www-data -g www-data \ - /var/www/storage \ - /var/www/storage/framework \ - /var/www/storage/logs \ - /var/www/storage/framework/sessions \ - /var/www/storage/framework/views \ - /var/www/storage/framework/cache \ +RUN find storage -name .gitignore -exec rm {} + \ + && chown -R www-data:www-data /var/www/storage && cp -r storage storage.skel \ && cp docker/env .env \ && composer install --prefer-source --no-interaction \ From a70ec47ef1ccad10d7b5c255bc2eb08122417159 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 12:23:13 +0200 Subject: [PATCH 14/23] Build gd with jpeg support --- docker/Dockerfile.apache | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 0a95c2f81..16f80aa6d 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -5,8 +5,14 @@ ARG COMPOSER_CHECKSUM="67bebe9df9866a795078bb2cf21798d8b0214f2e0b2fd81f2e907a8ef RUN apt-get update \ && apt-get install -y --no-install-recommends libmagickwand-dev git \ + libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libvpx-dev \ && docker-php-ext-install pdo_mysql pcntl gd \ && pecl install imagick \ + && docker-php-ext-configure gd \ + --with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \ + --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \ + --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \ + --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \ && docker-php-ext-enable imagick pcntl imagick \ && a2enmod rewrite \ && curl -LsS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar -o /tmp/composer.phar \ @@ -21,7 +27,7 @@ COPY . /var/www/ WORKDIR /var/www/ RUN find storage -name .gitignore -exec rm {} + \ - && chown -R www-data:www-data /var/www/storage + && chown -R www-data:www-data /var/www/storage \ && cp -r storage storage.skel \ && cp docker/env .env \ && composer install --prefer-source --no-interaction \ From 583abdf37a1718725860eccd5c07f5a0729b8cda Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 22:27:45 +0200 Subject: [PATCH 15/23] Include missing dependencies for image optimization, slim the image and run horizon --- docker/Dockerfile.apache | 29 ++++++++++++++++------------- docker/env | 11 ++++++++++- docker/start.sh | 3 +++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 16f80aa6d..ce9afc73b 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -4,31 +4,34 @@ ARG COMPOSER_VERSION="1.6.5" ARG COMPOSER_CHECKSUM="67bebe9df9866a795078bb2cf21798d8b0214f2e0b2fd81f2e907a8ef0be3434" RUN apt-get update \ - && apt-get install -y --no-install-recommends libmagickwand-dev git \ - libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libvpx-dev \ - && docker-php-ext-install pdo_mysql pcntl gd \ - && pecl install imagick \ + && apt-get install -y --no-install-recommends git \ + optipng pngquant jpegoptim gifsicle \ + libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4 libmagickwand-6.q16-3 \ + libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libvpx-dev libmagickwand-dev \ + && docker-php-source extract \ && docker-php-ext-configure gd \ --with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \ --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \ --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \ --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \ - && docker-php-ext-enable imagick pcntl imagick \ + && docker-php-ext-install pdo_mysql pcntl gd exif \ + && pecl install imagick \ + && docker-php-ext-enable imagick pcntl imagick gd exif \ && a2enmod rewrite \ - && curl -LsS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar -o /tmp/composer.phar \ - && echo "${COMPOSER_CHECKSUM} /tmp/composer.phar" | sha256sum -c - \ - && install -m0755 -o root -g root /tmp/composer.phar /usr/bin/composer.phar \ - && ln -sf /usr/bin/composer.phar /usr/bin/composer \ - && rm /tmp/composer.phar + && curl -LsS https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar -o /usr/bin/composer \ + && echo "${COMPOSER_CHECKSUM} /usr/bin/composer" | sha256sum -c - \ + && chmod 755 /usr/bin/composer \ + && apt-get autoremove --purge -y \ + libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxpm-dev libvpx-dev libmagickwand-dev \ + && rm -rf /var/cache/apt \ + && docker-php-source delete ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" COPY . /var/www/ WORKDIR /var/www/ -RUN find storage -name .gitignore -exec rm {} + \ - && chown -R www-data:www-data /var/www/storage \ - && cp -r storage storage.skel \ +RUN cp -r storage storage.skel \ && cp docker/env .env \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html diff --git a/docker/env b/docker/env index 03a4edb9f..0f2f9c597 100644 --- a/docker/env +++ b/docker/env @@ -40,7 +40,16 @@ SESSION_SECURE_COOKIE=true API_BASE="/api/1/" API_SEARCH="/api/search" -OPEN_REGISTRATION=true +OPEN_REGISTRATION=${OPEN_REGISTRATION} +MAX_CAPTION_LENGTH=${MAX_CAPTION_LENGTH} +MAX_PHOTO_SIZE=${MAX_PHOTO_SIZE} +ENFORCE_EMAIL_VERIFICATION=${ENFORCE_EMAIL_VERIFICATION} +REMOTE_FOLLOW=${REMOTE_FOLLOW} +ACTIVITY_PUB=${ACTIVITY_PUB} + +RECAPTCHA_ENABLED=${RECAPTCHA_ENABLED} +RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY} +RECAPTCHA_PRIVATE_KEY=${RECAPTCHA_PRIVATE_KEY} MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/docker/start.sh b/docker/start.sh index 5925d3f28..e716d8ee0 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,6 +1,9 @@ #!/bin/bash cp -r storage.skel/* storage/ +chown -R www-data:www-data storage/ php artisan migrate --force +php artisan storage:link +php artisan horizon & exec apache2-foreground From 4998830fa1d0de7629447f732543ae6103cb4a7c Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 22:31:16 +0200 Subject: [PATCH 16/23] Update the docker compose to use the apache image --- docker-compose.yml | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8e9ccd4c1..3867c2029 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,35 +1,28 @@ --- version: '3' services: - nginx: - image: nginx:alpine - networks: - - internal - - external - ports: - - 3000:80 - volumes: - - "php-storage:/var/www/html" - - ./contrib/nginx.conf:/etc/nginx/conf.d/default.conf - depends_on: - - php - php: + pixelfed: build: . image: pixelfed volumes: - "php-storage:/var/www/html" networks: + - external - internal environment: + # The full list of available variables is documented in docker/env - DB_HOST=mysql - DB_DATABASE=pixelfed - DB_USERNAME=${DB_USERNAME:-pixelfed} - DB_PASSWORD=${DB_PASSWORD:-pixelfed} - REDIS_HOST=redis - - APP_KEY=${APP_KEY} - env_file: - - ./.env + - APP_KEY=SetYourAppKeyHere + - APP_NAME=Pixelfed + - APP_URL=https://your.url + - MAIL_HOST=mail.host + - MAIL_FROM_ADDRESS=noreply@your.url + - MAIL_FROM_NAME=Pixelfed mysql: image: mysql:5.7 @@ -40,8 +33,6 @@ services: - MYSQL_USER=${DB_USERNAME:-pixelfed} - MYSQL_PASSWORD=${DB_PASSWORD:-pixelfed} - MYSQL_RANDOM_ROOT_PASSWORD="true" - env_file: - - ./.env volumes: - "mysql-data:/var/lib/mysql" From d327aeba2b74d171ebbb640c9c9fb1c2e311677f Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sat, 16 Jun 2018 23:51:33 +0200 Subject: [PATCH 17/23] Enable redis queuing by default and link horizon properly --- docker/env | 5 +++-- docker/start.sh | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docker/env b/docker/env index 0f2f9c597..a42252474 100644 --- a/docker/env +++ b/docker/env @@ -4,7 +4,7 @@ APP_KEY="${APP_KEY}" APP_DEBUG=false APP_URL=${APP_URL} -LOG_CHANNEL=stack +LOG_CHANNEL=stderr DB_CONNECTION=mysql DB_HOST=${DB_HOST} @@ -17,7 +17,8 @@ BROADCAST_DRIVER=log CACHE_DRIVER=file SESSION_DRIVER=file SESSION_LIFETIME=120 -QUEUE_DRIVER=sync +QUEUE_DRIVER=redis +HORIZON_PREFIX=horizon-pixelfed REDIS_HOST="${REDIS_HOST}" REDIS_PASSWORD=null diff --git a/docker/start.sh b/docker/start.sh index e716d8ee0..a2165980e 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,5 +1,9 @@ #!/bin/bash +set -o allexport +source .env +set +o allexport + cp -r storage.skel/* storage/ chown -R www-data:www-data storage/ php artisan migrate --force From cce25eb77123d1608a995a6097ace64572e7d7ba Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sun, 17 Jun 2018 10:20:21 +0200 Subject: [PATCH 18/23] Use environment variables only (no .env file) and separate horizon --- docker-compose.yml | 63 +++++++++++++++++++++++++--------------- docker/Dockerfile.apache | 19 +++++++++++- docker/env | 59 ------------------------------------- docker/start.sh | 16 ++++++---- 4 files changed, 68 insertions(+), 89 deletions(-) delete mode 100644 docker/env diff --git a/docker-compose.yml b/docker-compose.yml index 3867c2029..884b8bd4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,40 +1,56 @@ --- version: '3' + +# In order to set configuration, please use a .env file in +# your compose project directory (the same directory as your +# docker-compose.yml), and set database options, application +# name, key, and other settings there. +# A list of available settings is available in .env.example +# +# The services should scale properly across a swarm cluster +# if the volumes are properly shared between cluster members. + services: - pixelfed: - build: . + app: + # Uncomment to build a local copy of the image + # build: . image: pixelfed + # If you have a traefik running, uncomment this to expose Pixelfed + # labels: + # - traefik.enable=true + # - traefik.frontend.rule=Host:your.url + # - traefik.port=80 + env_file: + - ./.env volumes: - - "php-storage:/var/www/html" + - "app-storage:/var/www/storage" networks: - external - internal - environment: - # The full list of available variables is documented in docker/env - - DB_HOST=mysql - - DB_DATABASE=pixelfed - - DB_USERNAME=${DB_USERNAME:-pixelfed} - - DB_PASSWORD=${DB_PASSWORD:-pixelfed} - - REDIS_HOST=redis - - APP_KEY=SetYourAppKeyHere - - APP_NAME=Pixelfed - - APP_URL=https://your.url - - MAIL_HOST=mail.host - - MAIL_FROM_ADDRESS=noreply@your.url - - MAIL_FROM_NAME=Pixelfed - mysql: + # Uncomment if you set HORIZON_EMBED to false and wish to run a local worker + # worker: + # image: pixelfed + # env_file: + # - ./.env + # volumes: + # - "app-storage:/var/www/storage" + # networks: + # - internal + # command: php artisan horizon + + db: image: mysql:5.7 networks: - internal environment: - MYSQL_DATABASE=pixelfed - - MYSQL_USER=${DB_USERNAME:-pixelfed} - - MYSQL_PASSWORD=${DB_PASSWORD:-pixelfed} - - MYSQL_RANDOM_ROOT_PASSWORD="true" + - MYSQL_USER=${DB_USERNAME} + - MYSQL_PASSWORD=${DB_PASSWORD} + - MYSQL_RANDOM_ROOT_PASSWORD=true volumes: - - "mysql-data:/var/lib/mysql" + - "db-data:/var/lib/mysql" redis: image: redis:alpine @@ -43,10 +59,11 @@ services: networks: - internal +# Adjust your volume data in order to store data where you wish volumes: redis-data: - mysql-data: - php-storage: + db-data: + app-storage: networks: internal: diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index ce9afc73b..03cbbddfc 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -32,10 +32,27 @@ COPY . /var/www/ WORKDIR /var/www/ RUN cp -r storage storage.skel \ - && cp docker/env .env \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html VOLUME ["/var/www/storage"] +ENV APP_ENV=production \ + APP_DEBUG=false \ + LOG_CHANNEL=stderr \ + DB_CONNECTION=mysql \ + DB_PORT=3306 \ + DB_HOST=db \ + BROADCAST_DRIVER=log \ + QUEUE_DRIVER=redis \ + HORIZON_PREFIX=horizon-pixelfed \ + REDIS_HOST=redis \ + SESSION_SECURE_COOKIE=true \ + API_BASE="/api/1/" \ + API_SEARCH="/api/search" \ + OPEN_REGISTRATION=true \ + ENFORCE_EMAIL_VERIFICATION=true \ + REMOTE_FOLLOW=false \ + ACTIVITY_PUB=false + CMD /var/www/docker/start.sh diff --git a/docker/env b/docker/env deleted file mode 100644 index a42252474..000000000 --- a/docker/env +++ /dev/null @@ -1,59 +0,0 @@ -APP_NAME="${APP_NAME}" -APP_ENV=local -APP_KEY="${APP_KEY}" -APP_DEBUG=false -APP_URL=${APP_URL} - -LOG_CHANNEL=stderr - -DB_CONNECTION=mysql -DB_HOST=${DB_HOST} -DB_PORT=3306 -DB_DATABASE="${DB_DATABASE}" -DB_USERNAME="${DB_USERNAME}" -DB_PASSWORD="${DB_PASSWORD}" - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -SESSION_DRIVER=file -SESSION_LIFETIME=120 -QUEUE_DRIVER=redis -HORIZON_PREFIX=horizon-pixelfed - -REDIS_HOST="${REDIS_HOST}" -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_DRIVER=smtp -MAIL_HOST=${MAIL_HOST} -MAIL_PORT="${MAIL_PORT}" -MAIL_USERNAME="${MAIL_USERNAME}" -MAIL_PASSWORD="${MAIL_PASSWORD}" -MAIL_ENCRYPTION="${MAIL_ENCRYPTION}" - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -SESSION_DOMAIN="${SESSION_DOMAIN}" -SESSION_SECURE_COOKIE=true -API_BASE="/api/1/" -API_SEARCH="/api/search" - -OPEN_REGISTRATION=${OPEN_REGISTRATION} -MAX_CAPTION_LENGTH=${MAX_CAPTION_LENGTH} -MAX_PHOTO_SIZE=${MAX_PHOTO_SIZE} -ENFORCE_EMAIL_VERIFICATION=${ENFORCE_EMAIL_VERIFICATION} -REMOTE_FOLLOW=${REMOTE_FOLLOW} -ACTIVITY_PUB=${ACTIVITY_PUB} - -RECAPTCHA_ENABLED=${RECAPTCHA_ENABLED} -RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY} -RECAPTCHA_PRIVATE_KEY=${RECAPTCHA_PRIVATE_KEY} - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" -MIX_APP_URL="${APP_URL}" -MIX_API_BASE="${API_BASE}" -MIX_API_SEARCH="${API_SEARCH}" diff --git a/docker/start.sh b/docker/start.sh index a2165980e..be374a914 100755 --- a/docker/start.sh +++ b/docker/start.sh @@ -1,13 +1,17 @@ #!/bin/bash -set -o allexport -source .env -set +o allexport - +# Create the storage tree if needed and fix permissions cp -r storage.skel/* storage/ chown -R www-data:www-data storage/ -php artisan migrate --force php artisan storage:link -php artisan horizon & +# Migrate database if the app was upgraded +php artisan migrate --force + +# Run a worker if it is set as embedded +if [ HORIZON_EMBED = true ]; then + php artisan horizon & +fi + +# Finally run Apache exec apache2-foreground From a7b86d639078ac3a27cba72349959421d924e590 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Wed, 1 Aug 2018 22:36:28 +0200 Subject: [PATCH 19/23] Add the bcmath dependency, fix the Docker build --- docker/Dockerfile.apache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 03cbbddfc..9772a6833 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -14,7 +14,7 @@ RUN apt-get update \ --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \ --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \ --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \ - && docker-php-ext-install pdo_mysql pcntl gd exif \ + && docker-php-ext-install pdo_mysql pcntl gd exif bcmath \ && pecl install imagick \ && docker-php-ext-enable imagick pcntl imagick gd exif \ && a2enmod rewrite \ From 47225b99df5b24a8d853be5b6eb7f58d01e34890 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Thu, 16 Aug 2018 04:56:37 +0200 Subject: [PATCH 20/23] Provide a PHP config file to set the upload limit --- docker/php.ini | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docker/php.ini diff --git a/docker/php.ini b/docker/php.ini new file mode 100644 index 000000000..7fc73c567 --- /dev/null +++ b/docker/php.ini @@ -0,0 +1,5 @@ +file_uploads = On +memory_limit = 64M +upload_max_filesize = 64M +post_max_size = 64M +max_execution_time = 600 From 02197696dceb3871c72082899b7edf53bf71ac26 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Mon, 20 Aug 2018 15:42:49 +0200 Subject: [PATCH 21/23] Actually deploy the PHP configuration --- docker/Dockerfile.apache | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Dockerfile.apache b/docker/Dockerfile.apache index 9772a6833..ef3e2e37e 100644 --- a/docker/Dockerfile.apache +++ b/docker/Dockerfile.apache @@ -32,6 +32,7 @@ COPY . /var/www/ WORKDIR /var/www/ RUN cp -r storage storage.skel \ + && cp /var/www/docker/php.ini /usr/local/etc/php/conf.d/pixelfed.ini \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html From 5224d7cd96327eddbb7b0610914bd79da1677cd4 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Thu, 23 Aug 2018 22:43:47 +0200 Subject: [PATCH 22/23] Move Dockerfiles to contrib/ --- .dockerignore | 1 + Dockerfile | 2 +- {docker => contrib/docker}/Dockerfile.apache | 6 ++++-- {docker => contrib/docker}/Dockerfile.fpm | 0 {docker => contrib/docker}/php.ini | 0 {docker => contrib/docker}/start.sh | 0 6 files changed, 6 insertions(+), 3 deletions(-) rename {docker => contrib/docker}/Dockerfile.apache (94%) rename {docker => contrib/docker}/Dockerfile.fpm (100%) rename {docker => contrib/docker}/php.ini (100%) rename {docker => contrib/docker}/start.sh (100%) diff --git a/.dockerignore b/.dockerignore index 559772097..53c27d576 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ data +contrib Dockerfile docker-compose*.yml .dockerignore diff --git a/Dockerfile b/Dockerfile index 098369ddb..2f722aa37 120000 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1 @@ -docker/Dockerfile.apache \ No newline at end of file +contrib/docker/Dockerfile.apache \ No newline at end of file diff --git a/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache similarity index 94% rename from docker/Dockerfile.apache rename to contrib/docker/Dockerfile.apache index ef3e2e37e..7db56d9e8 100644 --- a/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -32,10 +32,12 @@ COPY . /var/www/ WORKDIR /var/www/ RUN cp -r storage storage.skel \ - && cp /var/www/docker/php.ini /usr/local/etc/php/conf.d/pixelfed.ini \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html +COPY contrib/docker/php.ini /usr/local/etc/php/conf.d/pixelfed.ini +COPY contrib/docker/start.sh /start.sh + VOLUME ["/var/www/storage"] ENV APP_ENV=production \ @@ -56,4 +58,4 @@ ENV APP_ENV=production \ REMOTE_FOLLOW=false \ ACTIVITY_PUB=false -CMD /var/www/docker/start.sh +CMD /start.sh diff --git a/docker/Dockerfile.fpm b/contrib/docker/Dockerfile.fpm similarity index 100% rename from docker/Dockerfile.fpm rename to contrib/docker/Dockerfile.fpm diff --git a/docker/php.ini b/contrib/docker/php.ini similarity index 100% rename from docker/php.ini rename to contrib/docker/php.ini diff --git a/docker/start.sh b/contrib/docker/start.sh similarity index 100% rename from docker/start.sh rename to contrib/docker/start.sh From c82d0fb3890f3b445e541feee204edccb464aa8e Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Thu, 23 Aug 2018 22:57:22 +0200 Subject: [PATCH 23/23] Fix the docker build --- .dockerignore | 2 +- contrib/docker/Dockerfile.apache | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 53c27d576..70376cdf4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ data -contrib Dockerfile +contrib/docker/Dockerfile.* docker-compose*.yml .dockerignore .git diff --git a/contrib/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache index 7db56d9e8..481db4647 100644 --- a/contrib/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -32,12 +32,10 @@ COPY . /var/www/ WORKDIR /var/www/ RUN cp -r storage storage.skel \ + && cp contrib/docker/php.ini /usr/local/etc/php/conf.d/pixelfed.ini \ && composer install --prefer-source --no-interaction \ && rm -rf html && ln -s public html -COPY contrib/docker/php.ini /usr/local/etc/php/conf.d/pixelfed.ini -COPY contrib/docker/start.sh /start.sh - VOLUME ["/var/www/storage"] ENV APP_ENV=production \ @@ -58,4 +56,4 @@ ENV APP_ENV=production \ REMOTE_FOLLOW=false \ ACTIVITY_PUB=false -CMD /start.sh +CMD /var/www/contrib/docker/start.sh