From 1a216faecb5c114afbf36ecbac8ec3f795309eba Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sun, 9 Apr 2017 14:50:13 +0200 Subject: [PATCH] docker: switch to Alpine Linux for the master image Relates to https://github.com/shaarli/Shaarli/issues/843 Changed: - switch base image from Debian:Jessie to Alpine:3.6 - switch to PHP 7.1 - switch from supervisord to s6 to manage services See: - https://alpinelinux.org/ - https://wiki.alpinelinux.org/wiki/Nginx_with_PHP - http://www.skarnet.org/software/s6/ - http://www.skarnet.org/software/s6/s6-svscan.html - http://www.skarnet.org/software/s6/s6-svc.html - http://www.skarnet.org/software/s6/s6-svstat.html Signed-off-by: VirtualTam --- Makefile | 2 +- docker/alpine/Dockerfile.master | 47 +++++++++++++++++++ docker/{production => alpine}/IMAGE.md | 0 .../{production/stable => alpine}/nginx.conf | 5 +- docker/alpine/php-fpm.conf | 16 +++++++ docker/alpine/services.d/.s6-svscan/finish | 2 + docker/alpine/services.d/nginx/run | 2 + docker/alpine/services.d/php-fpm/run | 2 + docker/production/Dockerfile | 37 --------------- docker/production/supervised.conf | 13 ----- docker/{production => }/stable/Dockerfile | 0 docker/{production => }/stable/IMAGE.md | 0 docker/{production => stable}/nginx.conf | 0 .../{production => }/stable/supervised.conf | 0 14 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 docker/alpine/Dockerfile.master rename docker/{production => alpine}/IMAGE.md (100%) rename docker/{production/stable => alpine}/nginx.conf (94%) create mode 100644 docker/alpine/php-fpm.conf create mode 100755 docker/alpine/services.d/.s6-svscan/finish create mode 100755 docker/alpine/services.d/nginx/run create mode 100755 docker/alpine/services.d/php-fpm/run delete mode 100644 docker/production/Dockerfile delete mode 100644 docker/production/supervised.conf rename docker/{production => }/stable/Dockerfile (100%) rename docker/{production => }/stable/IMAGE.md (100%) rename docker/{production => stable}/nginx.conf (100%) rename docker/{production => }/stable/supervised.conf (100%) diff --git a/Makefile b/Makefile index a3696ec9..656c27b0 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ check_permissions: @echo "----------------------" @echo "Check file permissions" @echo "----------------------" - @for file in `git ls-files`; do \ + @for file in `git ls-files | grep -v docker`; do \ if [ -x $$file ]; then \ errors=true; \ echo "$${file} is executable"; \ diff --git a/docker/alpine/Dockerfile.master b/docker/alpine/Dockerfile.master new file mode 100644 index 00000000..58f7c6e7 --- /dev/null +++ b/docker/alpine/Dockerfile.master @@ -0,0 +1,47 @@ +FROM alpine:3.6 +MAINTAINER Shaarli Community + +RUN apk --update --no-cache add \ + ca-certificates \ + curl \ + nginx \ + php7 \ + php7-ctype \ + php7-curl \ + php7-fpm \ + php7-gd \ + php7-iconv \ + php7-intl \ + php7-json \ + php7-mbstring \ + php7-openssl \ + php7-phar \ + php7-session \ + php7-xml \ + php7-zlib \ + s6 + +COPY nginx.conf /etc/nginx/nginx.conf +COPY php-fpm.conf /etc/php7/php-fpm.conf +COPY services.d /etc/services.d + +RUN curl -sS https://getcomposer.org/installer | php7 -- --install-dir=/usr/local/bin --filename=composer \ + && rm -rf /etc/php7/php-fpm.d/www.conf \ + && sed -i 's/post_max_size.*/post_max_size = 10M/' /etc/php7/php.ini \ + && sed -i 's/upload_max_filesize.*/upload_max_filesize = 10M/' /etc/php7/php.ini + + +WORKDIR /var/www +RUN curl -L https://github.com/shaarli/Shaarli/archive/master.tar.gz | tar xzf - \ + && mv Shaarli-master shaarli \ + && cd shaarli \ + && composer --prefer-dist --no-dev install \ + && rm -rf ~/.composer \ + && chown -R nginx:nginx . + +VOLUME /var/www/shaarli/data + +EXPOSE 80 + +ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] +CMD [] diff --git a/docker/production/IMAGE.md b/docker/alpine/IMAGE.md similarity index 100% rename from docker/production/IMAGE.md rename to docker/alpine/IMAGE.md diff --git a/docker/production/stable/nginx.conf b/docker/alpine/nginx.conf similarity index 94% rename from docker/production/stable/nginx.conf rename to docker/alpine/nginx.conf index e8754d9b..07fba33f 100644 --- a/docker/production/stable/nginx.conf +++ b/docker/alpine/nginx.conf @@ -1,6 +1,7 @@ -user www-data www-data; +user nginx nginx; daemon off; worker_processes 4; +pid /var/run/nginx.pid; events { worker_connections 768; @@ -59,7 +60,7 @@ http { fastcgi_split_path_info ^(.+\.php)(/.+)$; # filter and proxy PHP requests to PHP-FPM - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } diff --git a/docker/alpine/php-fpm.conf b/docker/alpine/php-fpm.conf new file mode 100644 index 00000000..0843c164 --- /dev/null +++ b/docker/alpine/php-fpm.conf @@ -0,0 +1,16 @@ +[global] +daemonize = no + +[www] +user = nginx +group = nginx +listen.owner = nginx +listen.group = nginx +catch_workers_output = yes +listen = /var/run/php-fpm.sock +pm = dynamic +pm.max_children = 20 +pm.start_servers = 1 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 2048 diff --git a/docker/alpine/services.d/.s6-svscan/finish b/docker/alpine/services.d/.s6-svscan/finish new file mode 100755 index 00000000..1dadeeaf --- /dev/null +++ b/docker/alpine/services.d/.s6-svscan/finish @@ -0,0 +1,2 @@ +#!/bin/sh +/bin/true diff --git a/docker/alpine/services.d/nginx/run b/docker/alpine/services.d/nginx/run new file mode 100755 index 00000000..21e7b0d6 --- /dev/null +++ b/docker/alpine/services.d/nginx/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +nginx diff --git a/docker/alpine/services.d/php-fpm/run b/docker/alpine/services.d/php-fpm/run new file mode 100755 index 00000000..21dd0107 --- /dev/null +++ b/docker/alpine/services.d/php-fpm/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +php-fpm7 -F diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile deleted file mode 100644 index d0509115..00000000 --- a/docker/production/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM debian:jessie -MAINTAINER Shaarli Community - -ENV TERM dumb -RUN apt-get update \ - && apt-get install --no-install-recommends -y \ - ca-certificates \ - curl \ - nginx-light \ - php5-curl \ - php5-fpm \ - php5-gd \ - php5-intl \ - supervisor \ - && apt-get clean - -RUN sed -i 's/post_max_size.*/post_max_size = 10M/' /etc/php5/fpm/php.ini -RUN sed -i 's/upload_max_filesize.*/upload_max_filesize = 10M/' /etc/php5/fpm/php.ini -COPY nginx.conf /etc/nginx/nginx.conf -COPY supervised.conf /etc/supervisor/conf.d/supervised.conf - -ADD https://getcomposer.org/composer.phar /usr/local/bin/composer -RUN chmod 755 /usr/local/bin/composer - -WORKDIR /var/www -RUN curl -L https://github.com/shaarli/Shaarli/archive/master.tar.gz | tar xzf - \ - && mv Shaarli-master shaarli \ - && cd shaarli \ - && composer --prefer-dist --no-dev install -RUN rm -rf html \ - && chown -R www-data:www-data . - -VOLUME /var/www/shaarli/data - -EXPOSE 80 - -CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/docker/production/supervised.conf b/docker/production/supervised.conf deleted file mode 100644 index 5acd9795..00000000 --- a/docker/production/supervised.conf +++ /dev/null @@ -1,13 +0,0 @@ -[program:php5-fpm] -command=/usr/sbin/php5-fpm -F -priority=5 -autostart=true -autorestart=true - -[program:nginx] -command=/usr/sbin/nginx -priority=10 -autostart=true -autorestart=true -stdout_events_enabled=true -stderr_events_enabled=true diff --git a/docker/production/stable/Dockerfile b/docker/stable/Dockerfile similarity index 100% rename from docker/production/stable/Dockerfile rename to docker/stable/Dockerfile diff --git a/docker/production/stable/IMAGE.md b/docker/stable/IMAGE.md similarity index 100% rename from docker/production/stable/IMAGE.md rename to docker/stable/IMAGE.md diff --git a/docker/production/nginx.conf b/docker/stable/nginx.conf similarity index 100% rename from docker/production/nginx.conf rename to docker/stable/nginx.conf diff --git a/docker/production/stable/supervised.conf b/docker/stable/supervised.conf similarity index 100% rename from docker/production/stable/supervised.conf rename to docker/stable/supervised.conf