Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Continuous integration with gitlab and docker

Continuous integration with gitlab and docker

Slides for a presentation I gave at VlbgWebDev 10/2016.
To reduce risks on conference wifi i've embedded videos.
Sorry but these are not visible on speaker deck.

Daniel Widerin

October 11, 2016
Tweet

Other Decks in Programming

Transcript

  1. CONTINUOUS INTEGRATION
    WITH GITLAB AND DOCKER
    VLBG WEBDEV 10/16

    View Slide

  2. DANIEL WIDERIN
    HEAD OF 

    DEVELOPMENT AND TEST
    CORPORATE IT

    ZUMTOBEL GROUP AG

    View Slide

  3. WHAT IS

    CONTINUOUS INTEGRATION?
    The Management
    CI/CD WITH GITLAB AND DOCKER

    View Slide

  4. CI/CD WITH GITLAB AND DOCKER
    CONTINUOUS INTEGRATION REQUIREMENTS AND BEST PRACTICES
    ▸ Use a code repository / version control system
    ▸ Use a branching model
    ▸ Commit early - commit often
    ▸ Automate the build, tests and deployments
    ▸ Use an integration machine
    ▸ Use continuous feedback mechanisms

    View Slide

  5. CI/CD WITH GITLAB AND DOCKER
    GITLAB
    ▸ GitLab started as on-premise
    GitHub
    ▸ Full featured webgui for git version
    control system
    ▸ Integrated very powerful CI
    environment
    ▸ Workflows / Permissions supported 

    out-of-the-box
    ▸ http://about.gitlab.com

    View Slide

  6. CI/CD WITH GITLAB AND DOCKER
    DOCKER
    ▸ Allows you to package your
    application into a standardized unit
    for software development
    ▸ Often called "lightweight"
    virtualization approach.
    ▸ very fast growing and wide
    spreaded in open source community
    ▸ insanely great!
    ▸ http://docker.io

    View Slide

  7. CI/CD WITH GITLAB AND DOCKER
    ARCHITECTURE
    ▸ GitLab server owns code and acts
    as coordinator
    ▸ GitLab CI runners connect to the
    coordinator using a REST api
    ▸ Redis job queue consumed by
    runners, execute it and upload
    artifacts back to coordinator.
    ▸ The more (powerful) runners you
    connect, the more builds you can
    run in parallel

    View Slide

  8. CI/CD WITH GITLAB AND DOCKER
    EXECUTORS
    ▸ GitLab runners have multiple executors:
    ▸ shell run build locally
    ▸ docker run build using Docker container
    ▸ ssh run build remotely with SSH
    ▸ parallels run build using Parallels VM
    ▸ virtualbox run build using VirtualBox VM
    ▸ docker+machine like docker, but uses auto-scaled docker machines
    ▸ kubernetes (experimental)

    View Slide

  9. SETUP

    View Slide

  10. CI/CD WITH GITLAB AND DOCKER
    SETUP YOUR CI-PIPELINE
    ▸ Code hosted on gitlab.com or your on-premise gitlab installation
    ▸ add a .gitlab-ci.yml file

    View Slide

  11. View Slide

  12. CI/CD WITH GITLAB AND DOCKER
    SETUP YOUR CI-PIPELINE
    ▸ Code hosted on gitlab.com or your on-premise gitlab installation
    ▸ add a .gitlab-ci.yml file
    ▸ connect a gitlab ci runner - use following command to install on macOS with homebrew:

    brew install gitlab-ci-multi-runner 

    --without-docker

    gitlab-runner register 

    --url https://gitlab.com 

    --token

    View Slide

  13. CI/CD WITH GITLAB AND DOCKER
    SETUP YOUR CI-PIPELINE
    ▸ Code hosted on gitlab.com or your on-premise gitlab installation
    ▸ add a .gitlab-ci.yml file
    ▸ connect a gitlab ci runner - use following command to install on macOS with homebrew:

    brew install gitlab-ci-multi-runner 

    --without-docker

    gitlab-runner register 

    --url https://gitlab.com 

    --token
    ▸ start the runner gitlab-runner

    gitlab-runner install

    gitlab-runner start

    View Slide

  14. View Slide

  15. CI/CD WITH GITLAB AND DOCKER
    SETUP YOUR CI-PIPELINE
    ▸ Code hosted on gitlab.com or your on-premise gitlab installation
    ▸ add a .gitlab-ci.yml file
    ▸ connect a gitlab ci runner - use following command to install on macOS with homebrew:

    brew install gitlab-ci-multi-runner 

    --without-docker

    gitlab-runner register 

    --url https://gitlab.com 

    --token
    ▸ start the runner gitlab-runner

    gitlab-runner install

    gitlab-runner start
    ▸ commit and push to remote to trigger ci pipeline.

    View Slide

  16. PYRAMID DEMO

    View Slide

  17. CI/CD WITH GITLAB AND DOCKER
    PYRAMID TUTORIAL APP
    ▸ Found in https://gitlab.com/widerin/vlbg-webdev-1016/
    tree/pyramid
    ▸ Just output the foo in route http://localhost:8080/hello/foo
    ▸ pytest covered
    ▸ build and tested on gitlab in docker

    View Slide

  18. View Slide

  19. View Slide

  20. FULLY DOCKERIZED
    APPLICATIONS
    CONNECT SERVICES IN TEST PIPELINE

    View Slide

  21. CI/CD WITH GITLAB AND DOCKER
    HOW TO CONNECT SERVICES?
    ▸ your application requires a
    database like postgresql
    ▸ your application requires a
    message queue like redis or
    rabbitmq
    ▸ your application requires a index
    engine like solr or elasticsearch
    ▸ very time consuming test setup
    in default ci-scenarios
    APPLICATION
    DATABASE
    INDEX

    View Slide

  22. FLASK DEMO

    View Slide

  23. CI/CD WITH GITLAB AND DOCKER
    FLASK TUTORIAL PING APP V1
    ▸ Found in https://gitlab.com/widerin/vlbg-webdev-1016/
    tree/master/example-1
    ▸ Ping application responses with "pong!"

    http://localhost:5000/ping
    ▸ pytest covered
    ▸ build and tested on gitlab in docker

    View Slide

  24. View Slide

  25. CI/CD WITH GITLAB AND DOCKER
    FLASK TUTORIAL PING APP V2
    ▸ Found in https://gitlab.com/widerin/vlbg-webdev-1016/
    tree/master/example-2
    ▸ Ping application responses with "pong!" and outputs the
    number of pings you sent to it.

    http://localhost:5000/ping
    ▸ redis as persistence layer
    ▸ pytest covered
    ▸ build and tested on gitlab in docker

    View Slide

  26. View Slide

  27. View Slide

  28. CI/CD WITH GITLAB AND DOCKER
    NATIVE BUILDS IN DOCKER
    ▸ Use your favourite linux docker image
    ▸ build within the image
    ▸ compile your application for your production servers in
    same linux distribution
    ▸ use caches for node_modules/, .m2/repository, ...
    ▸ you can build your own docker base and/or test images

    View Slide

  29. View Slide

  30. QUESTIONS?
    TOPICS FOR NEXT SESSIONS?
    CI/CD WITH GITLAB AND DOCKER

    View Slide

  31. THANK YOU
    all examples can be found here:

    https://gitlab.com/widerin/vlbg-webdev-1016
    http://widerin.net

    View Slide