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

Symfony live Paris 2017 :

Symfony live Paris 2017 :

SensioCloud, Heroku, OpenShift... Aujourd'hui les solutions PaaS se démocratisent. Permettant de déployer une application et tous ses services dans des conteneurs, elles promettent de simplifier la vie des développeurs en gérant l'infrastructure avec le code. Mais, au moment de l'utiliser pour l'une de nos applications, de nombreuses problématiques dont certaines propres à Symfony se sont posées : déploiement continu, 0-downtime, gestion du cache / des mots de passe / de la performance, adaptation journalière aux pics de trafic, etc. Voici comment nous les avons résolues une à une, ce qui a réussi, ce qui a échoué et ce qu'il reste à faire.

Joind.in: https://joind.in/event/symfonylive-paris-2017/dployer-une-app-symfony-dans-un-paas

Links:
- https://pecl.php.net/package/APCu
- http://blog.insight.sensiolabs.com/2014/12/22/making-symfony-bootable-with-dbal-2-5.html
- https://12factor.net/

http://paris2017.live.symfony.com/

Tristan Darricau

March 31, 2017
Tweet

Other Decks in Programming

Transcript

  1. Deploying Symfony
    on PaaS

    View full-size slide

  2. Who am I?
    Tristan Darricau
    Developer at SensioLabs
    phpBB core contributor
    @nicofuma
    Twitter / Github / Gitlab / ...

    View full-size slide

  3. Platform as a Service

    View full-size slide

  4. Secrets
    (passwords)

    View full-size slide

  5. Back to the sources
    IaaS / CaaS / PaaS / SaaS

    View full-size slide

  6. IaaS
    Infrastructure as a Service
    Provides naked virtual machines and ntworking

    View full-size slide

  7. CaaS
    Container as a Service
    Boots containers and connects them
    (swarm)

    View full-size slide

  8. PaaS
    Platform as a Service
    Provides networked services
    (including your application)

    View full-size slide

  9. SaaS
    Software as a Service

    View full-size slide

  10. PaaS promises

    View full-size slide

  11. Infrastructure as code

    View full-size slide

  12. From Development to Production
    PAAS
    DEV
    PROD
    QA ...
    PPRD

    View full-size slide

  13. Let's deploy

    View full-size slide

  14. ftp / rsync
    ansible / chef / ...

    View full-size slide

  15. Git Push
    $ git push staging master
    $ git push production master

    View full-size slide

  16. Build step
    Every application has to be built
    buildpack, build script, assemble script...
    every provider has its own receipe

    View full-size slide

  17. Describe infrastructure
    infrastructure:
    db-1:
    kind: 'database'
    version: 'mysql:10.0'
    disk: '10Go'
    app:
    kind: 'php'
    version: '7.1'
    extensions:
    - 'apcu'
    - 'pdo-mysql'
    scripts:
    - 'composer install'

    View full-size slide

  18. Building Symfony
    composer
    container
    router
    translations
    annotations
    templates
    assets
    ....

    View full-size slide

  19. Tips: composer
    composer install --no-interaction --prefer-dist \
    --no-dev --optimize-autoloader --apcu-autoloader

    View full-size slide

  20. Local, shared, in-memory cache
    Free performance boost
    https://pecl.php.net/package/APCu
    Tips: APCU

    View full-size slide

  21. But... passwords?

    View full-size slide

  22. Passwords hardcoded
    parameters:
    ...
    database_user: "my_user"
    database_password: "my_password"
    ...
    Who wants to commit passwords ?

    View full-size slide

  23. Use "secret" parameters.yml file
    Still not ideal...
    Inject / build parameters.yml on runtime
    Not always possible

    View full-size slide

  24. Environment variables
    parameters:
    ...
    env(DATABASE_USER): "default_username"
    env(DATABASE_PASSWORD): "default_password"
    ...
    doctrine:
    ...
    user: "%env(DATABASE_USER)%"
    password: "%env(DATABASE_PASSWORD)%"
    ...

    View full-size slide

  25. Environment variables
    Since Symfony 3.2 only
    Available only on runtime
    Read only when needed
    Never cached

    View full-size slide

  26. Symfony needs cache

    View full-size slide

  27. Cache warmers
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ TemplatePathsCacheWarmer
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ ValidatorCacheWarmer
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ TranslationsCacheWarmer
    Symfony\Bridge\ Doctrine\CacheWarmer\ ProxyCacheWarmer
    Symfony\Bundle\TwigBundle\CacheWarmer\ TemplateCacheWarmer
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ AnnotationsCacheWarmer
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ RouterCacheWarmer
    Symfony\Bundle\FrameworkBundle\CacheWarmer\ ClassCacheCacheWarmer
    FOS\RestBundle\Response\AllowedMethodsLoader\AllowedMethodsRouterLoad
    er
    ...

    View full-size slide

  28. Build on runtime?
    It may work but not ideal...
    Slow down first request
    May be blocked

    View full-size slide

  29. Generate on build
    Improved in Symfony 3.2
    Statically generated
    Read only filesystem compliant
    Requires all parameters? (passwords)

    View full-size slide

  30. Generate on build
    bin/console cache:clear --env=prod
    bin/console cache:warmup --env=prod

    View full-size slide

  31. Tips: doctrine
    Doctrine cache warmer needs the DB version
    http://blog.insight.sensiolabs.com/2014/12/22/making-
    symfony-bootable-with-dbal-2-5.html

    View full-size slide

  32. Going further on cache
    PHP compilation takes time?
    Do it at build
    PHP7 only
    opcache.enable=1
    opcache.enable_cli=1
    opcache.file_cache="/my/cache/dir"

    View full-size slide

  33. It was working

    View full-size slide

  34. Update your database?
    When? How?

    View full-size slide

  35. Doctrine dependency hell

    View full-size slide

  36. How to do?
    Complex situation, no magic solution
    External tool
    3 steps deployment
    Downtime
    Forward compatibility
    ...

    View full-size slide

  37. What have we done?

    View full-size slide

  38. 12 factors
    https://12factor.net/

    View full-size slide

  39. Going further

    View full-size slide

  40. Routing
    Handled by all providers
    DNS names
    SSL termination
    ...

    View full-size slide

  41. Multi applications
    Handled by all providers
    app/
    front/
    .my_paas/
    conf.yml
    packages.json
    back/
    .my_paas/
    conf.yml
    composer.json

    View full-size slide

  42. Review app
    Deploy a new env for each PR

    View full-size slide

  43. Why?
    Security
    Scaling

    View full-size slide

  44. Sessions
    # app/config/config.yml
    snc_redis:
    clients:
    default:
    type: predis
    alias: default
    dsn: redis://localhost
    session:
    client: default
    prefix: session
    # app/AppKernel.php
    $bundles = array(
    // ...
    new Snc\RedisBundle\SncRedisBundle(),
    // ...
    );
    composer require snc/redis-bundle \
    predis/predis

    View full-size slide

  45. Merci !
    #Symfony_Live
    @nicofuma
    Twitter / Github / Gitlab / ...
    https://joind.in/talk/bf1de

    View full-size slide