Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Once source code has been checked out from repository, following commands should be run from project root folder's context.

 

 

 

Table of Contents

Docker Installation (Official guide here)

Following steps are performed to get Docker up and running:

  1. Create docker user group in your system and add your user to that group.
     
  2. Adjust memory and swap accounting by editing the value GRUB_CMDLINE_LINUX in /etc/default/grub like:

    Code Block
    languagebash
    GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

    and update grub afterwards:

    Code Block
    languagebash
    sudo update-grub
  3. Reboot your system.
     
  4. Install Docker with command:

    Code Block
    languagebash
    wget -qO- https://get.docker.com/ | sh
  5. Install Docker-Compose with command:

    Code Block
    curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` > docker-compose;
    chmod +x docker-compose;
    sudo mv docker-compose /usr/local/bin/;

Building Containers

Project source code contains DockerFIles with build and run instructions, located at storage/build/scripts folder. We build following containers to develop and test against:

  1. Nginx container (for end-to-end UI testing and development) -  can be built with following command (please note the dot . at the end of the command):

    Code Block
    languagebash
    docker build -f storage/build/scripts/nginx.Dockerfile -t audithsoftworks/basis:nginx .

    Or you can just pull it with docker-compose pull ... command (see below).

     

  2. HHVM, PHP 5.5 and 5.6 containers (for unit-testing and development) - can be built with following command (please note the dot . at the end of the command):

    Code Block
    languagebash
    docker build -f storage/build/scripts/php_5.5.Dockerfile -t audithsoftworks/basis:php_5.5 .;
    docker build -f storage/build/scripts/php_5.6.Dockerfile -t audithsoftworks/basis:php_5.6 .;
    docker build -f storage/build/scripts/hhvm.Dockerfile -t audithsoftworks/basis:hhvm .;

    Or you can wait with pull and do that altogether with docker-compose pull ... command (see below).
     

  3. PHP-FPM 5.5 and 5.6 containers (for E2E UI-testing and development) - again, these images can be built locally (please note the dot . at the end of the command):

    Code Block
    languagebash
    docker build -f storage/build/scripts/php_5.5-fpm.Dockerfile -t audithsoftworks/basis:php_5.5-fpm .;
    docker build -f storage/build/scripts/php_5.6-fpm.Dockerfile -t audithsoftworks/basis:php_5.6-fpm .;

    Or you can wait with pull and do that altogether with docker-compose pull ... command (see below).

Running Containers

All required images can be pulled with following command (from the context of project folder, so that it could detect docker-compose.yml file):

Code Block
languagebash
docker-compose pull

At this point, we are ready to spin up our infrastructure:

Code Block
languagebash
docker-compose up -d && docker-compose ps

This will create and run all required containers. Once containers are up and running, we need to make tiny preparations in them to run our application:

  1. Postgres related tasks - we need to create our database:

    Code Block
    languagebash
    psql -h $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_postgres92_1) -U postgres -c "CREATE DATABASE basis;";
    psql -h $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_postgres93_1) -U postgres -c "CREATE DATABASE basis;";
    psql -h $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_postgres94_1) -U postgres -c "CREATE DATABASE basis;";
  2. Editing hosts file - we need to tell our PHP containers where to look for their appropriate Nginx instances:

    Code Block
    languagebash
    docker-compose run php55 /bin/sh -c "echo $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_nginxForPhpFpm55_1) basis.audith.org | tee -a /etc/hosts";
    docker-compose run php56 /bin/sh -c "echo $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_nginxForPhpFpm56_1) basis.audith.org | tee -a /etc/hosts";
    docker-compose run hhvmAsCli /bin/sh -c "echo $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' basis_nginxForHhvm_1) basis.audith.org | tee -a /etc/hosts";

That's it. Now it is time we built our project assets.

Build Project Assets

By running:

Code Block
languagebash
export PHP_CONTAINER=php55

or

Code Block
languagebash
export PHP_CONTAINER=php56

or 

Code Block
languagebash
export PHP_CONTAINER=hhvmAsCli

we can choose the environment we want to use. This will put a temporary (for the duration of terminal session) environmental variable called $PHP_CONTAINER.

Once the working PHP environment is chosen, we can go ahead and build the assets:

Code Block
languagebash
# npm update & bower update
docker-compose run $PHP_CONTAINER /bin/sh -c 'npm update && bower --config.interactive=false --allow-root update';
 
# Pull and build Woff2
docker-compose run $PHP_CONTAINER /bin/sh -c 'git clone --depth=1 https://github.com/google/woff2.git /home/basis/storage/build/tools/woff2';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis/storage/build/tools/woff2 && git submodule init && git submodule update && make clean all';
 
# Pull CSS3-Font-Converter
docker-compose run $PHP_CONTAINER /bin/sh -c 'git clone --depth=1 https://github.com/zoltan-dulac/css3FontConverter.git /home/basis/storage/build/tools/css3_font_converter';
 
# Copy required fonts to /public directory of the project
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/bootstrap/fonts /home/basis/public/fonts/glyphicons';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/fontawesome/fonts  /home/basis/public/fonts/font_awesome';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/ofl/armata /home/basis/public/fonts/armata';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/ofl/ptsans /home/basis/public/fonts/pt_sans';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/ofl/marcellus /home/basis/public/fonts/marcellus';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/ofl/pontanosans /home/basis/public/fonts/pontano_sans';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/ofl/montserrat /home/basis/public/fonts/montserrat';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cp -r /home/basis/public/bower_components/google-fonts/apache/opensans /home/basis/public/fonts/opensans';
 
# Update $PATH and make build tools executable
docker-compose run $PHP_CONTAINER /bin/sh -c 'export PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 && chmod -R +x /home/basis/storage/build/tools';


# Convert fonts
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/montserrat/stylesheet.css public/fonts/montserrat/*.ttf';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/pt_sans/stylesheet.css public/fonts/pt_sans/*.ttf';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/pontano_sans/stylesheet.css public/fonts/pontano_sans/*.ttf';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/armata/stylesheet.css public/fonts/armata/*.ttf';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/marcellus/stylesheet.css public/fonts/marcellus/*.ttf';
docker-compose run $PHP_CONTAINER /bin/sh -c 'cd /home/basis && PATH=$PATH:/home/basis/storage/build/tools/sfnt2woff:/home/basis/storage/build/tools/woff2 ./storage/build/tools/css3_font_converter/convertFonts.sh --use-font-weight --output=public/fonts/opensans/stylesheet.css public/fonts/opensans/*.ttf';

# Compile SCSS assets
docker-compose run $PHP_CONTAINER /bin/sh -c 'compass compile';
 
# Gulp it
docker-compose run $PHP_CONTAINER /bin/sh -c 'gulp';
 
# Create initial .env file to work with MySQL 5.5
cat .env.example | sed s/DB_HOST=.*/DB_HOST=mysql55/g | sed s/DB_USERNAME=.*/DB=mysql/g | sed s/DB_PASSWORD=.*//g | tee .env;
 
# Composer-update
docker-compose run $PHP_CONTAINER /bin/sh -c 'composer update --no-interaction';

Running Unit-tests

Once the project dependencies and assets have been pulled and built, we can start running unit-tests to make sure everything is in working order:

Code Block
languagebash
# Run tests for MySQL 5.5 - it was set above
docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';
 
# Switch to MySQL 5.6 and run tests
cat .env | sed s/DB_HOST=.*/DB_HOST=mysql56/g | sed s/DB=.*/DB=mysql/g | tee .env; docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';
 
# Switch to MySQL 5.7 and run tests
cat .env | sed s/DB_HOST=.*/DB_HOST=mysql57/g | sed s/DB=.*/DB=mysql/g | tee .env; docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';
 
# Switch to PgSQL 9.2 and run tests
cat .env | sed s/DB_HOST=.*/DB_HOST=postgres92/g | sed s/DB=.*/DB=pgsql/g | tee .env; docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';
 
# Switch to PgSQL 9.3 and run tests
cat .env | sed s/DB_HOST=.*/DB_HOST=postgres93/g | sed s/DB=.*/DB=pgsql/g | tee .env; docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';
 
# Switch to PgSQL 9.4 and run tests
cat .env | sed s/DB_HOST=.*/DB_HOST=postgres94/g | sed s/DB=.*/DB=pgsql/g | tee .env; docker-compose run $PHP_CONTAINER /bin/sh -c './vendor/bin/phpunit --debug --verbose';

That's it.