Skip to content

Instantly share code, notes, and snippets.

@yaredc
Last active December 1, 2020 16:36
Show Gist options
  • Save yaredc/3e00e317ae0f6795176a95acda0a7c86 to your computer and use it in GitHub Desktop.
Save yaredc/3e00e317ae0f6795176a95acda0a7c86 to your computer and use it in GitHub Desktop.
PHP8
FROM app/php:8.0
USER root
RUN rm -f /etc/crontabs/root &&\
touch /etc/crontabs/root &&\
chown -R www-data:www-data /var/www &&\
chmod -R 0774 /var/www
CMD ["sh", "-c", "/usr/bin/crontab -u www-data /var/www/crontab && /usr/sbin/crond -f -L /proc/self/fd/1"]
* * * * * php /var/www/bin/console task:run 2>&1
#server {
# listen 80;
# listen [::]:80;
# server_name 127.0.0.1;
# return 301 https://$host$request_uri;
#}
server {
listen 8080;
listen [::]:8080;
server_name 127.0.0.1;
server_name localhost;
root /var/www/public;
index index.php;
client_max_body_size 10M;
access_log /proc/self/fd/1 combined;
error_log /proc/self/fd/2 warn;
# add_header X-UA-Compatible "IE=edge";
# add_header X-XSS-Protection "1; mode=block";
# add_header X-Content-Type-Options "nosniff" always;
# add_header X-Frame-Options "DENY" always;
# add_header Referrer-Policy "strict-origin-when-cross-origin";
# add_header Access-Control-Allow-Origin "*";
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
# add_header Content-Security-Policy "font-src data: https://maxcdn.bootstrapcdn.com https://use.fontawesome.com https://cdnjs.cloudflare.com https://code.jquery.com https://themes.googleusercontent.com https://fonts.gstatic.com";
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /(protected|framework|nbproject|vendor|.idea|.git) {
access_log off;
log_not_found off;
return 404;
}
location /. {
access_log off;
log_not_found off;
return 404;
}
location ~ \.(gitignore|htaccess|bak|bat|yaml|lock|cache|sql|fla|md|psd|ini|log|sh|inc|swp|mwb|dist|bin|exe|bash)$ {
access_log off;
log_not_found off;
return 404;
}
location ~ \.(js|css|png|jpg|jpeg|gif|svg|swf|ico|pdf|mov|zip|rar|woff|woff2|ttf|html|htm)$ {
access_log off;
log_not_found off;
expires 1w;
try_files $uri =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
version: "3"
volumes:
composer:
pgsql:
rabbitmq:
elasticsearch:
services:
php:
image: app/php:8.0
build:
context: .
dockerfile: .docker/php.dockerfile
restart: always
volumes:
- ./:/var/www
- composer:/home/www-data/.composer
working_dir: /var/www
nginx:
image: app/nginx:1.15.5
depends_on:
- php
build:
context: .
dockerfile: .docker/nginx.dockerfile
volumes:
- ./.docker/default.conf:/etc/nginx/conf.d/default.conf
- ./:/var/www
ports:
- 8080:8080
working_dir: /var/www
pgsql:
depends_on:
- php
image: postgres:13.0-alpine
volumes:
- pgsql:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: root
ports:
- 5432:5432
rabbitmq:
depends_on:
- php
image: rabbitmq:3.8.9-management-alpine
volumes:
- rabbitmq:/var/lib/rabbitmq
environment:
RABBITMQ_DEFAULT_USER: root
RABBITMQ_DEFAULT_PASS: root
ports:
- 5672:5672
- 15672:15672
cron:
depends_on:
- php
image: app/cron:7.4
build:
context: .
dockerfile: .docker/cron.dockerfile
volumes:
- ./:/var/www
working_dir: /var/www
restart: always
elasticsearch:
depends_on:
- php
image: docker.elastic.co/elasticsearch/elasticsearch:7.5.1
volumes:
- elasticsearch:/usr/share/elasticsearch/data
environment:
- discovery.type=single-node
ports:
- 9200:9200
restart: always
kibana:
depends_on:
- elasticsearch
image: docker.elastic.co/kibana/kibana:7.5.1
environment:
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ports:
- 5601:5601
restart: always
logstash:
depends_on:
- kibana
image: docker.elastic.co/logstash/logstash:7.5.1
volumes:
- .docker/dev/logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
ports:
- 9600:9600
- 5044:5044
restart: always
filebeat:
depends_on:
- logstash
image: docker.elastic.co/beats/filebeat:7.5.1
volumes:
- .docker/dev/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml
- ./data:/var/www/data
restart: always
FROM nginx:1.15.5
COPY .docker/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80 443
 
FROM php:8-fpm-alpine
###########################################################
#PRODUCTION ENVIRONMENT
###########################################################
ENV PHP_FPM_USER="www-data" \
PHP_FPM_GROUP="www-data" \
TZ="Europe/Berlin"
#TIMEZONE
RUN apk add --no-cache --virtual .deps tzdata &&\
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime &&\
echo $TZ > /etc/timezone &&\
apk del .deps
#NAMESERVERS
RUN echo "nameserver 1.1.1.1" >> /etc/resolv.conf &&\
echo "nameserver 1.0.0.1" >> /etc/resolv.conf &&\
echo "nameserver 8.8.8.8" >> /etc/resolv.conf &&\
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
#DEPENDENCIES
RUN apk add --no-cache --virtual .deps \
autoconf \
build-base \
curl-dev \
zlib-dev \
icu-dev \
postgresql-dev \
oniguruma-dev \
libxml2-dev \
libzip-dev
#GD
RUN apk add --no-cache \
freetype \
libpng \
libjpeg-turbo \
msttcorefonts-installer \
fontconfig &&\
update-ms-fonts &&\
fc-cache -f &&\
apk add --no-cache --virtual .gd \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev &&\
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg &&\
docker-php-ext-install -j$(nproc) gd &&\
apk del .gd
#SODIUM
RUN docker-php-ext-enable sodium
#INSTALL EXTENSIONS
RUN docker-php-ext-install -j$(nproc) pdo_pgsql zip intl opcache
#PHP.INI SETTINGS
RUN echo "date.timezone=Europe/Berlin" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "memory_limit=2048M" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "date.timezone=Europe/Berlin" >> "$PHP_INI_DIR"/php.ini-development &&\
echo "memory_limit=2048M" >> "$PHP_INI_DIR"/php.ini-development &&\
cp "$PHP_INI_DIR"/php.ini-production "$PHP_INI_DIR"/php.ini &&\
echo "php_flag[display_errors]=off" >> /usr/local/etc/php-fpm.conf &&\
echo "php_admin_flag[log_errors]=on" >> /usr/local/etc/php-fpm.conf &&\
echo "php_admin_value[error_log]=/proc/self/fd/2" >> /usr/local/etc/php-fpm.conf &&\
echo "php_admin_value[error_reporting]=E_ALL" >> /usr/local/etc/php-fpm.conf &&\
echo "php_admin_value[display_startup_errors]=off" >> /usr/local/etc/php-fpm.conf
#JIT
RUN echo "opcache.enable=1" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "opcache.enable_cli=1" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "opcache.jit_buffer_size=100M" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "opcache.jit=tracing" >> "$PHP_INI_DIR"/php.ini-production &&\
echo "opcache.enable=1" >> "$PHP_INI_DIR"/php.ini-development &&\
echo "opcache.enable_cli=1" >> "$PHP_INI_DIR"/php.ini-development &&\
echo "opcache.jit_buffer_size=100M" >> "$PHP_INI_DIR"/php.ini-development &&\
echo "opcache.jit=tracing" >> "$PHP_INI_DIR"/php.ini-development
#PROD
RUN apk del .deps &&\
apk add --no-cache curl \
zlib \
icu \
libzip \
libpq \
libxml2 \
oniguruma \
openssh-keygen \
ca-certificates
###########################################################
#DEVELOPMENT ENVIRONMENT
###########################################################
#XDEBUG
#https://3.xdebug.org/docs/upgrade_guide
#https://3.xdebug.org/docs/all_settings#client_host
ENV EXT_XDEBUG_VERSION="3.0.0"
RUN docker-php-source extract &&\
mkdir -p /usr/src/php/ext/xdebug &&\
curl -fsSL https://github.com/xdebug/xdebug/archive/$EXT_XDEBUG_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/xdebug --strip 1 &&\
docker-php-ext-configure xdebug &&\
docker-php-ext-install xdebug &&\
docker-php-source delete &&\
echo "xdebug.mode=develop,debug,trace" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
cp "$PHP_INI_DIR"/php.ini-development "$PHP_INI_DIR"/php.ini &&\
echo "php_flag[display_errors]=on" >> /usr/local/etc/php-fpm.conf &&\
echo "php_admin_value[display_startup_errors]=on" >> /usr/local/etc/php-fpm.conf
#WORKDIR
RUN mkdir -p /var/www &&\
chown -R $PHP_FPM_USER:$PHP_FPM_GROUP /var/www /home/$PHP_FPM_USER &&\
chmod -R 0774 /var/www
#COMPOSER
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" &&\
php composer-setup.php &&\
php -r "unlink('composer-setup.php');" &&\
mv composer.phar /usr/local/bin/composer
ENV COMPOSER_HOME="/home/$PHP_FPM_USER/.composer" COMPOSER_MEMORY_LIMIT="-1"
#CLEAN UP
RUN rm -rf /var/cache/apk/*
WORKDIR /var/www
USER $PHP_FPM_USER
EXPOSE 9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment