Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Default settings for docker-compose
# @see https://docs.docker.com/compose/reference/envvars/#compose_file
COMPOSE_PROJECT_NAME=standard-php-dev-env
COMPOSE_FILE=docker-compose.yml
COMPOSE_CONVERT_WINDOWS_PATHS=1

# build
PHP_VERSION=7.4
TIMEZONE=UTC
NETWORKS_DRIVER=bridge

# application
APP_USER=www-data
APP_GROUP=www-data
APP_USER_ID=1000
APP_GROUP_ID=1000
APP_CODE_PATH_HOST=../
APP_CODE_PATH_CONTAINER=/var/www/current

# required so we can reach the nginx server from other containers via that hostname
APP_HOST=standard-php-dev-env.local

# nginx
NGINX_HOST_HTTP_PORT=8898
NGINX_HOST_HTTPS_PORT=8899

# php-cli
WORKSPACE_HOST_SSH_PORT=2239

# mysql
MYSQL_ROOT_PASSWORD=S3cr3T
MYSQL_DATABASE=test
MYSQL_USER=dba
MYSQL_PASSWORD=S3cr3T
MYSQL_HOST_PORT=6089
28 changes: 28 additions & 0 deletions .docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Default settings for docker-compose
# @see https://docs.docker.com/compose/reference/envvars/#compose_file
COMPOSE_PROJECT_NAME=docker-php-tutorial
COMPOSE_FILE=docker-compose.yml
COMPOSE_CONVERT_WINDOWS_PATHS=1

# build
PHP_VERSION=7.3
TIMEZONE=UTC
NETWORKS_DRIVER=bridge

# application
APP_USER=www-data
APP_GROUP=www-data
APP_USER_ID=1000
APP_GROUP_ID=1000
APP_CODE_PATH_HOST=../
APP_CODE_PATH_CONTAINER=/var/www/current

# required so we can reach the nginx server from other containers via that hostname
APP_HOST=docker-php-tutorial.local

# nginx
NGINX_HOST_HTTP_PORT=80
NGINX_HOST_HTTPS_PORT=443

# workspace
WORKSPACE_HOST_SSH_PORT=2222
14 changes: 14 additions & 0 deletions .docker/.shared/config/php/conf.d/zz-app.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; enable opcache
opcache.enable_cli = 1
opcache.enable = 1
opcache.fast_shutdown = 1
; check with find . -type f -print | grep php | wc -l
opcache.max_accelerated_files = 100
; revalidate everytime
opcache.revalidate_freq=0
;opcache.validate_timestamps = 0
opcache.memory_consumption=64
opcache.interned_strings_buffer=12
; enable xdebug
xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
8 changes: 8 additions & 0 deletions .docker/.shared/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

apt-get clean
rm -rf /var/lib/apt/lists/* \
/tmp/* \
/var/tmp/* \
/var/log/lastlog \
/var/log/faillog
52 changes: 52 additions & 0 deletions .docker/.shared/scripts/create_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

APP_USER=$1
APP_GROUP=$2
APP_USER_ID=$3
APP_GROUP_ID=$4

new_user_id_exists=$(id ${APP_USER_ID} > /dev/null 2>&1; echo $?)
if [ "$new_user_id_exists" = "0" ]; then
(>&2 echo "ERROR: APP_USER_ID $APP_USER_ID already exists - Aborting!");
exit 1;
fi

new_group_id_exists=$(getent group ${APP_GROUP_ID} > /dev/null 2>&1; echo $?)
if [ "$new_group_id_exists" = "0" ]; then
(>&2 echo "ERROR: APP_GROUP_ID $APP_GROUP_ID already exists - Aborting!");
exit 1;
fi

old_user_id=$(id -u ${APP_USER})
old_user_exists=$(id -u ${APP_USER} > /dev/null 2>&1; echo $?)
old_group_id=$(getent group ${APP_GROUP} | cut -d: -f3)
old_group_exists=$(getent group ${APP_GROUP} > /dev/null 2>&1; echo $?)

if [ "$old_group_id" != "${APP_GROUP_ID}" ]; then
# create the group
groupadd -f ${APP_GROUP}
# and the correct id
groupmod -g ${APP_GROUP_ID} ${APP_GROUP}
if [ "$old_group_exists" = "0" ]; then
# set the permissions of all "old" files and folder to the new group
find / -group $old_group_id -exec chgrp -h ${APP_GROUP} {} \; || true
fi
fi

if [ "$old_user_id" != "${APP_USER_ID}" ]; then
# create the user if it does not exist
if [ "$old_user_exists" != "0" ]; then
useradd ${APP_USER} -g ${APP_GROUP}
fi

# make sure the home directory exists with the correct permissions
mkdir -p /home/${APP_USER} && chmod 755 /home/${APP_USER} && chown ${APP_USER}:${APP_GROUP} /home/${APP_USER}

# change the user id, set the home directory and make sure the user has a login shell
usermod -u ${APP_USER_ID} -m -d /home/${APP_USER} ${APP_USER} -s $(which bash)

if [ "$old_user_exists" = "0" ]; then
# set the permissions of all "old" files and folder to the new user
find / -user $old_user_id -exec chown -h ${APP_USER} {} \; || true
fi
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -e

# fix for host.docker.internal not existing on linux https://github.com/docker/for-linux/issues/264
# see https://dev.to/bufferings/access-host-from-a-docker-container-4099
HOST_DOMAIN="host.docker.internal"
# check if the host exists
# see https://stackoverflow.com/a/24049165/413531
if dig ${HOST_DOMAIN} | grep -q 'NXDOMAIN'
then
# on linux, it will fail - so we'll "manually" add the hostname in the host file
HOST_IP=$(ip route | awk 'NR==1 {print $3}')
echo "$HOST_IP\t$HOST_DOMAIN" >> /etc/hosts
fi

exec "$@"
17 changes: 17 additions & 0 deletions .docker/.shared/scripts/install_php_extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# add wget
apt-get update -yqq && apt-get -f install -yyq wget

# download helper script
# @see https://github.com/mlocati/docker-php-extension-installer/
wget -q -O /usr/local/bin/install-php-extensions https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions \
|| (echo "Failed while downloading php extension installer!"; exit 1)

# install extensions
chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions \
opcache \
xdebug \
zip \
pdo_mysql \
;
20 changes: 20 additions & 0 deletions .docker/.shared/scripts/install_software.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

apt-get update -yqq && apt-get install -yqq \
curl \
dnsutils \
gdb \
git \
htop \
iproute2 \
iputils-ping \
ltrace \
make \
procps \
strace \
sudo \
sysstat \
unzip \
vim \
wget \
;
9 changes: 9 additions & 0 deletions .docker/.shared/scripts/modify_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

CONFIG_FILE=$1
VAR_NAME=$2
VAR_VALUE=$3

sed -i -e "s#${VAR_NAME}#${VAR_VALUE}#g" "${CONFIG_FILE}"

# cat "${CONFIG_FILE}"
4 changes: 4 additions & 0 deletions .docker/.shared/scripts/set_timezone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

TZ=$1
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
95 changes: 95 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: '3.7'

networks:
backend:
driver: ${NETWORKS_DRIVER}
ipam:
config:
- subnet: "192.168.230.0/24"

volumes:
data-spde:

services:
nginx:
image: standard-php-dev-env/nginx
build:
context: .
dockerfile: ./nginx/Dockerfile
args:
- APP_CODE_PATH=${APP_CODE_PATH_CONTAINER}
- APP_GROUP=${APP_GROUP}
- APP_GROUP_ID=${APP_GROUP_ID}
- APP_USER=${APP_USER}
- APP_USER_ID=${APP_USER_ID}
- TZ=${TIMEZONE}
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
ports:
- "${NGINX_HOST_HTTP_PORT}:80"
- "${NGINX_HOST_HTTPS_PORT}:443"
networks:
backend:
ipv4_address: 192.168.230.13
aliases:
- ${APP_HOST}

php-fpm:
image: standard-php-dev-env/php-fpm
build:
context: .
dockerfile: ./php-fpm/Dockerfile
args:
- APP_CODE_PATH=${APP_CODE_PATH_CONTAINER}
- APP_GROUP=${APP_GROUP}
- APP_GROUP_ID=${APP_GROUP_ID}
- APP_USER=${APP_USER}
- APP_USER_ID=${APP_USER_ID}
- TARGET_PHP_VERSION=${PHP_VERSION}
- TZ=${TIMEZONE}
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
networks:
backend:
ipv4_address: 192.168.230.12

php-cli:
image: standard-php-dev-env/php-cli
build:
context: .
dockerfile: ./php-cli/Dockerfile
args:
- APP_CODE_PATH=${APP_CODE_PATH_CONTAINER}
- APP_GROUP=${APP_GROUP}
- APP_GROUP_ID=${APP_GROUP_ID}
- APP_USER=${APP_USER}
- APP_USER_ID=${APP_USER_ID}
- TARGET_PHP_VERSION=${PHP_VERSION}
- TZ=${TIMEZONE}
volumes:
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
ports:
- "${WORKSPACE_HOST_SSH_PORT}:22"
networks:
backend:
ipv4_address: 192.168.230.11

mysql:
image: standard-php-dev-env/mysql
build:
context: .
dockerfile: ./mysql/Dockerfile
restart: always
volumes:
- data-spde:/var/lib/mysql
- ./mysql/init_data:/docker-entrypoint-initdb.d
networks:
backend:
ipv4_address: 192.168.230.10
ports:
- ${MYSQL_HOST_PORT}:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
Loading