My Own CI Within Docker

David Flores

Co-Mantainer at @DrupalConsole, Linux, Drupal, Symfony, Silex, Docker, Security, Python, Open Source, Father ...sometimes #Nerd Speaker

david@indava.com

@dmouse

Open Source

http://drupalconsole.com

PHP Mexico | The Right Way

http://www.meetup.com/es-ES/PHP-The-Right-Way/

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

/me with Docker 0.6.5

Linux User

Sorry Mac User

 

Docker Compose

Compose

 

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

 

Docker Cli

1

$ 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

Strider CD

Drone IO

Drone IO

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:8.9.5
  links:
    - redis:redisio
    - postgresql:postgresql
    - drone:drone.dev
  ports:
    - "10080:80"
    - "10443:443"
    - "2222:22"
  environment:
    - TZ=America/Mexico_City
    - GITLAB_TIMEZONE=Kolkata

    - 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/

 

Drone IO

 
drone:
  image: drone/drone:0.4.2
  ports:
    - "10081:8000"
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /home/gitlab/drone:/var/lib/drone
  environment:
    REMOTE_DRIVER: gitlab
    REMOTE_CONFIG: https://www.domain.com?client_id=XYZ&client_secret=ABC&open=true

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

 

Do it.

http://readme.drone.io/usage/overview/

.drone.yml

build:
  image: indava/drupal
  commands:
    - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    - php -r "if (hash_file('SHA384', 'composer-setup.php') === '...') {  } else { unlink('composer-setup.php'); } echo PHP_EOL;"
    - php composer-setup.php
    - php -r "unlink('composer-setup.php');"
    - php composer.phar install
    - php vendor/bin/codecept run 

.drone.yml

 

deploy:
  ssh:
    host: chevecha.com
    user: ci
    port: 22
    commands:
      - cd /apps/indava && git pull origin master
      - docker-compose build
      - docker-compose up -d
      - docker exec indava-test composer install --no-dev --prefer-dist
      - docker exec -i indava-test ./vendor/bin/drupal --root=/var/www/html/web config:import
cache:
  mount:
    - .git

Containers to test container to publish containers 

.drone.yml

 
build:
  image: php:5.6-apache
  commands:
    - echo "helloooou"

deploy:
  ssh:
    host: chevecha.com
    user: ci
    port: 22
    commands:
      - cd /apps/drupal-docker && git pull origin master
      - docker build -t indava/drupal .
      - docker push indava/drupal

Questions

My Own CI with Docker

By David Flores

My Own CI with Docker

  • 1,580