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/

6d213150fb8a02cc361b7e045b7dac5b?s=128

Tristan Darricau

March 31, 2017
Tweet

Transcript

  1. Deploying Symfony on PaaS

  2. Who am I? Tristan Darricau Developer at SensioLabs phpBB core

    contributor @nicofuma Twitter / Github / Gitlab / ...
  3. Platform as a Service

  4. Challenging

  5. Build

  6. Secrets (passwords)

  7. Database

  8. PaaS ?

  9. Back to the sources IaaS / CaaS / PaaS /

    SaaS
  10. IaaS Infrastructure as a Service Provides naked virtual machines and

    ntworking
  11. CaaS Container as a Service Boots containers and connects them

    (swarm)
  12. PaaS Platform as a Service Provides networked services (including your

    application)
  13. SaaS Software as a Service

  14. PaaS promises

  15. Infrastructure as code

  16. Automation

  17. None
  18. From Development to Production PAAS DEV PROD QA ... PPRD

  19. Let's deploy

  20. ftp / rsync ansible / chef / ...

  21. Git Push $ git push staging master $ git push

    production master
  22. None
  23. None
  24. Build step Every application has to be built buildpack, build

    script, assemble script... every provider has its own receipe
  25. 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'
  26. None
  27. Building Symfony composer container router translations annotations templates assets ....

  28. None
  29. Tips: composer composer install --no-interaction --prefer-dist \ --no-dev --optimize-autoloader --apcu-autoloader

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

  31. But... passwords?

  32. Passwords hardcoded parameters: ... database_user: "my_user" database_password: "my_password" ... Who

    wants to commit passwords ?
  33. Use "secret" parameters.yml file Still not ideal... Inject / build

    parameters.yml on runtime Not always possible
  34. Environment variables parameters: ... env(DATABASE_USER): "default_username" env(DATABASE_PASSWORD): "default_password" ... doctrine:

    ... user: "%env(DATABASE_USER)%" password: "%env(DATABASE_PASSWORD)%" ...
  35. Environment variables Since Symfony 3.2 only Available only on runtime

    Read only when needed Never cached
  36. None
  37. Cache?

  38. Symfony needs cache

  39. 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 ...
  40. Build on runtime? It may work but not ideal... Slow

    down first request May be blocked
  41. Generate on build Improved in Symfony 3.2 Statically generated Read

    only filesystem compliant Requires all parameters? (passwords)
  42. Generate on build bin/console cache:clear --env=prod bin/console cache:warmup --env=prod

  43. 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
  44. None
  45. 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"
  46. Database

  47. It was working

  48. None
  49. Update your database? When? How?

  50. Doctrine dependency hell

  51. When?

  52. How to do? Complex situation, no magic solution External tool

    3 steps deployment Downtime Forward compatibility ...
  53. What have we done?

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

  55. Going further

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

  57. Multi applications Handled by all providers app/ front/ .my_paas/ conf.yml

    packages.json back/ .my_paas/ conf.yml composer.json
  58. Review app Deploy a new env for each PR

  59. Read-Only

  60. Why? Security Scaling

  61. 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
  62. Merci ! #Symfony_Live @nicofuma Twitter / Github / Gitlab /

    ... https://joind.in/talk/bf1de