Skip to content

Commit a47aeff

Browse files
authored
Merge pull request #1 from rpmeir/first-commit
First commit
2 parents daa9a8b + ec05c84 commit a47aeff

File tree

23 files changed

+750
-1
lines changed

23 files changed

+750
-1
lines changed

.docker/.env

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Default settings for docker-compose
2+
# @see https://docs.docker.com/compose/reference/envvars/#compose_file
3+
COMPOSE_PROJECT_NAME=standard-php-dev-env
4+
COMPOSE_FILE=docker-compose.yml
5+
COMPOSE_CONVERT_WINDOWS_PATHS=1
6+
7+
# build
8+
PHP_VERSION=7.4
9+
TIMEZONE=UTC
10+
NETWORKS_DRIVER=bridge
11+
12+
# application
13+
APP_USER=www-data
14+
APP_GROUP=www-data
15+
APP_USER_ID=1000
16+
APP_GROUP_ID=1000
17+
APP_CODE_PATH_HOST=../
18+
APP_CODE_PATH_CONTAINER=/var/www/current
19+
20+
# required so we can reach the nginx server from other containers via that hostname
21+
APP_HOST=standard-php-dev-env.local
22+
23+
# nginx
24+
NGINX_HOST_HTTP_PORT=8898
25+
NGINX_HOST_HTTPS_PORT=8899
26+
27+
# php-cli
28+
WORKSPACE_HOST_SSH_PORT=2239
29+
30+
# mysql
31+
MYSQL_ROOT_PASSWORD=S3cr3T
32+
MYSQL_DATABASE=test
33+
MYSQL_USER=dba
34+
MYSQL_PASSWORD=S3cr3T
35+
MYSQL_HOST_PORT=6089

.docker/.env.example

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Default settings for docker-compose
2+
# @see https://docs.docker.com/compose/reference/envvars/#compose_file
3+
COMPOSE_PROJECT_NAME=docker-php-tutorial
4+
COMPOSE_FILE=docker-compose.yml
5+
COMPOSE_CONVERT_WINDOWS_PATHS=1
6+
7+
# build
8+
PHP_VERSION=7.3
9+
TIMEZONE=UTC
10+
NETWORKS_DRIVER=bridge
11+
12+
# application
13+
APP_USER=www-data
14+
APP_GROUP=www-data
15+
APP_USER_ID=1000
16+
APP_GROUP_ID=1000
17+
APP_CODE_PATH_HOST=../
18+
APP_CODE_PATH_CONTAINER=/var/www/current
19+
20+
# required so we can reach the nginx server from other containers via that hostname
21+
APP_HOST=docker-php-tutorial.local
22+
23+
# nginx
24+
NGINX_HOST_HTTP_PORT=80
25+
NGINX_HOST_HTTPS_PORT=443
26+
27+
# workspace
28+
WORKSPACE_HOST_SSH_PORT=2222
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; enable opcache
2+
opcache.enable_cli = 1
3+
opcache.enable = 1
4+
opcache.fast_shutdown = 1
5+
; check with find . -type f -print | grep php | wc -l
6+
opcache.max_accelerated_files = 100
7+
; revalidate everytime
8+
opcache.revalidate_freq=0
9+
;opcache.validate_timestamps = 0
10+
opcache.memory_consumption=64
11+
opcache.interned_strings_buffer=12
12+
; enable xdebug
13+
xdebug.remote_enable=1
14+
xdebug.remote_host=host.docker.internal

.docker/.shared/scripts/cleanup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
apt-get clean
4+
rm -rf /var/lib/apt/lists/* \
5+
/tmp/* \
6+
/var/tmp/* \
7+
/var/log/lastlog \
8+
/var/log/faillog
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
APP_USER=$1
4+
APP_GROUP=$2
5+
APP_USER_ID=$3
6+
APP_GROUP_ID=$4
7+
8+
new_user_id_exists=$(id ${APP_USER_ID} > /dev/null 2>&1; echo $?)
9+
if [ "$new_user_id_exists" = "0" ]; then
10+
(>&2 echo "ERROR: APP_USER_ID $APP_USER_ID already exists - Aborting!");
11+
exit 1;
12+
fi
13+
14+
new_group_id_exists=$(getent group ${APP_GROUP_ID} > /dev/null 2>&1; echo $?)
15+
if [ "$new_group_id_exists" = "0" ]; then
16+
(>&2 echo "ERROR: APP_GROUP_ID $APP_GROUP_ID already exists - Aborting!");
17+
exit 1;
18+
fi
19+
20+
old_user_id=$(id -u ${APP_USER})
21+
old_user_exists=$(id -u ${APP_USER} > /dev/null 2>&1; echo $?)
22+
old_group_id=$(getent group ${APP_GROUP} | cut -d: -f3)
23+
old_group_exists=$(getent group ${APP_GROUP} > /dev/null 2>&1; echo $?)
24+
25+
if [ "$old_group_id" != "${APP_GROUP_ID}" ]; then
26+
# create the group
27+
groupadd -f ${APP_GROUP}
28+
# and the correct id
29+
groupmod -g ${APP_GROUP_ID} ${APP_GROUP}
30+
if [ "$old_group_exists" = "0" ]; then
31+
# set the permissions of all "old" files and folder to the new group
32+
find / -group $old_group_id -exec chgrp -h ${APP_GROUP} {} \; || true
33+
fi
34+
fi
35+
36+
if [ "$old_user_id" != "${APP_USER_ID}" ]; then
37+
# create the user if it does not exist
38+
if [ "$old_user_exists" != "0" ]; then
39+
useradd ${APP_USER} -g ${APP_GROUP}
40+
fi
41+
42+
# make sure the home directory exists with the correct permissions
43+
mkdir -p /home/${APP_USER} && chmod 755 /home/${APP_USER} && chown ${APP_USER}:${APP_GROUP} /home/${APP_USER}
44+
45+
# change the user id, set the home directory and make sure the user has a login shell
46+
usermod -u ${APP_USER_ID} -m -d /home/${APP_USER} ${APP_USER} -s $(which bash)
47+
48+
if [ "$old_user_exists" = "0" ]; then
49+
# set the permissions of all "old" files and folder to the new user
50+
find / -user $old_user_id -exec chown -h ${APP_USER} {} \; || true
51+
fi
52+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# fix for host.docker.internal not existing on linux https://github.com/docker/for-linux/issues/264
5+
# see https://dev.to/bufferings/access-host-from-a-docker-container-4099
6+
HOST_DOMAIN="host.docker.internal"
7+
# check if the host exists
8+
# see https://stackoverflow.com/a/24049165/413531
9+
if dig ${HOST_DOMAIN} | grep -q 'NXDOMAIN'
10+
then
11+
# on linux, it will fail - so we'll "manually" add the hostname in the host file
12+
HOST_IP=$(ip route | awk 'NR==1 {print $3}')
13+
echo "$HOST_IP\t$HOST_DOMAIN" >> /etc/hosts
14+
fi
15+
16+
exec "$@"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# add wget
4+
apt-get update -yqq && apt-get -f install -yyq wget
5+
6+
# download helper script
7+
# @see https://github.com/mlocati/docker-php-extension-installer/
8+
wget -q -O /usr/local/bin/install-php-extensions https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions \
9+
|| (echo "Failed while downloading php extension installer!"; exit 1)
10+
11+
# install extensions
12+
chmod uga+x /usr/local/bin/install-php-extensions && sync && install-php-extensions \
13+
opcache \
14+
xdebug \
15+
zip \
16+
pdo_mysql \
17+
;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
apt-get update -yqq && apt-get install -yqq \
4+
curl \
5+
dnsutils \
6+
gdb \
7+
git \
8+
htop \
9+
iproute2 \
10+
iputils-ping \
11+
ltrace \
12+
make \
13+
procps \
14+
strace \
15+
sudo \
16+
sysstat \
17+
unzip \
18+
vim \
19+
wget \
20+
;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
CONFIG_FILE=$1
4+
VAR_NAME=$2
5+
VAR_VALUE=$3
6+
7+
sed -i -e "s#${VAR_NAME}#${VAR_VALUE}#g" "${CONFIG_FILE}"
8+
9+
# cat "${CONFIG_FILE}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
TZ=$1
4+
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

0 commit comments

Comments
 (0)