Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Laravel Day / Deploy

"Da sempre fare il deploy di applicazioni multi-istanza rappresenta una sfida per lo sviluppatore e per il sistemista. Oggi grazie a strumenti gratuiti e un pò di esperienza in materia è possibile eseguire tale operazione lavorando su pipeline che prevedono testing automatico, validazione del code style e molto altro, in modo da ottenere una Continuous Integration consistente, efficace ed in tempi brevissimi. Scopriamo insieme come con un progetto Laravel e le pipeline di Bitbucket."

  • Be the first to comment

  • Be the first to like this

Laravel Day / Deploy

  1. 1. 2017.LARAVEL DAYDeploy di applicazioni Laravel con le pipeline di Bitbucket
  2. 2. @SENSORARI OSimone (Demo) Gentili
  3. 3. IL PROGETTO LEGACYlaravel 4, forge, homestead, beanstalk, …
  4. 4. N configurazioni, N branch, N code (~_~;)
  5. 5. 1 codebase, 1 deploy, N configurazioni (◠‿◠)
  6. 6. Totale assenza di una suite di test (~_~;)
  7. 7. Un po’ di test end2end (◠‿◠)
  8. 8. beanstalk effettua il deploy anche se i test si rompono ¯_(ツ)_/¯
  9. 9. CONTINUOUS DEPLOYMENTCircleCI, TravisCI, CodeShip, Go-CD, Jenkins, …
  10. 10. Jenkins, Go-CD (◠‿◠)
  11. 11. No software da installare (╯°□°)╯︵ ┻━┻
  12. 12. CircleCI, TravisCI, CodeShip, Go-CD, Jenkins, …
  13. 13. CircleCI, TravisCI, .. (◠‿◠)
  14. 14. Budget a disposizione Limitato (ノಠ益ಠ)ノ彡┻━┻
  15. 15. CircleCI, TravisCI, CodeShip, Go-CD, Jenkins, …
  16. 16. $ git remote add bitbucket git@… $ git push bitbucket master (☞゚ヮ゚)☞
  17. 17. Bitbucket Pipelines (◠‿◠)
  18. 18. BITBUCKET PIPELINESssh, code deploy, private repositories, environments, …
  19. 19. When someone pushes to the repo, Pipelines runs the build in a Docker image. - https://confluence.atlassian.com
  20. 20. Repository privati (~_~;)
  21. 21. umask 077 ; echo $SSH_KEY | base64 --decode > ~/.ssh/id_rsa (◠‿◠)
  22. 22. 1 codebase, 1 deploy, N configurazioni (◠‿◠)
  23. 23. branches: master: - step: script: - apt-get update && apt-get install -qy git curl libmcrypt-dev mysql-client zip unzip - docker-php-ext-install mcrypt && docker-php-ext-install pdo_mysql - apt-get update && apt-get install -y vim … … - chmod +x install-composer.sh - ./install-composer.sh - composer dumpautoload - composer install - mkdir -p ~/.ssh - cat my_known_hosts >> ~/.ssh/known_hosts - (umask 077 ; echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa) - php artisan migrate - ./runtests - tar -czf build.tar.gz ./* - sftp $SERVER_SSH_USER@$SERVER_SSH_IP <<< $'put build.tar.gznEXIT' - ssh $SERVER_SSH_USER@$SERVER_SSH_IP ' export TEMP=tmp-folder && export CURRENT=/home/forge/www.example.com && export BACKUP=/home/forge/old_api && mkdir -p $CURRENT && mkdir -p /home/forge/$TEMP && rm -rf $TEMP && mkdir $TEMP && tar -vxzf build.tar.gz -C $TEMP && mkdir -p $BACKUP && rm -rf $BACKUP && mv $CURRENT $BACKUP && mv $TEMP $CURRENT && cp $BACKUP/.env $CURRENT/.env && cd $CURRENT && php artisan migrate --force' - sftp $SERVER_SSH_USER_FOO@$SERVER_SSH_IP_FOO <<< $'put build.tar.gznEXIT’ - ssh $SERVER_SSH_USER_FOO@$SERVER_SSH_IP_FOO ' export TEMP=tmp-folder && export
  24. 24. Deploy di applicazioni Laravel con le pipeline di Bitbucket (◠‿◠)
  25. 25. - aws deploy push --application-name LaravelDaySample --s3-location s3://production-artifacts- laravel/production_api_build.zip —no-ignore- hidden-files - aws deploy create-deployment --application- name LaravelDaySample --s3-location bucket=production-artifacts- laravel,key=production_api_build.zip,bundleTyp e=zip --deployment-group-name LaravelDaySample --auto-rollback-configuration enabled=true,events="DEPLOYMENT_FAILURE" -- file-exists-behavior RETAIN
  26. 26. LARAVEL TENANT.env, models, controllers, …
  27. 27. .ENV MAIL_DRIVER=smtp MAIL_HOST=******** MAIL_PORT=2525 MAIL_USERNAME=42 MAIL_PASSWORD=42 MAIL_ADDRESS=******** MAIL_NAME=******** API_PREFIX=api API_DEBUG=true S3_KEY=******** S3_SECRET=******** S3_REGION=eu-west-1 S3_BUCKET=******** SMS_SEND=0 SMS_USERNAME=******** SMS_PASSWORD=******** APP_ENV=local APP_DEBUG=true APP_KEY=******** APP_TENANT=Tenant APP_BACKUP_PATH=tenant DB_HOST=127.0.0.1 DB_DATABASE=******** DB_USERNAME=******** DB_PASSWORD=******** DB_PORT=3306 CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379
  28. 28. ./APP/HTTP/ROUTES.PHP <?php $tenant = env(‘APP_TENANT'); $root = file_exists( base_path() . ‘/$tenant/' . ‘/Http/Controllers/Api/FooController.php' )) ? $tenant : ’App'; $api->get( ‘resource/{id}', $root . ‘HttpControllersApiFooController@show’ )->where(['id' => '[0-9]+']);
  29. 29. ./COMPOSER.JSON "autoload": { "psr-4": { "App": "app/", "Verona": "tenants/verona/", "Forli": "tenants/forli/", "Molise": "tenants/molise/", "Cesena": "tenants/cesena/", "Veneto": "tenants/veneto/", "Tokyo": “tenants/tokyo/" } },
  30. 30. ASPETTI MIGLIORABILIdatabase, scripts, …
  31. 31. Spazio su disco scarso (~_~;)
  32. 32. Configurazione tenant legata al dominio (◠‿◠)
  33. 33. pipeline da ricostruire ad ogni nuovo progetto (~_~;)
  34. 34. deployer, capistrano, rsync, … (◠‿◠)
  35. 35. budget (◠‿◠)
  36. 36. budget (~_~;)
  37. 37. LINK & RISORSEascii, documentazione, …
  38. 38. LINKS ➤ https://en.wikipedia.org/wiki/List_of_emoticons ➤ https://bitbucket.org/product/features/pipelines ➤ https://confluence.atlassian.com/bitbucket/laravel-with- bitbucket-pipelines-913473967.html ➤ https://github.com/sensorario ➤ https://github.com/edbizarro/bitbucket-pipelines-php7 ➤ https://www.slideshare.net/sensorario ➤ https://joind.in/event/laravelday/deploy-di-applicazioni-laravel- con-le-pipeline-di-bitbucket
  39. 39. FINE
  40. 40. QUESTIO N TIME
  41. 41. https://joind.in/event/laravelday/deploy-di-applicazioni-laravel-con-le-pipeline-di-bitbucket
  42. 42. 2017.LARAVEL DAYDeploy di applicazioni Laravel con le pipeline di Bitbucket

×