CI and Docker

David Flores

Software developer | CTO at indava.com | @phpmx User Group Leader
#PHP #Linux #Docker #Symfony #Drupal #InfoSec #Security #Golang

david@indava.com

@dmouse

David Flores

Started @drupalconsole with great friends #Linux #Docker #Symfony #Drupal #Python #GoLang, Techlead @indavaIT. Sometimes ... nerd speaker.

david@indava.com

@dmouse

Open Source

https://github.com/dmouse

Community

https://phpmexico.mx

http://bit.ly/docker-php-ci

/me with Docker 0.6.5

Linux User

Sorry Mac/Win Users

Docker

Docker

Is not a virtualization tool

Docker

Is not comparable with Vagrant

Containers

Are not virtual machines

Container Process

Host Process

Container Versioning

  • Commit
  • Pull
  • Push
  • Tags

Docker Compose

Compose

Is a tool for defining and running multi-container Docker applications.

https://docs.docker.com/compose/

Docker Cli


$ docker run --name app-redis -d redis 

$ docker run --name app-php -d --link app-redis:redis php:7-fpm

$ docker run --name app-nginx -d -p 8080:80 \
    -v app:/var/www/html --link app-php:php \
    -e "NGINX_HOST=foobar.com" -e "NGINX_PORT=80" nginx 

Docker Compose

app-redis:
    image: redis

app-php:
    image: php:7-fpm
    links:
      - app-redis:redis

app-nginx:
    image: nginx
    links:
       - app-php:php
    volumes:
       - app:/var/www/html
    environment:
       - NGINX_HOST=foobar.com
       - NGINX_PORT=80
    ports:
       - "8080:80"

Docker Compose


$ docker-compose up -d
 ~/p/w/indava.dev docker-compose up -d                                                           
Starting indavadev_indavaComDB_1
Starting indava-dev

CI

CI Software

https://en.wikipedia.org/wiki/Comparison_of_continuous_integration_software

Travis CI

Drone IO

Drone IO

Infrastructure

PostgreSql

postgresql:
  image: sameersbn/postgresql:9.4-3
  environment:
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production
  volumes:
    - /home/docker/gitlab/postgresql:/var/lib/postgresql

https://github.com/indava/gitlab/

Redis

redis:
  image: sameersbn/redis:latest
  volumes:
    - /home/gitlab/redis:/var/lib/redis

https://github.com/indava/gitlab/

Gitlab

gitlab:
  image: sameersbn/gitlab:12.9.2
  links:
    - redis:redisio
    - postgresql:postgresql
  ports:
    - "10080:80"
    - "10443:443"
    - "2222:22"
  environment:
    - TZ=America/Mexico_City

    - GITLAB_SECRETS_DB_KEY_BASE=4BA

    - GITLAB_HOST=domain.com
    - GITLAB_PORT=443
    - GITLAB_SSH_PORT=2222
    - GITLAB_HTTPS=true

https://github.com/indava/gitlab/

Runners

runner:
  image: gitlab/gitlab-runner:alpine
  volumes:
    - ./runner:/etc/gitlab-runner
    - /var/run/docker.sock:/var/run/docker.sock
  restart: always

https://github.com/indava/gitlab/

Usage

 .gitlab-ci.yml

image: "indava/php:7.3"

stages:
  - build
  - test
  - deploy
  
services:
  - mysql:latest
  
variables:
  DATABASE_URL: "mysql://root:toor@127.0.0.1:3306/ci"
  MYSQL_DATABASE: "ci"
  MYSQL_ROOT_PASSWORD: "toor"

build:
  stage: build
  script:
    - composer install

 .gitlab-ci.yml

phpcs:
  stage: test
  script:
    -  ./bin/phpunit

jslint:
  stage: test
  script:
    - eslint .
    
phpunit:
  stage: test
  script:
    - php bin/phpunit

Questions

http://bit.ly/docker-php-ci

Happy Hacking

Made with Slides.com