From 2a3fe990dd0730fce9465bbef6ad1a01054f775d Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sun, 17 Jun 2018 01:02:50 +0200 Subject: docker: build the images from the local sources Relates to https://github.com/shaarli/Shaarli/issues/1153 Signed-off-by: VirtualTam --- .docker/.htaccess | 13 ++++++ .docker/nginx.conf | 73 ++++++++++++++++++++++++++++++ .docker/php-fpm.conf | 16 +++++++ .docker/services.d/.s6-svscan/finish | 2 + .docker/services.d/nginx/run | 2 + .docker/services.d/php-fpm/run | 2 + .dockerignore | 51 +++++++++++++++++++++ .gitattributes | 4 +- Dockerfile | 70 ++++++++++++++++++++++++++++ Dockerfile.armhf | 49 ++++++++++++++++++++ docker/.htaccess | 13 ------ docker/alpine/Dockerfile.armhf.latest | 49 -------------------- docker/alpine/Dockerfile.armhf.master | 49 -------------------- docker/alpine/Dockerfile.latest | 54 ---------------------- docker/alpine/Dockerfile.master | 63 -------------------------- docker/alpine/IMAGE.md | 10 ---- docker/alpine/nginx.conf | 73 ------------------------------ 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 - 21 files changed, 281 insertions(+), 334 deletions(-) create mode 100644 .docker/.htaccess create mode 100644 .docker/nginx.conf create mode 100644 .docker/php-fpm.conf create mode 100755 .docker/services.d/.s6-svscan/finish create mode 100755 .docker/services.d/nginx/run create mode 100755 .docker/services.d/php-fpm/run create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Dockerfile.armhf delete mode 100644 docker/.htaccess delete mode 100644 docker/alpine/Dockerfile.armhf.latest delete mode 100644 docker/alpine/Dockerfile.armhf.master delete mode 100644 docker/alpine/Dockerfile.latest delete mode 100644 docker/alpine/Dockerfile.master delete mode 100644 docker/alpine/IMAGE.md delete mode 100644 docker/alpine/nginx.conf delete mode 100644 docker/alpine/php-fpm.conf delete mode 100755 docker/alpine/services.d/.s6-svscan/finish delete mode 100755 docker/alpine/services.d/nginx/run delete mode 100755 docker/alpine/services.d/php-fpm/run diff --git a/.docker/.htaccess b/.docker/.htaccess new file mode 100644 index 00000000..f601c1ee --- /dev/null +++ b/.docker/.htaccess @@ -0,0 +1,13 @@ + + = 2.4> + Require all denied + + + Allow from none + Deny from all + + + + + Require all denied + diff --git a/.docker/nginx.conf b/.docker/nginx.conf new file mode 100644 index 00000000..07fba33f --- /dev/null +++ b/.docker/nginx.conf @@ -0,0 +1,73 @@ +user nginx nginx; +daemon off; +worker_processes 4; +pid /var/run/nginx.pid; + +events { + worker_connections 768; +} + +http { + include mime.types; + default_type application/octet-stream; + keepalive_timeout 20; + + client_max_body_size 10m; + + index index.html index.php; + + server { + listen 80; + root /var/www/shaarli; + + access_log /var/log/nginx/shaarli.access.log; + error_log /var/log/nginx/shaarli.error.log; + + location ~ /\. { + # deny access to dotfiles + access_log off; + log_not_found off; + deny all; + } + + location ~ ~$ { + # deny access to temp editor files, e.g. "script.php~" + access_log off; + log_not_found off; + deny all; + } + + location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { + # cache static assets + expires max; + add_header Pragma public; + add_header Cache-Control "public, must-revalidate, proxy-revalidate"; + } + + location = /favicon.ico { + # serve the Shaarli favicon from its custom location + alias /var/www/shaarli/images/favicon.ico; + } + + location / { + # Slim - rewrite URLs + try_files $uri /index.php$is_args$args; + } + + location ~ (index)\.php$ { + # Slim - split URL path into (script_filename, path_info) + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + # filter and proxy PHP requests to PHP-FPM + fastcgi_pass unix:/var/run/php-fpm.sock; + fastcgi_index index.php; + include fastcgi.conf; + } + + location ~ \.php$ { + # deny access to all other PHP scripts + deny all; + } + } +} diff --git a/.docker/php-fpm.conf b/.docker/php-fpm.conf new file mode 100644 index 00000000..0843c164 --- /dev/null +++ b/.docker/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/services.d/.s6-svscan/finish b/.docker/services.d/.s6-svscan/finish new file mode 100755 index 00000000..1dadeeaf --- /dev/null +++ b/.docker/services.d/.s6-svscan/finish @@ -0,0 +1,2 @@ +#!/bin/sh +/bin/true diff --git a/.docker/services.d/nginx/run b/.docker/services.d/nginx/run new file mode 100755 index 00000000..21e7b0d6 --- /dev/null +++ b/.docker/services.d/nginx/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +nginx diff --git a/.docker/services.d/php-fpm/run b/.docker/services.d/php-fpm/run new file mode 100755 index 00000000..21dd0107 --- /dev/null +++ b/.docker/services.d/php-fpm/run @@ -0,0 +1,2 @@ +#!/bin/execlineb -P +php-fpm7 -F diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..a0d28dc6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,51 @@ +# Docker-ignore +.dev +.git +.github +tests + +# Shaarli runtime resources +cache/* +data/* +pagecache/* +tmp/* + +# Eclipse project files +.settings +.buildpath +.project + +# Raintpl generated pages +*.rtpl.php + +# 3rd-party dependencies +vendor/ + +# Release archives +*.tar.gz +*.zip +inc/languages/*/LC_MESSAGES/shaarli.mo + +# Development and test resources +coverage +doxygen +sandbox +phpmd.html + +# User plugin configuration +plugins/*/config.php + +# 3rd party themes +tpl/* +!tpl/default +!tpl/vintage + +# Front end +node_modules +tpl/default/js +tpl/default/css +tpl/default/fonts +tpl/default/img +tpl/vintage/js +tpl/vintage/css +tpl/vintage/img diff --git a/.gitattributes b/.gitattributes index 6b6ffbd5..9d22f11b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,7 +33,9 @@ Dockerfile text .travis.yml export-ignore doc/**/*.json export-ignore doc/**/*.md export-ignore -docker/ export-ignore +.docker/ export-ignore +.dockerignore export-ignore +Dockerfile* export-ignore Doxyfile export-ignore Makefile export-ignore node_modules/ export-ignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4cda6f31 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,70 @@ +# Stage 1: +# - Copy Shaarli sources +# - Build documentation +FROM python:3-alpine as docs +ADD . /usr/src/app/shaarli +RUN cd /usr/src/app/shaarli \ + && pip install --no-cache-dir mkdocs \ + && mkdocs build + +# Stage 2: +# - Resolve PHP dependencies with Composer +FROM composer:latest as composer +COPY --from=docs /usr/src/app/shaarli /app/shaarli +RUN cd shaarli \ + && composer --prefer-dist --no-dev install + +# Stage 3: +# - Frontend dependencies +FROM node:9.9-alpine as node +COPY --from=composer /app/shaarli shaarli +RUN cd shaarli \ + && yarn install \ + && yarn run build \ + && rm -rf node_modules + +# Stage 4: +# - Shaarli image +FROM alpine:3.6 +LABEL maintainer="Shaarli Community" + +RUN apk --update --no-cache add \ + ca-certificates \ + nginx \ + php7 \ + php7-ctype \ + php7-curl \ + php7-fpm \ + php7-gd \ + php7-iconv \ + php7-intl \ + php7-json \ + php7-mbstring \ + php7-openssl \ + php7-session \ + php7-xml \ + php7-zlib \ + s6 + +COPY .docker/nginx.conf /etc/nginx/nginx.conf +COPY .docker/php-fpm.conf /etc/php7/php-fpm.conf +COPY .docker/services.d /etc/services.d + +RUN 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 +COPY --from=node /shaarli shaarli + +RUN chown -R nginx:nginx . \ + && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ + && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log + +VOLUME /var/www/shaarli/data + +EXPOSE 80 + +ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] +CMD [] diff --git a/Dockerfile.armhf b/Dockerfile.armhf new file mode 100644 index 00000000..5dcc34aa --- /dev/null +++ b/Dockerfile.armhf @@ -0,0 +1,49 @@ +FROM lsiobase/alpine.armhf:3.6 +LABEL 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 .docker/nginx.conf /etc/nginx/nginx.conf +COPY .docker/php-fpm.conf /etc/php7/php-fpm.conf +COPY .docker/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 . \ + && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ + && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log + +VOLUME /var/www/shaarli/data + +EXPOSE 80 + +ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] +CMD [] diff --git a/docker/.htaccess b/docker/.htaccess deleted file mode 100644 index f601c1ee..00000000 --- a/docker/.htaccess +++ /dev/null @@ -1,13 +0,0 @@ - - = 2.4> - Require all denied - - - Allow from none - Deny from all - - - - - Require all denied - diff --git a/docker/alpine/Dockerfile.armhf.latest b/docker/alpine/Dockerfile.armhf.latest deleted file mode 100644 index 824a1926..00000000 --- a/docker/alpine/Dockerfile.armhf.latest +++ /dev/null @@ -1,49 +0,0 @@ -FROM lsiobase/alpine.armhf: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/latest.tar.gz | tar xzf - \ - && mv Shaarli-latest shaarli \ - && cd shaarli \ - && composer --prefer-dist --no-dev install \ - && rm -rf ~/.composer \ - && chown -R nginx:nginx . \ - && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ - && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log - -VOLUME /var/www/shaarli/data - -EXPOSE 80 - -ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] -CMD [] diff --git a/docker/alpine/Dockerfile.armhf.master b/docker/alpine/Dockerfile.armhf.master deleted file mode 100644 index 6c89adc3..00000000 --- a/docker/alpine/Dockerfile.armhf.master +++ /dev/null @@ -1,49 +0,0 @@ -FROM lsiobase/alpine.armhf: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 . \ - && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ - && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log - -VOLUME /var/www/shaarli/data - -EXPOSE 80 - -ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] -CMD [] diff --git a/docker/alpine/Dockerfile.latest b/docker/alpine/Dockerfile.latest deleted file mode 100644 index 755d8751..00000000 --- a/docker/alpine/Dockerfile.latest +++ /dev/null @@ -1,54 +0,0 @@ -# Stage 1: -# - Get Shaarli sources -# - Resolve PHP dependencies with Composer -FROM composer:latest as composer -RUN curl -L https://github.com/shaarli/Shaarli/archive/latest.tar.gz | tar xzf - \ - && mv Shaarli-latest shaarli \ - && cd shaarli \ - && composer --prefer-dist --no-dev install - -# Stage 2: -# - Shaarli image -FROM alpine:3.6 -LABEL maintainer="Shaarli Community" - -RUN apk --update --no-cache add \ - ca-certificates \ - nginx \ - php7 \ - php7-ctype \ - php7-curl \ - php7-fpm \ - php7-gd \ - php7-iconv \ - php7-intl \ - php7-json \ - php7-mbstring \ - php7-openssl \ - 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 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 -COPY --from=composer /app/shaarli shaarli - -RUN chown -R nginx:nginx . \ - && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ - && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log - -VOLUME /var/www/shaarli/data - -EXPOSE 80 - -ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] -CMD [] diff --git a/docker/alpine/Dockerfile.master b/docker/alpine/Dockerfile.master deleted file mode 100644 index 7bbe1fb7..00000000 --- a/docker/alpine/Dockerfile.master +++ /dev/null @@ -1,63 +0,0 @@ -# Stage 1: -# - Get Shaarli sources -# - Resolve PHP dependencies with Composer -FROM composer:latest as composer -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 - -# Stage 2: -# - Frontend dependencies -FROM node:9.9-alpine as node -COPY --from=composer /app/shaarli shaarli -RUN cd shaarli \ - && yarn install \ - && yarn run build \ - && rm -rf node_modules - -# Stage 3: -# - Shaarli image -FROM alpine:3.6 -LABEL maintainer="Shaarli Community" - -RUN apk --update --no-cache add \ - ca-certificates \ - nginx \ - php7 \ - php7-ctype \ - php7-curl \ - php7-fpm \ - php7-gd \ - php7-iconv \ - php7-intl \ - php7-json \ - php7-mbstring \ - php7-openssl \ - 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 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 -COPY --from=node /shaarli shaarli - -RUN chown -R nginx:nginx . \ - && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \ - && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log - -VOLUME /var/www/shaarli/data - -EXPOSE 80 - -ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"] -CMD [] diff --git a/docker/alpine/IMAGE.md b/docker/alpine/IMAGE.md deleted file mode 100644 index a8952257..00000000 --- a/docker/alpine/IMAGE.md +++ /dev/null @@ -1,10 +0,0 @@ -## Alpine images -- [Alpine Linux](https://www.alpinelinux.org/) -- [PHP-FPM](http://php-fpm.org/) -- [Nginx](http://nginx.org/) - -### `shaarli/shaarli:latest` -- [Shaarli](https://github.com/shaarli/Shaarli), `latest` branch - -### `shaarli/shaarli:master` -- [Shaarli](https://github.com/shaarli/Shaarli), `master` branch diff --git a/docker/alpine/nginx.conf b/docker/alpine/nginx.conf deleted file mode 100644 index 07fba33f..00000000 --- a/docker/alpine/nginx.conf +++ /dev/null @@ -1,73 +0,0 @@ -user nginx nginx; -daemon off; -worker_processes 4; -pid /var/run/nginx.pid; - -events { - worker_connections 768; -} - -http { - include mime.types; - default_type application/octet-stream; - keepalive_timeout 20; - - client_max_body_size 10m; - - index index.html index.php; - - server { - listen 80; - root /var/www/shaarli; - - access_log /var/log/nginx/shaarli.access.log; - error_log /var/log/nginx/shaarli.error.log; - - location ~ /\. { - # deny access to dotfiles - access_log off; - log_not_found off; - deny all; - } - - location ~ ~$ { - # deny access to temp editor files, e.g. "script.php~" - access_log off; - log_not_found off; - deny all; - } - - location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { - # cache static assets - expires max; - add_header Pragma public; - add_header Cache-Control "public, must-revalidate, proxy-revalidate"; - } - - location = /favicon.ico { - # serve the Shaarli favicon from its custom location - alias /var/www/shaarli/images/favicon.ico; - } - - location / { - # Slim - rewrite URLs - try_files $uri /index.php$is_args$args; - } - - location ~ (index)\.php$ { - # Slim - split URL path into (script_filename, path_info) - try_files $uri =404; - fastcgi_split_path_info ^(.+\.php)(/.+)$; - - # filter and proxy PHP requests to PHP-FPM - fastcgi_pass unix:/var/run/php-fpm.sock; - fastcgi_index index.php; - include fastcgi.conf; - } - - location ~ \.php$ { - # deny access to all other PHP scripts - deny all; - } - } -} diff --git a/docker/alpine/php-fpm.conf b/docker/alpine/php-fpm.conf deleted file mode 100644 index 0843c164..00000000 --- a/docker/alpine/php-fpm.conf +++ /dev/null @@ -1,16 +0,0 @@ -[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 deleted file mode 100755 index 1dadeeaf..00000000 --- a/docker/alpine/services.d/.s6-svscan/finish +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/bin/true diff --git a/docker/alpine/services.d/nginx/run b/docker/alpine/services.d/nginx/run deleted file mode 100755 index 21e7b0d6..00000000 --- a/docker/alpine/services.d/nginx/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/execlineb -P -nginx diff --git a/docker/alpine/services.d/php-fpm/run b/docker/alpine/services.d/php-fpm/run deleted file mode 100755 index 21dd0107..00000000 --- a/docker/alpine/services.d/php-fpm/run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/execlineb -P -php-fpm7 -F -- cgit v1.2.3