ã¿ã¤ãã«ã®éãCapistranoã§Javaã®Webã¢ããªã±ã¼ã·ã§ã³ï¼warãã¡ã¤ã«ã¨ãJettyãçµã¿è¾¼ãã jarãã¡ã¤ã«ã¨ãï¼ããããã¤ãã¦ãã®ã§ãããã¿ãªããã©ããã£ã¦ããã§ããããï¼ï¼
ä¼ç¤¾ã§ã¯Java以å¤ã®ãããã¯ããçµæ§ãã£ã¦ãããããCapistranoã§ãããã¤ãã¦ããããJavaã®ãããã¯ããCapistranoã§ãããã¤ãã¦ããã®ã§ãããGradleã¨ãã§ããã®ãå¤ãã®ããªãã¼ããã
æè¿Capistranoã®ãã¼ã¸ã§ã³ã2ãã3ã¸ä¸ããã¨ãã«ããã®è¾ºã®äºæ ãæ°ã«ãªã£ãã®ã§ããã°è¨äºã«æ¸ããã¨ã«ãã¾ããã
Capistranoã®ãã¼ã¸ã§ã³ã¯ã3.2.1ã§ãã
ã¤ã³ã¹ãã¼ã«ãã¿ã¹ã¯ã®ããã¼ãªã©ã¯ä»¥ä¸ã®ãã¼ã¸ãåèã«ãªãã¨æãã¾ãã
ãã«ãã»ãããã¤ã®æµã
- Gitãªãã¸ããªã«push
- Jenkinsã§ã¦ããããã¹ãï¼ãã«ã
- 社å ã®Mavenãªãã¸ããªã«publish
ã¨ããæµãã¯èªååããã¦ã¾ãã
ãã®å¾ãMavenãªãã¸ããªã«publishãããã¢ã¼ãã£ãã¡ã¯ããèªåã§ã¹ãã¼ã¸ã³ã°ç°å¢ã¸ãããã¤ããããæ¬çªç°å¢ã¸ãããã¤ã楽ã«ããããã«ããããã¤ãèªååããããªãã¾ãã ãããã®ãããã¤ãCapistranoã使ã£ã¦èªååãã¦ãã¾ãã
ãããã¤ã¿ã¹ã¯
Capistranoã§ãããã¤ããã¨ããããã©ã«ãã ã¨Gitããã½ã¼ã¹ã³ã¼ããåå¾ããã®ã§ãããã¿ã¹ã¯ããªã¼ãã¼ã©ã¤ããããã¨ã§ç¤¾å ã®Mavenãªãã¸ããªããã¢ã¼ãã£ãã¡ã¯ããwgetã§åå¾ããããã«å¤æ´ãã¦ã¾ãã
Capistrano3ã§ã¯ä»¥ä¸ã®ãã¼ã¸ã«ããéããè¤æ°ã®ã¿ã¹ã¯ãé çªã«å¼ã°ãã¾ãã
Capistrano3のデプロイフレームワークの使い方 - Qiita
å¼ã³åºããã¦ããã¿ã¹ã¯ãè¦ã¦ã¿ãã¨ãgité¢é£ã®ã¿ã¹ã¯ãdeploy:check
ã¿ã¹ã¯ã¨deploy:updating
ã¿ã¹ã¯ã®ä¸ã§å¼ã³åºããã¦ãã¾ãã
ã¾ãã¯ãdeploy:check
ã¿ã¹ã¯ããªã¼ãã¼ã©ã¤ããã¦git:check
ãå¼ã°ãªãããã«ãã¾ããï¼åèï¼Overriding Capistrano tasksï¼
å
ã
ã®å¦çããgit:check
ã®å¼ã³åºãã ãåé¤ãã¾ãã
# deply.rb namespace :deploy do Rake::Task["deploy:check"].clear_actions task :check do #invoke "#{scm}:check" gitã使ããªãã®ã§ä¸è¦ invoke 'deploy:check:directories' invoke 'deploy:check:linked_dirs' invoke 'deploy:check:make_linked_dirs' invoke 'deploy:check:linked_files' end end
次ã«ãdeploy:updating
ããªã¼ãã¼ã©ã¤ããã¾ãã
ãããã®åã«ã¢ã¼ãã£ãã¡ã¯ãã®ãã¼ã¸ã§ã³çªå·ãå
¥åããããã®ã¿ã¹ã¯ãä½ãã¾ããããã¦ãbefore
ã使ã£ã¦ä½æããã¿ã¹ã¯ãdeploy:updating
ã¿ã¹ã¯ã®å®è¡åã«å¼ã°ããããã«ãã¾ãã
ask
ã使ãã¨å¯¾è©±çã«ãã©ã¡ã¼ã¿ã渡ããã¨ãã§ãã¾ãã
# deply.rb namespace :deploy do task :version do ask(:version, "nil") on roles(:all) do |h| if fetch(:version).nil? || fetch(:version) == "nil" error "version ãæå®ããã¦ãã¾ãã" exit 99 else execute "echo \"OK! version: #{fetch(:version)}\"" end end end before :updating, :version end
ããã§ã¢ã¼ãã£ãã¡ã¯ãã®ãã¼ã¸ã§ã³çªå·ã対話çã«å ¥åã§ããããã«ãªãã¾ãããç°å¢å¤æ°ã§æ¸¡ãã¦ãè¯ãã§ããã
ã§ã¯ãdeploy:updating
ããªã¼ãã¼ã©ã¤ããã¦ãMavenãªãã¸ããªããã¢ã¼ãã£ãã¡ã¯ãããã¦ã³ãã¼ãããããã«ãã¾ãã
ã¾ããdeploy:updating
ã¿ã¹ã¯ããå¼ã³åºãã¦ããdeploy:set_current_revision
ã¿ã¹ã¯ã§RIVISIONã¨ãããã¡ã¤ã«ãä½ã£ã¦ããã®ã§ããããã®ã¿ã¹ã¯ã®ä¸ã§ãgité¢é£ã®ã¿ã¹ã¯ãå¼ã³åºãã¦ããã®ã§ãããæ¸ãæãã¾ãã
# deply.rb set :application, 'myapp' set :group_dir, 'com/exmaple' set :m2repo, 'http://m2repo.example.com' namespace :deploy do Rake::Task["deploy:updating"].clear_actions task :updating => :new_release_path do #invoke "#{scm}:create_release" gitã使ããªãã®ã§ä¸è¦ # 代ããã«ãwgetã§Mavenãªãã¸ããªããjar/warãã¡ã¤ã«ããã¦ã³ãã¼ãããããã«ãã on release_roles :all do execute :mkdir, '-p', release_path execute :wget, "#{fetch(:m2repo)}/#{fetch(:group)}/#{fetch(:application)}/#{fetch(:version)}/#{fetch(:application)}-#{fetch(:version)}.war -P #{release_path}" end #invoke "deploy:set_current_revision" gitã使ããªãã®ã§ä¸è¦ # 代ããã«ãå ¥åããããã¼ã¸ã§ã³ãREVISIONãã¡ã¤ã«ã«æ¸ãè¾¼ã on release_roles :all do within release_path do execute :echo, "\"#{fetch(:version)}\" >> REVISION" end end invoke 'deploy:symlink:shared' end end
ãã¨ã¯åèµ·åã¿ã¹ã¯ãä½ãã¾ããafter
ã使ã£ã¦publishing
ã®å¾ã«å®è¡ãããããã«ãã¾ãã
# deply.rb namespace :deploy do task :restart do on roles(:app), in: :sequence, wait: 5 do |host| info("restart on #{host}") # LBãããµã¼ãã¼ãåãé¢ãã¦ãã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ãåèµ·åãããããå¦çãããã«æ¸ã end end after :publishing, :restart end
ããã§ãCapistranoã使ã£ã¦èªåãããã¤ã§ããããã«ãªãã¾ããã
ã¹ãã¼ã¸ã³ã°ç°å¢ã¸ãããã¤ãããå ´åã¯cap staging deploy
ã§ããï¼
ãããã«
ä»ã®ã¨ããããã®ãããã¤æ¹æ³ã§å°ã£ã¦ãªãã®ã§ãããJava ã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤ã«ã¤ãã¦ã®ãã¹ããã©ã¯ãã£ã¹ãæ°ã«ãªã£ã¦ãã¨ããã§ãã»ã»ã»ã
æå¾ã«deploy.rbã®å ¨ä½åãè¼ãã¦ããã¾ãã
# deply.rb set :application, 'myapp' set :group_dir, 'com/exmaple' set :m2repo, 'http://m2repo.example.com' namespace :deploy do Rake::Task["deploy:check"].clear_actions task :check do #invoke "#{scm}:check" gitã使ããªãã®ã§ä¸è¦ã«ãªã invoke 'deploy:check:directories' invoke 'deploy:check:linked_dirs' invoke 'deploy:check:make_linked_dirs' invoke 'deploy:check:linked_files' end task :version do ask(:version, "nil") on roles(:all) do |h| if fetch(:version).nil? || fetch(:version) == "nil" error "version ãæå®ããã¦ãã¾ãã" exit 99 else execute "echo \"OK! version: #{fetch(:version)}\"" end end end before :updating, :version Rake::Task["deploy:updating"].clear_actions task :updating => :new_release_path do #invoke "#{scm}:create_release" gitã使ããªãã®ã§ä¸è¦ã«ãªã # 代ããã«ãwgetã§Mavenãªãã¸ããªããjar/warãã¡ã¤ã«ããã¦ã³ãã¼ãããããã«ãã on release_roles :all do execute :mkdir, '-p', release_path execute :wget, "#{fetch(:m2repo)}/#{fetch(:group)}/#{fetch(:application)}/#{fetch(:version)}/#{fetch(:application)}-#{fetch(:version)}.war -P #{release_path}" end #invoke "deploy:set_current_revision" gitã使ããªãã®ã§ä¸è¦ã«ãªã # 代ããã«ãå ¥åããããã¼ã¸ã§ã³ãREVISIONãã¡ã¤ã«ã«æ¸ãè¾¼ã on release_roles :all do within release_path do execute :echo, "\"#{fetch(:version)}\" >> REVISION" end end invoke 'deploy:symlink:shared' end task :restart do on roles(:app), in: :sequence, wait: 5 do |host| info("restart on #{host}") # LBãããµã¼ãã¼ãåãé¢ãã¦ãã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ãåèµ·åãããããå¦çãããã«æ¸ã end end after :publishing, :restart end