Skip to content

Commit

Permalink
Merge pull request #6 from OleksiiBulba/release/0.2.0
Browse files Browse the repository at this point in the history
Release/0.2.0
  • Loading branch information
OleksiiBulba authored Jul 19, 2021
2 parents 6c5d1ee + dd6c8fe commit 7a4ee04
Show file tree
Hide file tree
Showing 31 changed files with 867 additions and 175 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
/src/.dc-running
/src/composer.json
/src/composer.lock
/src/index.php
/src/public/
/src/src/
/src/vendor/
/tests/install/*
!/tests/install/.gitkeep
!/tests/install/.gitkeep
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Planned
- Add bin directory to checkout during installation, so it will be possible to use shell scripts.
- Add github actions for installation tests;

## [0.2.0] - 2021-07-19

### Added
- Added more configs *.ini and php-fpm;
- php writes logs to _/var/www/html/var/log/$pool.access.log_ and _/var/www/html/var/log/$pool.error.log_
- xdebug writes logs to _/var/www/html/var/xdebug_
- Added Dockerfile for php container;
- Added entrypoint script, .bashrc;
- Added `build` command that forces rebuilding containers in case Dockerfile for php container changed;
- Added `rebuild` command that stops containers, run `build` command and starts containers again;
- Added `run-test-install.sh` shell script, so everyone can run installation tests locally;
- Added some files inside _tests/install_ folder for testing purposes;
- Added docs/COMMANDS.md file with all available commands inside;
- Added crontab;

### Changed
- Changed `ENV` variable to `APP_ENV` so it is the same as env variable in Symfony;
- _docker-compose.*_ files moved to _.docker_ folder;
- Created nginx conf template instead different conf files;
- _.env.dist_ file moved to _.docker_ folder;
- If _.env_ does not exist, it is created from _.docker/.env.dist_ file;
- If _.env.local_, _.env.{APP_ENV}_, and _.env.{APP_ENV}.local_ do not exist, they are created as an empty files;
- `restart` command does not require running project anymore, if project is not running, it just starts it.
- `onlinesetup` script uses remote repository name `origin-install`;

### Fixed
- Fixed project paths inside docker-compose containers;

## [0.1.0] - 2021-01-31

Expand All @@ -25,4 +54,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **ps** shows running containers;
- **logs** shows container logs;
- **bash** enters to php container with bash;
- _.env.dist_ file as an example for _.env_ file
- _.env.dist_ file as an example for _.env_ file
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

This project is intended to help php developers to dockerize their projects. The difference of this project from
others similar is simplicity: you run single bash command and get power of make commands with set of docker-compose
files for different purposes. After installing php-dockerizer into your project you can commit only files you want
files for different purposes. After installing php-dockerizer into your project, you can commit only files you want
to keep.

## Usage

Usage of the dockerizer is pretty simple: you run online install command, it fetches changes from install repository to your project and you can commit files you want to keep.
Keep in mind that dockerizer will copy the list of the files and directories to the root of your project:
Usage of the dockerizer is pretty simple: you run online install command, it fetches changes from a source repository to your project, and you can commit files you want to keep.
Keep in mind that dockerizer will copy these files and directories to the root of your project:
```text
Makefile
.docker
.make
```
* In future dockerizer will be able to detect if there is any file conflicts with your existing files, or
* In future dockerizer will be able to detect if there is any file conflicts with your existing files.

### Requirements

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

Before installation, you should have already in your project:
* _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;
* _composer.json_ and _composer.lock_ files (it ensures the project has been set up correctly);

### Installation

To install php-dockerizer simply run command:
To install php-dockerizer into your project simply run command:
```shell
curl -s https://raw.githubusercontent.com/OleksiiBulba/php-dockerizer/master/bin/onlinesetup | bash -s -- https://github.com/OleksiiBulba/php-dockerizer origin/master dockerizer
```
Expand All @@ -31,12 +36,17 @@ If you cloned repository to your github account, you can install php-dockerizer
curl -s https://raw.githubusercontent.com/{you-github-username}/php-dockerizer/master/bin/onelinesetup | bash -s -- https://github.com/{you-github-username}/php-dockerizer origin/master dockerizer
```

You can change `origin/master` to appropriate branch you want to use, and `dockerizer` to any directory name that does not exist in your repo, do not worry, it will be removed after installation.
You can change `origin/master` to appropriate branch you want to use and `dockerizer` to any directory name that does not exist in your repo; do not worry, the directory will be removed after installation.

## Contributing

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

### Running tests

If you cloned the repo, you can run command `./tests/run-test-install.sh` to test installation process.
Command `./tests/clean-test-install.sh` will uninstall dockerizer files from _tests/install_ folder.

## License

[MIT](https://opensource.org/licenses/MIT)
13 changes: 9 additions & 4 deletions bin/onlinesetup
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

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

mkdir $INSTALL_DIR; cd ./$INSTALL_DIR
INSTALL_ROOT=$(realpath $INSTALL_ROOT)

CURRENT_DIR=$(pwd)
cd $INSTALL_ROOT; mkdir $INSTALL_DIR; cd ./$INSTALL_DIR

git init -qqq
git remote add origin $REPO
git fetch origin -qqq
git remote add origin-install $REPO
git fetch origin-install -qqq
git checkout $VERSION -- src
# TODO: add bin folder so it will be possible to use shell scripts during installation

Expand All @@ -17,3 +21,4 @@ shopt -s dotglob
mv ./src/* ../
$PREV_DOTGLOB
cd ../; rm -rf ./$INSTALL_DIR
cd $CURRENT_DIR
12 changes: 12 additions & 0 deletions docs/COMMANDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Commands

There are all available make commands:
* **help** - Prints all available commands;
* **run** - Run docker containers
* **ps** - Show running containers
* **stop** - Stops all containers
* **restart** - Stops and runs again all containers
* **build** - Rebuild php container if there is any changes
* **rebuild** - Stops containers (if running), rebuilds php container (see build command) and starts containers back
* **logs** - Show containers logs
* **bash** - Show containers logs
4 changes: 2 additions & 2 deletions src/.env.dist → src/.docker/.env.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENV=dev
APP_ENV=dev

# defines prefix to all container names
#PROJECT_NAME=project
Expand All @@ -12,4 +12,4 @@ MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=project

# Nginx
NGINX_HOST=website.local
NGINX_HOST=localhost
69 changes: 69 additions & 0 deletions src/.docker/build/nginx/templates/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
upstream fastcgi_backend {
server php:9000;
}

server {
listen ${NGINX_PORT};
server_name ${NGINX_HOST};
root ${SITE_ROOT};

location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}

# optionally disable falling back to PHP script for the asset directories;
# nginx will return a 404 error when files are not found instead of passing the
# request to Symfony (improves performance but Symfony's 404 page is not displayed)
# location /bundles {
# try_files $uri =404;
# }

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

location ~ ^/index\.php(/|$) {
fastcgi_pass fastcgi_backend;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;

fastcgi_index index.php;

# optionally set the value of the environment variables used in the application
# fastcgi_param APP_ENV prod;
# fastcgi_param APP_SECRET <app-secret-id>;
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
# Caveat: When PHP-FPM is hosted on a different machine from nginx
# $realpath_root may not resolve as you expect! In this case try using
# $document_root instead.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
124 changes: 124 additions & 0 deletions src/.docker/build/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
ARG PHP_VERSION=8.0.6
FROM php:${PHP_VERSION}-fpm

ENV INSTALL_DIR /var/www/html
ENV SSH_USER root
ENV SSH_PASSWORD root

# sodium
# php ^7.2
RUN apt-get update && apt-cache search libsodium && apt-get install -y libsodium-dev # libsodium18

# Install System Dependencies
RUN requirements="libcurl3-dev libfreetype6 libjpeg62-turbo libjpeg62-turbo-dev libpng-dev libfreetype6-dev libicu-dev libxslt1-dev" \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
libcurl3-dev libfreetype6 libjpeg62-turbo libjpeg62-turbo-dev libpng-dev libfreetype6-dev libicu-dev libxslt1-dev \
libicu-dev \
libssl-dev \
libedit-dev \
libedit2 \
libxslt1-dev \
apt-utils \
gnupg \
redis-tools \
default-mysql-client \
git \
vim \
nano \
wget \
curl \
lynx \
psmisc \
libzip-dev \
libonig-dev \
unzip \
tar \
cron \
bash-completion \
&& apt-get clean

# Install XDebug
RUN yes | pecl install xdebug && \
echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini

RUN docker-php-ext-configure \
gd --with-freetype=/usr/include/ \
--with-jpeg=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install zip \
&& docker-php-ext-install intl \
&& docker-php-ext-install xsl \
&& docker-php-ext-install soap \
&& docker-php-ext-install bcmath \
&& docker-php-ext-install sodium \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install sockets \
&& docker-php-ext-enable xdebug \
&& apt-get purge --auto-remove -y libcurl3-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev

# Install OpenSSH server
RUN apt-get update \
&& apt-get install -y openssh-server \
sudo \
openssh-server
RUN mkdir /var/run/sshd
RUN echo "${SSH_USER}:${SSH_PASSWORD}" | chpasswd
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
EXPOSE 22

# Install oAuth
RUN apt-get update \
&& apt-get install -y \
libpcre3 \
libpcre3-dev \
# php-pear \
&& pecl install oauth \
&& echo "extension=oauth.so" > /usr/local/etc/php/conf.d/docker-php-ext-oauth.ini

# Install Node, NVM, NPM and Grunt
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - \
&& apt-get install -y nodejs build-essential \
&& curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | sh \
&& npm i -g grunt-cli yarn requirejs

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
ENV PATH="/var/www/.composer/vendor/bin/:${PATH}"

RUN echo "memory_limit=2048M" >> /usr/local/etc/php/conf.d/common.ini \
&& echo "max_execution_time=1000" >> /usr/local/etc/php/conf.d/common.ini \
&& echo "max_input_time=1000" >> /usr/local/etc/php/conf.d/common.ini

# Install Mhsendmail
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install golang-go \
&& mkdir /opt/go \
&& export GOPATH=/opt/go \
&& go get github.com/mailhog/mhsendmail

# Configuring system
COPY ./config/ini/ /usr/local/etc/php/conf.d/
COPY ./config/php-fpm/ /usr/local/etc/php-fpm/
COPY ./bin/* /usr/local/bin/
COPY ./users/* /var/www/
COPY ./config/crontab /etc/cron.d/crontab
RUN chmod +x /usr/local/bin/*

RUN chmod 777 -Rf /var/www /var/www/.* \
&& chown -Rf www-data:www-data /var/www /var/www/.* \
&& usermod -u 1000 www-data \
&& chsh -s /bin/bash www-data

COPY ./bin/ /docker/scripts
RUN chown -R www-data /docker/scripts/*
RUN chmod ug+rx /docker/scripts/*

VOLUME ${INSTALL_DIR}
WORKDIR ${INSTALL_DIR}
USER www-data

CMD bash -c '/docker/scripts/entrypoint'
3 changes: 3 additions & 0 deletions src/.docker/build/php/bin/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

php-fpm
1 change: 1 addition & 0 deletions src/.docker/build/php/config/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# * * * * * /usr/local/bin/php /var/www/html/bin/cron "cron options" >> /var/www/html/var/log/cron.log
10 changes: 10 additions & 0 deletions src/.docker/build/php/config/ini/opcache.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 512M
opcache.max_accelerated_files = 100000
opcache.validate_timestamps=0
opcache.consistency_checks=0
opcache.interned_strings_buffer=8
opcache.fast_shutdown=1
opcache.revalidate_freq = 0
opcache.revalidate_path = 1
9 changes: 9 additions & 0 deletions src/.docker/build/php/config/ini/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
memory_limit = 2048M
max_execution_time = 38000
always_populate_raw_post_data = -1
date.timezone = "UTC"
upload_max_filesize = 128M
zlib.output_compression = on
log_errors = On
display_errors = On
sendmail_path = "/opt/go/bin/mhsendmail --smtp-addr='mailhog:1025'"
Loading

0 comments on commit 7a4ee04

Please sign in to comment.