Skip to content

Commit 3fe3051

Browse files
authored
Merge pull request #5 from OleksiiBulba/refactor-2
Refactor 2
2 parents bf4f427 + 513c7a6 commit 3fe3051

25 files changed

+770
-88
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Planned
99
- Add bin directory to checkout during installation, so it will be possible to use shell scripts.
10+
- Add github actions for installation tests;
11+
12+
### Added
13+
- Added more configs *.ini and php-fpm;
14+
- php writes logs to _/var/www/html/var/log/$pool.access.log_ and _/var/www/html/var/log/$pool.error.log_
15+
- xdebug writes logs to _/var/www/html/var/xdebug_
16+
- Added Dockerfile for php container;
17+
- Added entrypoint script, .bashrc;
18+
- Added `build` command that forces rebuilding containers in case Dockerfile for php container changed;
19+
- Added `rebuild` command that stops containers, run `build` command and starts containers again;
20+
- Added `run-test-install.sh` shell script, so everyone can run installation tests locally;
21+
- Added some files inside _tests/install_ folder for testing purposes;
22+
- Added docs/COMMANDS.md file with all available commands inside;
23+
24+
### Changed
25+
- Changed `ENV` variable to `APP_ENV` so it is the same as env variable in Symfony;
26+
- _docker-compose.*_ files moved to _.docker_ folder;
27+
- Created nginx conf template instead different conf files;
28+
- _.env.dist_ file moved to _.docker_ folder;
29+
- If _.env_ does not exist, it is created from _.docker/.env.dist_ file;
30+
- If _.env.local_, _.env.{APP_ENV}_, and _.env.{APP_ENV}.local_ do not exist, they are created as an empty files;
31+
- `restart` command does not require running project anymore, if project is not running, it just starts it.
32+
- `onlinesetup` script uses remote repository name `origin-install`;
33+
34+
### Fixed
35+
- Fixed project paths inside docker-compose containers;
1036

1137
## [0.1.0] - 2021-01-31
1238

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Makefile
2020

2121
To use dockerizer you need to install [make](https://www.gnu.org/software/make/) and [docker-compose](https://docs.docker.com/compose/install/).
2222

23+
Before installation, you should have already in your project:
24+
* _vendor_, _public_ and _src_ folders (for php packages, index.php file and source files respectfully) -- it is required because dockerizer mounts these folders into containers;
25+
* _composer.json_ and _composer.lock_ files (it ensures the project has been set up correctly);
26+
2327
### Installation
2428

2529
To install php-dockerizer into your project simply run command:
@@ -38,6 +42,11 @@ You can change `origin/master` to appropriate branch you want to use and `docker
3842

3943
Please feel free to open pull request or create an issue, they are more than welcome!
4044

45+
### Running tests
46+
47+
If you cloned the repo, you can run command `./tests/run-test-install.sh` to test installation process.
48+
Command `./tests/clean-test-install.sh` will uninstall dockerizer files from _tests/install_ folder.
49+
4150
## License
4251

4352
[MIT](https://opensource.org/licenses/MIT)

bin/onlinesetup

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
REPO=${1:-https://github.com/OleksiiBulba/php-dockerizer}
44
VERSION=${2:-origin/master}
5-
INSTALL_DIR=${3:-dockerizer}
5+
INSTALL_ROOT=${3:-./}
6+
INSTALL_DIR=${4:-dockerizer}
67

7-
mkdir $INSTALL_DIR; cd ./$INSTALL_DIR
8+
INSTALL_ROOT=$(realpath $INSTALL_ROOT)
9+
10+
CURRENT_DIR=$(pwd)
11+
cd $INSTALL_ROOT; mkdir $INSTALL_DIR; cd ./$INSTALL_DIR
812

913
git init -qqq
10-
git remote add origin $REPO
11-
git fetch origin -qqq
14+
git remote add origin-install $REPO
15+
git fetch origin-install -qqq
1216
git checkout $VERSION -- src
1317
# TODO: add bin folder so it will be possible to use shell scripts during installation
1418

@@ -17,3 +21,4 @@ shopt -s dotglob
1721
mv ./src/* ../
1822
$PREV_DOTGLOB
1923
cd ../; rm -rf ./$INSTALL_DIR
24+
cd $CURRENT_DIR

docs/COMMANDS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Commands
2+
3+
There are all available make commands:
4+
* **help** - Prints all available commands;
5+
* **run** - Run docker containers
6+
* **ps** - Show running containers
7+
* **stop** - Stops all containers
8+
* **restart** - Stops and runs again all containers
9+
* **build** - Rebuild php container if there is any changes
10+
* **rebuild** - Stops containers (if running), rebuilds php container (see build command) and starts containers back
11+
* **logs** - Show containers logs
12+
* **bash** - Show containers logs

src/.docker/.env.dist

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#APP_ENV=dev
2-
#
3-
## defines prefix to all container names
4-
##PROJECT_NAME=project
5-
#
6-
## MySQL database
7-
#MYSQL_HOST=localhost
8-
#MYSQL_USER=db_user
9-
#MYSQL_PASSWORD=db_password
10-
## Change it on production!
11-
#MYSQL_ROOT_PASSWORD=root
12-
#MYSQL_DATABASE=project
13-
#
14-
## Nginx
15-
#NGINX_HOST=website.local
1+
APP_ENV=dev
2+
3+
# defines prefix to all container names
4+
#PROJECT_NAME=project
5+
6+
# MySQL database
7+
MYSQL_HOST=localhost
8+
MYSQL_USER=db_user
9+
MYSQL_PASSWORD=db_password
10+
# Change it on production!
11+
MYSQL_ROOT_PASSWORD=root
12+
MYSQL_DATABASE=project
13+
14+
# Nginx
15+
NGINX_HOST=localhost

src/.docker/build/nginx/templates/default.conf.template

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,49 @@ server {
1212
try_files $uri /index.php$is_args$args;
1313
}
1414

15-
location /public {
16-
alias ${SITE_ROOT};
17-
add_header X-Frame-Options "SAMEORIGIN";
18-
}
19-
2015
# optionally disable falling back to PHP script for the asset directories;
2116
# nginx will return a 404 error when files are not found instead of passing the
2217
# request to Symfony (improves performance but Symfony's 404 page is not displayed)
23-
#location /bundles {
24-
# try_files $uri =404;
25-
#}
26-
27-
index index.php;
28-
autoindex off;
29-
charset off;
18+
# location /bundles {
19+
# try_files $uri =404;
20+
# }
3021

3122
add_header 'X-Content-Type-Options' 'nosniff';
3223
add_header 'X-XSS-Protection' '1; mode=block';
3324

34-
3525
location ~ ^/index\.php(/|$) {
36-
try_files $uri =404;
3726
fastcgi_pass fastcgi_backend;
27+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
28+
include fastcgi_params;
3829

3930
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
4031
fastcgi_param PHP_VALUE "max_execution_time=600";
4132
fastcgi_read_timeout 600s;
4233
fastcgi_connect_timeout 600s;
4334

4435
fastcgi_index index.php;
45-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
46-
fastcgi_param DOCUMENT_ROOT $realpath_root;
47-
include fastcgi_params;
4836

37+
# optionally set the value of the environment variables used in the application
38+
# fastcgi_param APP_ENV prod;
39+
# fastcgi_param APP_SECRET <app-secret-id>;
40+
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";
41+
42+
# When you are using symlinks to link the document root to the
43+
# current version of your application, you should pass the real
44+
# application path instead of the path to the symlink to PHP
45+
# FPM.
46+
# Otherwise, PHP's OPcache may not properly detect changes to
47+
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
48+
# for more information).
49+
# Caveat: When PHP-FPM is hosted on a different machine from nginx
50+
# $realpath_root may not resolve as you expect! In this case try using
51+
# $document_root instead.
52+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
53+
fastcgi_param DOCUMENT_ROOT $realpath_root;
54+
include fastcgi_params;
55+
# Prevents URIs that include the front controller. This will 404:
56+
# http://domain.tld/index.php/some-path
57+
# Remove the internal directive to allow URIs like this
4958
internal;
5059
}
5160

src/.docker/build/php/Dockerfile

Lines changed: 124 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,124 @@
1-
ARG PHP_VERSION=8.0.2
2-
3-
# alpine
4-
FROM php:${PHP_VERSION}-fpm-alpine
5-
RUN apk update \
6-
&& apk add --no-cache $PHPIZE_DEPS \
7-
bash \
8-
git \
9-
zip \
10-
unzip
11-
12-
# PHP extensions
13-
RUN docker-php-ext-install opcache pdo_mysql mysqli
14-
RUN docker-php-ext-enable opcache
15-
#
16-
17-
# xdebug extensions
18-
RUN pecl install xdebug
19-
RUN docker-php-ext-enable xdebug
20-
#
21-
22-
# Composer
23-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
24-
#
25-
26-
RUN rm -rf /var/cache/apk/*
27-
28-
CMD ["php-fpm", "--nodaemonize"]
1+
ARG PHP_VERSION=8.0.6
2+
FROM php:${PHP_VERSION}-fpm
3+
4+
ENV INSTALL_DIR /var/www/html
5+
ENV SSH_USER root
6+
ENV SSH_PASSWORD root
7+
8+
# sodium
9+
# php ^7.2
10+
RUN apt-get update && apt-cache search libsodium && apt-get install -y libsodium-dev # libsodium18
11+
12+
# Install System Dependencies
13+
RUN requirements="libcurl3-dev libfreetype6 libjpeg62-turbo libjpeg62-turbo-dev libpng-dev libfreetype6-dev libicu-dev libxslt1-dev" \
14+
apt-get update \
15+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common \
16+
&& apt-get update \
17+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
18+
libcurl3-dev libfreetype6 libjpeg62-turbo libjpeg62-turbo-dev libpng-dev libfreetype6-dev libicu-dev libxslt1-dev \
19+
libicu-dev \
20+
libssl-dev \
21+
libedit-dev \
22+
libedit2 \
23+
libxslt1-dev \
24+
apt-utils \
25+
gnupg \
26+
redis-tools \
27+
default-mysql-client \
28+
git \
29+
vim \
30+
nano \
31+
wget \
32+
curl \
33+
lynx \
34+
psmisc \
35+
libzip-dev \
36+
libonig-dev \
37+
unzip \
38+
tar \
39+
cron \
40+
bash-completion \
41+
&& apt-get clean
42+
43+
# Install XDebug
44+
RUN yes | pecl install xdebug && \
45+
echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini
46+
47+
RUN docker-php-ext-configure \
48+
gd --with-freetype=/usr/include/ \
49+
--with-jpeg=/usr/include/ \
50+
&& docker-php-ext-install gd \
51+
&& docker-php-ext-install zip \
52+
&& docker-php-ext-install intl \
53+
&& docker-php-ext-install xsl \
54+
&& docker-php-ext-install soap \
55+
&& docker-php-ext-install bcmath \
56+
&& docker-php-ext-install sodium \
57+
&& docker-php-ext-install pdo_mysql \
58+
&& docker-php-ext-install sockets \
59+
&& docker-php-ext-enable xdebug \
60+
&& apt-get purge --auto-remove -y libcurl3-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev
61+
62+
# Install OpenSSH server
63+
RUN apt-get update \
64+
&& apt-get install -y openssh-server \
65+
sudo \
66+
openssh-server
67+
RUN mkdir /var/run/sshd
68+
RUN echo "${SSH_USER}:${SSH_PASSWORD}" | chpasswd
69+
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
70+
# SSH login fix. Otherwise user is kicked off after login
71+
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
72+
EXPOSE 22
73+
74+
# Install oAuth
75+
RUN apt-get update \
76+
&& apt-get install -y \
77+
libpcre3 \
78+
libpcre3-dev \
79+
# php-pear \
80+
&& pecl install oauth \
81+
&& echo "extension=oauth.so" > /usr/local/etc/php/conf.d/docker-php-ext-oauth.ini
82+
83+
# Install Node, NVM, NPM and Grunt
84+
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - \
85+
&& apt-get install -y nodejs build-essential \
86+
&& curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | sh \
87+
&& npm i -g grunt-cli yarn requirejs
88+
89+
# Install Composer
90+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
91+
ENV PATH="/var/www/.composer/vendor/bin/:${PATH}"
92+
93+
RUN echo "memory_limit=2048M" >> /usr/local/etc/php/conf.d/common.ini \
94+
&& echo "max_execution_time=1000" >> /usr/local/etc/php/conf.d/common.ini \
95+
&& echo "max_input_time=1000" >> /usr/local/etc/php/conf.d/common.ini
96+
97+
# Install Mhsendmail
98+
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install golang-go \
99+
&& mkdir /opt/go \
100+
&& export GOPATH=/opt/go \
101+
&& go get github.com/mailhog/mhsendmail
102+
103+
# Configuring system
104+
COPY ./config/ini/ /usr/local/etc/php/conf.d/
105+
COPY ./config/php-fpm/ /usr/local/etc/php-fpm/
106+
COPY ./bin/* /usr/local/bin/
107+
COPY ./users/* /var/www/
108+
COPY ./config/crontab /etc/cron.d/crontab
109+
RUN chmod +x /usr/local/bin/*
110+
111+
RUN chmod 777 -Rf /var/www /var/www/.* \
112+
&& chown -Rf www-data:www-data /var/www /var/www/.* \
113+
&& usermod -u 1000 www-data \
114+
&& chsh -s /bin/bash www-data
115+
116+
COPY ./bin/ /docker/scripts
117+
RUN chown -R www-data /docker/scripts/*
118+
RUN chmod ug+rx /docker/scripts/*
119+
120+
VOLUME ${INSTALL_DIR}
121+
WORKDIR ${INSTALL_DIR}
122+
USER www-data
123+
124+
CMD bash -c '/docker/scripts/entrypoint'

src/.docker/build/php/bin/entrypoint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
php-fpm

src/.docker/build/php/config/crontab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# * * * * * /usr/local/bin/php /var/www/html/bin/cron "cron options" >> /var/www/html/var/log/cron.log

src/.docker/build/php/php.ini renamed to src/.docker/build/php/config/ini/php.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ date.timezone = "UTC"
55
upload_max_filesize = 128M
66
zlib.output_compression = on
77
log_errors = On
8-
display_errors = Off
9-
;sendmail_path = "/opt/go/bin/mhsendmail --smtp-addr='mailhog:1025'"
8+
display_errors = On
9+
sendmail_path = "/opt/go/bin/mhsendmail --smtp-addr='mailhog:1025'"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
xdebug.idekey="PHPSTORM"
22
xdebug.mode=develop,debug
3+
xdebug.discover_client_host=true
34
xdebug.client_host=host.docker.internal
45
xdebug.client_port=9003
56
xdebug.start_with_request=yes
67
xdebug.remote_handler=dbgp
7-
xdebug.output_dir="/app/var/log/xdebug"
8-
xdebug.discover_client_host=true
8+
xdebug.output_dir="/var/www/html/var/xdebug"
99
xdebug.cli_color=1
1010
xdebug.var_display_max_depth=15
1111
xdebug.remote_cookie_expire_time=-9999
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[global]
2+
error_log = /var/www/html/var/log/$pool.error.log
3+
4+
; https://github.com/docker-library/php/pull/725#issuecomment-443540114
5+
;log_limit = 8192
6+
7+
[www]
8+
; if we send this to /proc/self/fd/1, it never appears
9+
access.log = /var/www/html/var/log/$pool.access.log
10+
11+
clear_env = no
12+
13+
; Ensure worker stdout and stderr are sent to the main error log.
14+
catch_workers_output = yes
15+
decorate_workers_output = no

0 commit comments

Comments
 (0)