Skip to content

Commit

Permalink
dev: Use official php docker image (ankitpokhrel#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Nov 5, 2020
1 parent c3bd393 commit 7217839
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 37 deletions.
50 changes: 32 additions & 18 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
FROM phpearth/php:7.3-nginx
FROM php:7.3-fpm-alpine

LABEL maintainer="[email protected],[email protected]" \
description="This builds tus-php-base image"

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PHP_INI_DIR /etc/php/7.3
ENV PHP_INI_DIR /usr/local/etc/php
ENV COMPOSER_ALLOW_SUPERUSER 1

ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub

RUN ln -sf /usr/share/zoneinfo/Asia/Kathmandu /etc/localtime

RUN apk update && apk add --no-cache \
php7.3-imap \
php7.3-intl \
php7.3-mbstring \
php7.3-openssl \
php7.3-ldap \
php7.3-curl \
php7.3-pcntl \
php7.3-dev \
php7.3-pear \
composer

# Install APCu and Xdebug extension.
RUN pecl upgrade apcu xdebug
make \
supervisor \
nginx \
php7-imap \
php7-intl \
php7-curl \
composer \
curl \
ca-certificates

# Install required extensions.
RUN docker-php-ext-install pcntl

# Install pecl extensions.
#
# Some dependencies like c-compiler and autoconf are only required
# to compile pecl extensions. However, these dependencies take a
# lot of space. Therefore, we will remove these dependencies
# after installing the required extensions.
RUN apk add --no-cache g++ autoconf && \
pecl upgrade apcu xdebug && \
apk del g++ autoconf

COPY ./bin/xdebug.sh /bin/xdebug
RUN chmod +x /bin/xdebug

# There are some default configurations from the image that will override
# our php-fpm settings and we don't want that. To avoid that, we will
# delete all configurations available by default. Also, we will
# create a folder for the php-fpm socket.
RUN mkdir -p /var/run/php-fpm && rm -rf /usr/local/etc/php-fpm.d/*.conf

COPY ./configs/supervisord.conf /etc/supervisord.conf
COPY ./configs/nginx.conf /etc/nginx/nginx.conf
COPY ./configs/php.ini $PHP_INI_DIR/php.ini
COPY ./configs/xdebug.ini $PHP_INI_DIR/conf.d/00_xdebug.disable
COPY ./configs/www.conf $PHP_INI_DIR/php-fpm.d/www.conf
COPY ./configs/www.conf /usr/local/etc/php-fpm.d/www.conf

ENTRYPOINT [ "sh" ]
2 changes: 1 addition & 1 deletion docker/base/bin/xdebug.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

XDEBUG_CONFIG=/etc/php/7.3/conf.d/00_xdebug
XDEBUG_CONFIG=/etc/php7/conf.d/00_xdebug

enable()
{
Expand Down
43 changes: 43 additions & 0 deletions docker/base/configs/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[unix_http_server]
file=/dev/shm/supervisor.sock

[supervisord]
logfile=/tmp/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
user=root

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock

[program:php-fpm]
command=/usr/local/sbin/php-fpm -F
autostart=true
autorestart=true
priority=1
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:nginx]
command=/usr/sbin/nginx -g 'pid /tmp/nginx.pid; daemon off;'
autostart=true
autorestart=true
priority=2
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
2 changes: 1 addition & 1 deletion docker/base/configs/www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ daemonize = yes
[www]
user = www-data
group = www-data
listen = /run/php-fpm7.3/php-fpm.sock
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
Expand Down
2 changes: 1 addition & 1 deletion docker/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ ENV SERVER_URL http://0.0.0.0:8081

WORKDIR /var/www/example

CMD ["/sbin/runit-wrapper"]
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
2 changes: 1 addition & 1 deletion docker/client/configs/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ server {
client_max_body_size 3000m;

location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm7.3/php-fpm.sock;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
Expand Down
11 changes: 4 additions & 7 deletions docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM tus-php-base

## Redis Installation
RUN apk add --no-cache redis

## Expose environment variables
ENV REDIS_HOST tus-php-redis
ENV REDIS_PORT 6379
RUN apk add --no-cache redis

## Configurations
COPY ./configs/default.conf /etc/nginx/conf.d/default.conf

ENV DOC_ROOT /var/www
Expand All @@ -16,8 +12,9 @@ RUN mkdir -p ${SOURCE_CODE}
VOLUME ${SOURCE_CODE}

WORKDIR ${DOC_ROOT}
RUN mkdir -p ${DOC_ROOT}/uploads
RUN chown -R www-data:root ${DOC_ROOT}/uploads

RUN mkdir -p ${DOC_ROOT}/uploads && \
chown -R www-data:root ${DOC_ROOT}/uploads

COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
2 changes: 1 addition & 1 deletion docker/server/configs/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ server {
client_max_body_size 3000m;

location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm7.3/php-fpm.sock;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
Expand Down
11 changes: 4 additions & 7 deletions docker/server/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/bin/sh

# Install dependencies.
composer install

# This /sbin/runit-wrapper has been copied from the base image phpearth/php:7.2-nginx
# This is necessary to keep container in running state, otherwise container will
# exit immediately after it's built. We need to keep it running to handle
# incoming request. /sbin/runit-wrapper also handles SIGINT properly and
# let system handle those signals appropriately.
# see https://github.com/phpearth/docker-php/blob/master/docker/tags/nginx/sbin/runit-wrapper
/sbin/runit-wrapper
# Start supervisord.
/usr/bin/supervisord -n -c /etc/supervisord.conf

0 comments on commit 7217839

Please sign in to comment.