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

Django & Continuous integration

Django & Continuous integration

Как быстро и просто внедрить проект на Django непрерывную интеграцию.

Moscow Python Meetup
PRO

July 09, 2012
Tweet

More Decks by Moscow Python Meetup

Other Decks in Technology

Transcript

  1. Continuous integration
    и Django
    Илья Барышев
    Moscow Django Meetup #4

    View Slide

  2. What is CI?
    A software development practice where
    members of a team integrate their work
    frequently, usually each person integrates at
    least daily - leading to multiple integrations
    per day. Each integration is verified by an
    automated build (including test) to detect
    integration errors as quickly as possible.
    Martin Fowler

    View Slide

  3. Зачем нужен CI
    • сокращается время интеграции
    • защита от регрессий
    • всегда работающая копия проекта
    • качественная оценка кода (lint)

    View Slide

  4. • Free, MIT Licence
    • java  -­‐jar  jenkins.war
    • WebGUI
    • Богатый функционал out of the box
    • Более 400 плагинов

    View Slide

  5. Jenkins dashboard
    http://ci.django-cms.org/

    View Slide

  6. django-jenkins
    • простая установка и настройка
    • тестируем только свои приложения
    • поддержка анализаторов кода:
    • coverage
    • pylint, pep8, pyflakes
    • csslint, jslint и др.

    View Slide

  7. Тестовый проект
    https://github.com/coagulant/jenkins_demo
    pip  install  django==1.4
    django-­‐admin.py  \
           startproject  jenkins_demo  .
    django-­‐admin.py  \
           startapp  meetup
    jenkins_demo/
           __init__.py
           settings.py
           urls.py
           wsgi.py
    meetup/
           __init__.py
           models.py
           tests.py
           views.py
    manage.py

    View Slide

  8. Тесты django
    $  python  manage.py  test
    Creating  test  database  for  alias  'default'...
    ....................................................................
    ....................................................................
    ....................................................................
    ....................................................................
    ....................................................................
    ...s................................................................
    ........
    -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐
    -­‐-­‐
    Ran  416  tests  in  16.872s
    OK  (skipped=1)
    Destroying  test  database  for  alias  'default'...

    View Slide

  9. Настраиваем django-jenkins
    pip  install  django-­‐jenkins  coverage  pylint
    INSTALLED_APPS  =  (
           ...
           'meetup',
           'django_jenkins',
           ...
    )
    PROJECT_APPS  =  (
           'meetup',
    )

    View Slide

  10. Тесты django-jenkins
    $  python  manage.py  jenkins
    Creating  test  database  for  alias  'default'...
    .
    -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐
    Ran  1  test  in  0.004s
    OK
    Destroying  test  database  for  alias  'default'...

    View Slide

  11. Ставим Jenkins и плагины
    Устанавливаем плагины
    Violations и Cobertura для Jenkins
    $  wget  http://mirrors.jenkins-­‐ci.org/war/latest/
    jenkins.war
    $  java  -­‐jar  jenkins.war

    View Slide

  12. Создание job
    Настраиваем сборку

    View Slide

  13. Запускаем тесты

    View Slide

  14. Запускаем тесты

    View Slide

  15. Послесборочные операции

    View Slide

  16. Так не бывает

    View Slide

  17. Так бывает
    Покрытие
    Количество тестов

    View Slide

  18. Shining Panda plug-in
    • поддержка python, virtualenv, buildout, tox
    при настройке заданий

    View Slide

  19. Shining Panda plug-in
    • ось Python для многомерных
    конфигураций

    View Slide

  20. Shining Panda
    • Jenkins SaaS
    • Python, Java
    • Linux, Windows
    • MySQL, PostgreSQL, MongoDB
    • 12$ в месяц (48c в час)
    • https://www.shiningpanda.com/

    View Slide

  21. Travis CI
    • CI SaaS
    • Free for opensource
    • Python, Javascript, Ruby, etc (11 языков)
    • Интеграция с гитхабом
    • Тестирование pull-реквестов (beta)
    • http://travis-ci.org/

    View Slide

  22. Travis dashboard

    View Slide

  23. language:  python
    python:
       -­‐  2.6
       -­‐  2.7
    env:
       -­‐  DJANGO_VERSION=1.3.1
       -­‐  DJANGO_VERSION=1.4
    install:
       -­‐  pip  install  -­‐q  Django==$DJANGO_VERSION  
       -­‐  pip  install  reqs.txt  -­‐-­‐use-­‐mirrors
       -­‐  python  setup.py  -­‐q  install
    script:  python  runtests.py
    branches:
       only:
           -­‐  dev
    Пример .travis.yml

    View Slide

  24. Полезные ссылочки
    • http://martinfowler.com/articles/continuousIntegration.html
    • http://jenkins-ci.org/
    • https://github.com/kmmbvnr/django-jenkins
    • https://github.com/coagulant/jenkins_demo
    • https://www.shiningpanda.com/
    • http://travis-ci.org/

    View Slide

  25. Спасибо
    [email protected]
    @coagulant http://blog.futurecolors.ru/

    View Slide