From a20acb2db1ab7285330e38c7f73debf481880185 Mon Sep 17 00:00:00 2001 From: iliyan ivanov Date: Fri, 10 Jul 2020 22:16:17 +0300 Subject: [PATCH] initial --- .drone.yml | 34 +++++++++++++++++++++++ build.sh | 11 ++++++++ nginx/Dockerfile | 7 +++++ nginx/site.conf | 30 +++++++++++++++++++++ php/Dockerfile | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 .drone.yml create mode 100755 build.sh create mode 100644 nginx/Dockerfile create mode 100644 nginx/site.conf create mode 100644 php/Dockerfile diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..98504dc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,34 @@ +kind: pipeline +name: default + +steps: + - name: build + image: docker + privileged: true + when: + branch: + - master + event: + - push + environment: + DOCKER_USERNAME: + from_secret: docker_username + DOCKER_PASSWORD: + from_secret: docker_password + commands: + - docker login -u $${DOCKER_USERNAME} -p $${DOCKER_PASSWORD} $${DOCKER_REGISTRY} + - docker image build -f ./nginx/Dockerfile -t $${DOCKER_REGISTRY}/laravel-php-fpm/nginx ./nginx + - docker image build -f ./php/Dockerfile -t $${DOCKER_REGISTRY}/laravel-php-fpm/php ./php + - | + docker image push $${DOCKER_REGISTRY}/laravel-php-fpm/nginx + docker image push $${DOCKER_REGISTRY}/laravel-php-fpm/php + docker image prune --force + volumes: + - name: docker_socket + path: /var/run/docker.sock + +volumes: + - name: docker_socket + host: + path: /var/run/docker.sock + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7b7c28e --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +DOCKER_REGISTRY=${1:-localhost:5000} + +docker image build -t ${DOCKER_REGISTRY}/laravel-php-fpm/php -f php/Dockerfile ./php +docker image build -t ${DOCKER_REGISTRY}/laravel-php-fpm/nginx -f nginx/Dockerfile ./nginx + +[ -z "$1" ] && exit + +docker image push ${DOCKER_REGISTRY}/laravel-php-fpm/php +docker image push ${DOCKER_REGISTRY}/laravel-php-fpm/nginx diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..9014c67 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,7 @@ +FROM nginx + +ADD site.conf /etc/nginx/conf.d/default.conf + +CMD usermod -u ${LARA_UID:-1000} nginx \ + && groupmod -g ${LARA_GUID:-1000} nginx \ + && nginx -g "daemon off;" diff --git a/nginx/site.conf b/nginx/site.conf new file mode 100644 index 0000000..29b4f64 --- /dev/null +++ b/nginx/site.conf @@ -0,0 +1,30 @@ +server { + listen 80; + + index index.php index.html; + server_name php-docker.local; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /www; + + # rewire non-files to index.php + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME /www/public/$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + real_ip_header X-Forwarded-For; + fastcgi_read_timeout 1200; + proxy_connect_timeout 1200; + proxy_send_timeout 1200; + proxy_read_timeout 1200; + send_timeout 1200; + } +} diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..1bec807 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,70 @@ +FROM ubuntu:18.04 + +# it seems -y is not enough +ENV TERM=xterm \ + TZ=Europe/Sofia \ + DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + build-essential \ + bzip2 \ + ca-certificates \ + curl \ + git \ + php-bcmath \ + php-ctype \ + php-curl \ + php-dev \ + php-fpm \ + php-gd \ + php-gearman \ + php-geoip \ + php-json \ + php-mbstring \ + php-memcache \ + php-memcached \ + php-mongodb \ + php-mysql \ + php-pdo \ + php-pgsql \ + php-redis \ + php-sqlite3 \ + php-xml \ + php-xmlrpc \ + php-zip \ + phpunit \ + unzip \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# setup composer 1.8.5 +RUN export COMPOSER_SHA256_SUM=4e4c1cd74b54a26618699f3190e6f5fc63bb308b13fa660f71f2a2df047c0e17 \ + && curl "https://getcomposer.org/download/1.8.5/composer.phar" -o /usr/local/bin/composer \ + && [ "$(sha256sum /usr/local/bin/composer | cut -d " " -f1)" = "$COMPOSER_SHA256_SUM" ] \ + && chmod +x /usr/local/bin/composer \ + && unset -v COMPOSER_SHA256_SUM + +RUN ln -f -s /usr/share/zoneinfo/Europe/Sofia /etc/localtime + +RUN mkdir -pv /run/php + +# listen on all IPs +RUN sed -i 's#listen = /run/php/php7.2-fpm.sock#listen = 9000#g' /etc/php/7.2/fpm/pool.d/www.conf + +# setup composer cache +RUN mkdir -pv /var/www/.composer + +# setup volumes +VOLUME /var/www/.composer + +WORKDIR /www + +EXPOSE 9000 + +CMD usermod -u ${LARA_UID:-1000} www-data \ + && groupmod -g ${LARA_GUID:-1000} www-data \ + && chown www-data:www-data -Rc /var/www/.composer \ + && /usr/sbin/php-fpm7.2 -F +