项目作者: rybus

项目描述 :
Capistrano + Symfony plugin to deploy Akeneo
高级语言: Ruby
项目地址: git://github.com/rybus/akeneo-deployment.git
创建时间: 2017-12-04T21:31:02Z
项目社区:https://github.com/rybus/akeneo-deployment

开源协议:GNU General Public License v3.0

下载


Deploy Akeneo with Capistrano

When deploying an application, multiple steps are necessary (code pulling, dependencies updates, cache clearing, etc.).
In order to facilitate this crucial moment, you can use a tool like Capistrano.

In the following cookbook, you will learn how to deploy your project to one or multiple servers with a source code
hosted on a Git repository.

Prerequisites

  1. Make sure you have write permissions on the server you want to deploy to.
  2. Make sure you can connect to the server using SSH.
  3. Make sure you can access your Git repository.

Ruby and Capistrano installation

  1. Install Ruby: installation procedure.
  2. Create a Gemfile at the root of the project, with the following content:
  1. source "https://rubygems.org"
  2. gem 'capistrano'
  3. gem 'capistrano-symfony', '~> 1.0.0.rc1'
  4. gem 'capistrano-composer'
  1. Install Bundler and the dependencies from the Gemfile
  1. sudo gem install bundler
  2. bundle install --path vendor/bundle

This file lists the bundles to install from the official Ruby repository. More info about Gemfiles here.

  1. Create a Capfile
  1. # /host/path/to/you/pim/Capfile
  2. # Load DSL and set up stages
  3. require "capistrano/setup"
  4. # Include default deployment tasks
  5. require "capistrano/deploy"
  6. require 'capistrano/symfony'
  7. require "capistrano/scm/git"
  8. install_plugin Capistrano::SCM::Git
  9. Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

This file is responsible for the actual loading of the dependencies. More info about Capfiles here.

File structure

This is the file structure from the project root.

  1. .
  2. ├── Capfile
  3. ├── config
  4. ├── deploy
  5. ├── development.rb
  6. ├── production.rb
  7. └── staging.rb
  8. └── deploy.rb
  9. └── Gemfile

Common configuration

In the following configuration, please update repo_url to point to your git repository.

  1. set :application, 'acme'
  2. set :repo_url, 'git@github.com:acme/project.git'
  3. set :format, :pretty
  4. set :log_level, :info
  5. set :symfony_env, "prod"
  6. set :symfony_directory_structure, 3
  7. set :sensio_distribution_version, 4
  8. set :app_path, "app"
  9. set :web_path, "web"
  10. set :app_config_path, "app/config"
  11. set :log_path, "var/logs"
  12. set :cache_path, "var/cache"
  13. set :branch, ENV.fetch("BRANCH", "master")
  14. set :composer_install_flags, '--no-dev --prefer-dist --no-interaction --optimize-autoloader'
  15. set :linked_files, %w{app/config/parameters.yml}
  16. set :linked_dirs, %w{var/logs web/uploads app/file_storage}
  17. set :controllers_to_clear, ["app_*.php"]
  18. set :symfony_console_path, "bin/console"
  19. set :symfony_console_flags, "--no-debug"
  20. set :keep_releases, 3
  21. after 'deploy:finishing', 'deploy:cleanup'
  22. after 'deploy:updated', 'symfony:assets:install'
  23. namespace :deploy do
  24. desc "Regenerating cache, assets and javascript"
  25. task :javascript do
  26. on roles(:app) do
  27. within release_path do
  28. execute *%w[ rm -rf var/cache/* ./web/bundles/* ./web/css/* ./web/js/* ]
  29. symfony_console('pim:installer:assets', '--env=prod')
  30. symfony_console('cache:warmup', '--env=prod')
  31. execute *%w[ rm -rf node_modules; npm install; npm run ]
  32. execute *%w[ yarn run webpack ]
  33. execute *%w[ partners_clear_cache ]
  34. end
  35. end
  36. end
  37. end
  38. after 'deploy:updated', 'deploy:javascript'

You can adapt other settings according to the configuration of your server.

Environment-specific configuration

You have to create one file per environment you have.

  1. set :stage, :staging
  2. set :deploy_to, '/home/akeneo/'
  3. set :ssh_user, 'akeneo'
  4. server 'akeneo.tld', user: fetch(:ssh_user), roles: %w{web app db}

Remote file structure

The remote file structure will be the following, with /deploy/to being the value of :deploy_to.

  1. ├── current -> /deploy/to/releases/20150120114500/
  2. ├── releases
  3. ├── 20150080072500
  4. ├── 20150090083000
  5. └── ...
  6. ├── repo
  7. └── <VCS related data>
  8. ├── revisions.log
  9. └── shared
  10. ├── app
  11. | ├── file_storage
  12. | └── config
  13. | └── parameters.yml # Create this file.
  14. ├── var
  15. | └── logs
  16. └── web
  17. └── uploads

Important you have to create parameters.yml on the remote server before the first deployment.

Deployment

You can deploy on the staging environment by running

  1. bundle exec cap staging deploy

You can also specify which branch you want to deploy by using

  1. bundle exec cap staging deploy BRANCH=hotfix

See also