Symfony 2 under control

68
Continuous Integration and Automated Deployments for Symfony-based projects Symfony 2 under control

description

Symfony Camp 2013 UA. Continuous Integration and Automated Deployments for Symfony-based projects P.S. Original PPTX presentation contains a lot of notes

Transcript of Symfony 2 under control

Page 1: Symfony 2 under control

Continuous Integration and Automated Deployments for Symfony-based projects

Symfony 2 under control

Page 3: Symfony 2 under control

3

INTRODUCTION

Page 4: Symfony 2 under control

4

Batteries ARE Included

Page 5: Symfony 2 under control

5

For standard projects Phing

Jenkins CI Capifony

Quick facts

Page 6: Symfony 2 under control

6

Open Source

Bundle

Quick facts

Page 7: Symfony 2 under control

7

What is Continuous Integration?

Page 8: Symfony 2 under control

8

Improve quality

Understand current

situation

Automate checklists

Notify colleagues

How could it help you?

Page 9: Symfony 2 under control

9

composer require "epam/ci-

bundle=1.0.*"

//update AppKernel

app/console epam-ci:init

"Acme Demo Project"

How to use?

Page 10: Symfony 2 under control

10

•Tweak configuration•Install tools on envs•…•Profit!

How to use?

Page 11: Symfony 2 under control

11

BUILD

Page 12: Symfony 2 under control

12

Mmm… Build!

Page 13: Symfony 2 under control

13

Ant Phing

Pake

Build tools

Page 14: Symfony 2 under control

14

Target

•Set of tasks

Task

•Action

Types

•Data types

Phing Terminology

Page 15: Symfony 2 under control

15

build-epam-ci.xml

• Default workflow

build.xml

• Overwrites

Phing build files

Page 16: Symfony 2 under control

16

build.properties.dist

• Project config

build.properties

• Environment config

Phing config files

Page 17: Symfony 2 under control

17

build

•dev env•console

build-ci

•CI env•XML

Main Phing Targets

Page 18: Symfony 2 under control

18

package

• tar.gz package• DDL dump

deploy

• packageenv

Main Phing Targets

Page 19: Symfony 2 under control

19

phing -lAll Phing targets?

Page 20: Symfony 2 under control

20

Phing. Want more?

Page 21: Symfony 2 under control

21

clean

prepare

build-tools-self-update

Phing Targets. Special

Page 22: Symfony 2 under control

22

validate

install

list-updates

security-checker

Phing Targets. Composer

Page 23: Symfony 2 under control

23

phplint pdepend

phpmd

Phing Targets. Static analysis

Page 24: Symfony 2 under control

24

apidoc phpcs

php-cs-fixer

Phing Target. General

Page 25: Symfony 2 under control

25

phpunit

phplocphpcpd

Phing Targets. General, by Sebastian Bergmann

Page 26: Symfony 2 under control

26

Regular build workflow

DB tasks

twig:lint

Phing Targets. Symfony-specific

Page 27: Symfony 2 under control

27

Package

Deployment

Phing Targets. Deployment

Page 28: Symfony 2 under control

28

CONTINUOUS INTEGRATION

Page 29: Symfony 2 under control

29

CI servers

Page 30: Symfony 2 under control

30

Open-source

Enterprise

Jenkins CI overview

Page 31: Symfony 2 under control

31

Tons of plugins

PHP Template by Sebastian Bergmann

Jenkins CI overview

Page 32: Symfony 2 under control

32

IDE Integration

RESTful API

Jenkins CI overview

Page 33: Symfony 2 under control

33

Jenkins CI RESTful API

http://habrahabr.ru/post/169097/

Page 34: Symfony 2 under control

34

git greenballs

parameterized-trigger

copyartifact

email-ext

Jenkins Plugins (common)

Page 35: Symfony 2 under control

35

phing checkstyle dry

jdepend plot pmd

violations xunit htmlpublisher

Jenkins Plugins (PHP-specific)

Page 36: Symfony 2 under control

36

build-<branchname>

build-package-tag

Jenkins Jobs for build

Page 37: Symfony 2 under control

37

deploy-qa-<branchname>

deploy-package-tag

Jenkins Jobs for deployment

Page 38: Symfony 2 under control

38

Deployed .tar.gz archive Previous deployed version

DB dump before deployment

Doctrine Migrations info DB schema

Jenkins Jobs for deployment. Artifacts

Icons by http://dryicons.com

Page 39: Symfony 2 under control

39

DEPLOYMENT

Page 40: Symfony 2 under control

40

Deployment strategy

Page 41: Symfony 2 under control

41

Custom Zend Server package

PaaS

Deployment tools

Page 42: Symfony 2 under control

42

Phar Capistrano

Capifony

Deployment tools

Page 43: Symfony 2 under control

43

Based on Capistrano

Symfony 1 & 2

Capifony

Page 44: Symfony 2 under control

44

Multistage

Maintenance mode

Clustered environments

Capifony

Page 45: Symfony 2 under control

45

Directory structure

Page 46: Symfony 2 under control

46

releases/

current/ (symlink)

shared/

Directory structure

Page 47: Symfony 2 under control

47

app/config/parameters.yml

app/logs

web/uploads

Directory structure / Shared

Page 48: Symfony 2 under control

48

ln -s

not shared across nodes

Directory structure / Shared

Page 49: Symfony 2 under control

49

`-- /var/www/my-app.com|-- current → /var/www/my-app.com/releases/20100512131539|-- releases| `-- 20100512131539| `-- 20100509150741| `-- 20100509145325`-- shared |-- web | `-- uploads |-- logs `-- config `-- parameters.yml

Directory structure example

from http://capifony.org/#4_setup_server

Page 50: Symfony 2 under control

50

All you need is package

capistrano-deploy-strategy-archive

Deployment via SCM vs package

Page 51: Symfony 2 under control

51

Deployment via SCM vs package: Github not available? Goodbye, vendors!

Page 52: Symfony 2 under control

52

Decreases deployment time

Increases build time

Deployment via SCM vs package

Page 53: Symfony 2 under control

53

Reproducible

Quick fixes not available

Deployment via SCM vs package

Page 54: Symfony 2 under control

54

.tar.gz

Optimized autoloader

only necessary dirs & files

Package contents

Page 55: Symfony 2 under control

55

assets:install

assetic:dump

version.txt & db-schema.sql

Package contents

Page 56: Symfony 2 under control

56

DBDeploy Liquibase

Doctrine Migrations

Doctrine Fixtures

Database Migrations

Page 57: Symfony 2 under control

57

Deployment: Maintenance mode

Page 58: Symfony 2 under control

58

User Jenkins Phing Capifony

Capifony & Jenkins CI

Page 59: Symfony 2 under control

59

Maintenance mode on

Backup DB

Clear Doctrine cache

Download previous build metadata

Capifony & Phing. Deployment preparations

Page 60: Symfony 2 under control

60

Deploy tar.gz package

Restart services

Symfony-specific tasks

Capifony & Phing. Deployment

Page 61: Symfony 2 under control

61

Maintenance mode off

Housekeeping

Capifony & Phing. Post-deployment steps

Page 62: Symfony 2 under control

62

Broken build???

Page 63: Symfony 2 under control

63

Enable Maintenance

Manually backup for analysis

Rollback is semi-automatic

Page 64: Symfony 2 under control

64

Switch to previous release

Additional tasks

Disable Maintenance

Rollback

Page 65: Symfony 2 under control

65

Write rollback guide

Enable monitoring on prod

Rollback tips

Page 66: Symfony 2 under control

66

P.S.

Page 67: Symfony 2 under control

67

Build

• Static analysis via HHVM• Actually was implemented, but hphpa changed a lot (now it’s

https://github.com/sebastianbergmann/hhvm-wrapper)

Deployment

• Cronjob / CLI script handling• Web server (Apache, nginx) config manipulations• Ext- and lib- dependency verification via Composer• Custom script execution during deployment

What is not implemented yet

Page 68: Symfony 2 under control

Questions?