make Mongo, xDebug, Node, and prestissimo Installation Optional

on the Workspace and PHP-FPM Containers

+ general refactoring
This commit is contained in:
Mahmoud Zalt 2016-07-25 06:25:38 +03:00
parent 419434020c
commit e1dbb972f1
5 changed files with 240 additions and 101 deletions

120
README.md
View File

@ -48,11 +48,13 @@ It's like Laravel Homestead but for Docker instead of Vagrant.
- [Install PHP Extensions](#Install-PHP-Extensions) - [Install PHP Extensions](#Install-PHP-Extensions)
- [Change the PHP-FPM Version](#Change-the-PHP-FPM-Version) - [Change the PHP-FPM Version](#Change-the-PHP-FPM-Version)
- [Change the PHP-CLI Version](#Change-the-PHP-CLI-Version) - [Change the PHP-CLI Version](#Change-the-PHP-CLI-Version)
- [Install xDebug](#Install-xDebug)
- [Misc](#Misc) - [Misc](#Misc)
- [Run a Docker Virtual Host](#Run-Docker-Virtual-Host) - [Run a Docker Virtual Host](#Run-Docker-Virtual-Host)
- [Find your Docker IP Address](#Find-Docker-IP-Address) - [Find your Docker IP Address](#Find-Docker-IP-Address)
- [Use custom Domain](#Use-custom-Domain) - [Use custom Domain](#Use-custom-Domain)
- [Install Prestissimo](#Install-Prestissimo) - [Install Prestissimo](#Install-Prestissimo)
- [Install Node + NVM](#Install-Node)
- [Debugging](#debugging) - [Debugging](#debugging)
- [Help & Questions](#Help) - [Help & Questions](#Help)
@ -577,14 +579,47 @@ composer require predis/predis:^1.0
<a name="Use-Mongo"></a> <a name="Use-Mongo"></a>
### Use Mongo ### Use Mongo
1 - First make sure you run the MongoDB Container (`mongo`) with the `docker-compose up` command. 1 - First install `mongo` in the Workspace and the PHP-FPM Containers:
<br>
a) open the `docker-compose.yml` file
<br>
b) search for the `INSTALL_MONGO` argument under the Workspace Container
<br>
c) set it to `true`
<br>
d) search for the `INSTALL_MONGO` argument under the PHP-FPM Container
<br>
e) set it to `true`
It should be like this:
```yml
workspace:
build:
context: ./workspace
args:
- INSTALL_MONGO=true
...
php-fpm:
build:
context: ./php-fpm
args:
- INSTALL_MONGO=true
...
```
2 - Re-build the containers docker-compose build workspace php-fpm
3 - Run the MongoDB Container (`mongo`) with the `docker-compose up` command.
```bash ```bash
docker-compose up -d mongo docker-compose up -d mongo
``` ```
2 - Add the MongoDB configurations to the `config/database.php` config file: 4 - Add the MongoDB configurations to the `config/database.php` config file:
```php ```php
'connections' => [ 'connections' => [
@ -606,21 +641,21 @@ docker-compose up -d mongo
], ],
``` ```
3 - Open your Laravel's `.env` file and update the following variables: 5 - Open your Laravel's `.env` file and update the following variables:
- set the `DB_HOST` to your `Docker-IP`. - set the `DB_HOST` to your `Docker-IP`.
- set the `DB_PORT` to `27017`. - set the `DB_PORT` to `27017`.
- set the `DB_DATABASE` to `database`. - set the `DB_DATABASE` to `database`.
4 - Finally make sure you have the `jenssegers/mongodb` package installed via Composer and its Service Provider is added. 6 - Finally make sure you have the `jenssegers/mongodb` package installed via Composer and its Service Provider is added.
```bash ```bash
composer require jenssegers/mongodb composer require jenssegers/mongodb
``` ```
More details about this [here](https://github.com/jenssegers/laravel-mongodb#installation). More details about this [here](https://github.com/jenssegers/laravel-mongodb#installation).
5 - Test it: 7 - Test it:
- First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent). - First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent).
- Enter the Workspace Container `docker exec -it laradock_workspace_1 bash`. - Enter the Workspace Container `docker exec -it laradock_workspace_1 bash`.
@ -732,10 +767,42 @@ Right now you have to manually edit the `Dockerfile` or create a new one like it
<br>
<a name="Install-xDebug"></a>
### Install xDebug
1 - First install `xDebug` in the Workspace and the PHP-FPM Containers:
<br>
a) open the `docker-compose.yml` file
<br>
b) search for the `INSTALL_XDEBUG` argument under the Workspace Container
<br>
c) set it to `true`
<br>
d) search for the `INSTALL_XDEBUG` argument under the PHP-FPM Container
<br>
e) set it to `true`
It should be like this:
```yml
workspace:
build:
context: ./workspace
args:
- INSTALL_XDEBUG=true
...
php-fpm:
build:
context: ./php-fpm
args:
- INSTALL_XDEBUG=true
...
```
2 - Re-build the containers docker-compose build workspace php-fpm
3 - Use it
@ -843,7 +910,48 @@ server_name laravel.dev;
<a name="Install-Prestissimo"></a> <a name="Install-Prestissimo"></a>
### Install Prestissimo ### Install Prestissimo
[Prestissimo](https://github.com/hirak/prestissimo) is a plugin for composer which enables parallel install functionality. You can enable Prestissimo by setting `INSTALL_PRESTISSIMO=true` in the `docker-compose.yml` file. [Prestissimo](https://github.com/hirak/prestissimo) is a plugin for composer which enables parallel install functionality.
To install Prestissimo in the Workspace container
1 - Open the `docker-compose.yml` file
2 - Search for the `INSTALL_PRESTISSIMO` argument under the Workspace Container and set it to `true`
It should be like this:
```yml
workspace:
build:
context: ./workspace
args:
- INSTALL_PRESTISSIMO=true
...
```
3 - Re-build the container docker-compose build workspace
<a name="Install-Node"></a>
### Install Node + NVM
To install NVM and NodeJS in the Workspace container
1 - Open the `docker-compose.yml` file
2 - Search for the `INSTALL_NODE` argument under the Workspace Container and set it to `true`
It should be like this:
```yml
workspace:
build:
context: ./workspace
args:
- INSTALL_NODE=true
...
```
3 - Re-build the container docker-compose build workspace
<br> <br>
<a name="debugging"></a> <a name="debugging"></a>

View File

@ -2,6 +2,36 @@ version: '2'
services: services:
### Workspace Utilities Container ###########################
workspace:
build:
context: ./workspace
args:
- INSTALL_MONGO=false
- INSTALL_XDEBUG=false
- INSTALL_NODE=false
- INSTALL_PRESTISSIMO=false
volumes_from:
- volumes_source
tty: true
### PHP-FPM Container #######################################
php-fpm:
build:
context: ./php-fpm
args:
- INSTALL_MONGO=false
- INSTALL_XDEBUG=false
dockerfile: Dockerfile-70
volumes_from:
- volumes_source
expose:
- "9000"
links:
- workspace
### Nginx Server Container ################################## ### Nginx Server Container ##################################
nginx: nginx:
@ -19,19 +49,6 @@ services:
links: links:
- php-fpm - php-fpm
### PHP-FPM Container #######################################
php-fpm:
build:
context: ./php-fpm
dockerfile: Dockerfile-70
volumes_from:
- volumes_source
expose:
- "9000"
links:
- workspace
### HHVM Container ########################################## ### HHVM Container ##########################################
hhvm: hhvm:
@ -144,16 +161,20 @@ services:
links: links:
- beanstalkd - beanstalkd
### Workspace Utilities Container ########################### ### Caddy Server Container ##################################
workspace: caddy:
build: build: ./caddy
context: ./workspace
args:
- INSTALL_PRESTISSIMO=false
volumes_from: volumes_from:
- volumes_source - volumes_source
tty: true ports:
- "80:80"
- "443:443"
- "2015:2015"
volumes:
- ./caddy/Caddyfile:/etc/Caddyfile
links:
- php-fpm
### Laravel Application Code Container ###################### ### Laravel Application Code Container ######################
@ -175,20 +196,4 @@ services:
- /var/lib/neo4j:/var/lib/neo4j/data - /var/lib/neo4j:/var/lib/neo4j/data
- /var/lib/mongo:/data/db - /var/lib/mongo:/data/db
### Caddy Server Container ##################################
# Edit the Caddyfile if needed (./caddy/Caddyfile)
caddy:
build: ./caddy
volumes_from:
- volumes_source
ports:
- "80:80"
- "443:443"
- "2015:2015"
volumes:
- ./caddy/Caddyfile:/etc/Caddyfile
links:
- php-fpm
### Add more Containers below ############################### ### Add more Containers below ###############################

View File

@ -21,8 +21,8 @@ ADD ./laravel.pool.conf /usr/local/etc/php-fpm.d/
# Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev", # Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev",
# "libpng12-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev", # "libpng12-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev",
RUN apt-get update \ RUN apt-get update && \
&& apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
curl \ curl \
libmemcached-dev \ libmemcached-dev \
libz-dev \ libz-dev \
@ -43,18 +43,26 @@ RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install pdo_pgsql RUN docker-php-ext-install pdo_pgsql
# Install the PHP gd library # Install the PHP gd library
RUN docker-php-ext-install gd \ RUN docker-php-ext-install gd && \
&& docker-php-ext-configure gd \ docker-php-ext-configure gd \
--enable-gd-native-ttf \ --enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \ --with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 --with-freetype-dir=/usr/include/freetype2
# Install the mongodb extention ARG INSTALL_MONGO=true
RUN pecl install mongodb ENV INSTALL_MONGO ${INSTALL_MONGO}
RUN if [ ${INSTALL_MONGO} = true ]; then \
# Install the mongodb extention
pecl install mongodb \
;fi
# Install the xdebug extention ARG INSTALL_XDEBUG=true
RUN pecl install xdebug \ ENV INSTALL_XDEBUG ${INSTALL_XDEBUG}
&& docker-php-ext-enable xdebug RUN if [ ${INSTALL_XDEBUG} = true ]; then \
# Install the xdebug extention
pecl install xdebug && \
docker-php-ext-enable xdebug \
;fi
# #
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------

View File

@ -21,8 +21,8 @@ ADD ./laravel.pool.conf /usr/local/etc/php-fpm.d/
# Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev", # Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev",
# "libpng12-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev", # "libpng12-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev",
RUN apt-get update \ RUN apt-get update && \
&& apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
curl \ curl \
libmemcached-dev \ libmemcached-dev \
libz-dev \ libz-dev \
@ -43,18 +43,26 @@ RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install pdo_pgsql RUN docker-php-ext-install pdo_pgsql
# Install the PHP gd library # Install the PHP gd library
RUN docker-php-ext-install gd \ RUN docker-php-ext-install gd && \
&& docker-php-ext-configure gd \ docker-php-ext-configure gd \
--enable-gd-native-ttf \ --enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \ --with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 --with-freetype-dir=/usr/include/freetype2
# Install the mongodb extention ARG INSTALL_MONGO=true
RUN pecl install mongodb ENV INSTALL_MONGO ${INSTALL_MONGO}
RUN if [ ${INSTALL_MONGO} = true ]; then \
# Install the mongodb extention
pecl install mongodb \
;fi
# Install the xdebug extention ARG INSTALL_XDEBUG=true
RUN pecl install xdebug \ ENV INSTALL_XDEBUG ${INSTALL_XDEBUG}
&& docker-php-ext-enable xdebug RUN if [ ${INSTALL_XDEBUG} = true ]; then \
# Install the xdebug extention
pecl install xdebug && \
docker-php-ext-enable xdebug \
;fi
# Install the memcached extention # Install the memcached extention
RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-memcached/archive/php7.tar.gz" \ RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-memcached/archive/php7.tar.gz" \

View File

@ -17,22 +17,19 @@ ENV LC_CTYPE=UTF-8
ENV LANG=en_US.UTF-8 ENV LANG=en_US.UTF-8
ENV TERM xterm ENV TERM xterm
# Add the "PHP 7" ppa
RUN apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ondrej/php
# #
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Software's Installation # Software's Installation
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# #
# Install "software-properties-common" (for the "add-apt-repository") # Install "PHP Extentions", "libraries", "Software's"
RUN apt-get update && apt-get install -y \ RUN apt-get update && \
software-properties-common apt-get install -y --force-yes \
# Add the "PHP 7" ppa
RUN add-apt-repository -y \
ppa:ondrej/php
# Install "PHP-CLI 7", "PHP extentions", "useful Tools"
RUN apt-get update && apt-get install -y --force-yes \
php7.0-cli \ php7.0-cli \
php7.0-common \ php7.0-common \
php7.0-curl \ php7.0-curl \
@ -47,53 +44,65 @@ RUN apt-get update && apt-get install -y --force-yes \
php7.0-zip \ php7.0-zip \
php7.0-memcached \ php7.0-memcached \
php7.0-gd \ php7.0-gd \
php7.0-xdebug \ pkg-config \
php-dev \ php-dev \
libcurl4-openssl-dev \ libcurl4-openssl-dev \
libedit-dev \ libedit-dev \
libssl-dev \ libssl-dev \
libxml2-dev \ libxml2-dev \
xz-utils \ xz-utils \
sqlite3 \
libsqlite3-dev \ libsqlite3-dev \
sqlite3 \
git \ git \
curl \ curl \
vim \ vim \
nano \ nano \
pkg-config && apt-get clean
# Clean up now, to free up some space
RUN apt-get clean
# Composer: Install composer and add its bin to the PATH. # Composer: Install composer and add its bin to the PATH.
RUN curl -s http://getcomposer.org/installer | php \ RUN curl -s http://getcomposer.org/installer | php && \
&& echo "export PATH=${PATH}:/var/www/laravel/vendor/bin" >> ~/.bashrc \ echo "export PATH=${PATH}:/var/www/laravel/vendor/bin" >> ~/.bashrc && \
&& mv composer.phar /usr/local/bin/composer mv composer.phar /usr/local/bin/composer
# Prestissimo: Install Prestissimo (A Composer parallel install plugin) ARG INSTALL_PRESTISSIMO=true
ARG INSTALL_PRESTISSIMO=false ENV INSTALL_PRESTISSIMO ${INSTALL_PRESTISSIMO}
RUN if [ "$INSTALL_PRESTISSIMO" = true ] ; then \ RUN if [ ${INSTALL_PRESTISSIMO} = true ]; then \
composer global require "hirak/prestissimo:^0.3"; \ # Prestissimo: Install Prestissimo (A Composer parallel install plugin)
fi composer global require "hirak/prestissimo:^0.3" \
;fi
# MongoDB: Install the mongodb extension ARG INSTALL_MONGO=true
RUN pecl install mongodb \ ENV INSTALL_MONGO ${INSTALL_MONGO}
&& echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini RUN if [ ${INSTALL_MONGO} = true ]; then \
# MongoDB: Install the mongodb extension
pecl install mongodb && \
echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini \
;fi
# XDebug: Load the xdebug extension only with phpunit commands ARG INSTALL_XDEBUG=true
RUN sed -i 's/^/;/g' /etc/php/7.0/cli/conf.d/20-xdebug.ini \ ENV INSTALL_XDEBUG ${INSTALL_XDEBUG}
&& echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/laravel/vendor/bin/phpunit'" >> ~/.bashrc RUN if [ ${INSTALL_XDEBUG} = true ]; then \
# XDebug: Load the xdebug extension only with phpunit commands
apt-get install -y --force-yes php7.0-xdebug && \
sed -i 's/^/;/g' /etc/php/7.0/cli/conf.d/20-xdebug.ini && \
echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/laravel/vendor/bin/phpunit'" >> ~/.bashrc \
;fi
# NVM: Install nvm (A Node Version Manager) ARG INSTALL_NODE=true
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash ENV INSTALL_NODE ${INSTALL_NODE}
ENV NVM_DIR=/root/.nvm RUN if [ ${INSTALL_NODE} = true ]; then \
# Node: Install nvm (A Node Version Manager) and use it to install NodeJS
# Node: Install node curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash \
RUN . ~/.nvm/nvm.sh \ ;fi
&& nvm install stable \ ENV if [ ${INSTALL_NODE} = true ]; then \
&& nvm use stable \ # I had to split this condifiton link this because when I get it inside the above if statment is refuses to work!
&& nvm alias stable \ NVM_DIR=/root/.nvm \
&& npm install -g gulp bower RUN . ~/.nvm/nvm.sh && \
nvm install stable && \
nvm use stable && \
nvm alias stable && \
npm install -g gulp bower \
;fi
# #
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
@ -105,7 +114,8 @@ RUN . ~/.nvm/nvm.sh \
RUN . ~/.bashrc RUN . ~/.bashrc
# Clean up # Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /var/www/laravel WORKDIR /var/www/laravel