際際滷

際際滷Share a Scribd company logo
Deployment kodu
z Capistrano
Typowy proces
 Aktualizacja kodu
 Kon鍖guracja
 Instalacja zale甜noci
 Aktualizacja bazy danych
 Uruchomienie aplikacji
Proste rozwizanie
1. Pobierz najnowsz wersje kodu
2. Zaktualizuj wartoci w plikach kon鍖guracyjnych
3. Zainstaluj zale甜ne biblioteki A, B i C
4. Uruchom w bazie plik migrate.sql
5. Zrestartuj serwer
Problemy
 Plan awaryjny
 Aktualizacja wielu serwer坦w jednoczenie
 Wsp坦dzielenie plik坦w pomidzy releasami
 Zero downtime
Capistrano
 Narzdzie do zautomatyzowanego zarzdzania
zdalnymi serwerami
 Pozwala w przyjazny spos坦b de鍖niowa i
wykonywa zadania lub cae cigi zada na
zdalnych maszynach
 Ruby gem
 Nakadka na gem SSHKit
Instalacja
$ gem install capistrano	
$ cap install	
!
Instalacja
"## Capfile	
"## config	
$ "## deploy	
$ $ "## production.rb	
$ $ %## staging.rb	
$ %## deploy.rb	
%## lib	
%## capistrano	
%## tasks
Cap鍖le
# Load DSL and Setup Up Stages	
require 'capistrano/setup'	
!
# Includes default deployment tasks	
require 'capistrano/deploy'	
!
# Includes tasks from other gems included in your Gemfile	
#	
# require 'capistrano/rails'	
# require 'capistrano/laravel'	
# require 'capistrano/symfony'	
# require 'capistrano/npm'	
!
# Loads custom tasks from `lib/capistrano/tasks' if you have any
defined.	
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
deploy.rb
set :application, "my_app"	
set :scm, "git"	
set :repo_url, 	
	 "git@github.com/me/my_app.git"	
!
set :branch, "master"	
set :deploy_to, 	
	 "/var/www/my_app"
deploy.rb
set :application, "my_app"	
set :scm, "git"	
set :repo_url, 	
	 "git@github.com/me/my_app.git"	
!
set :branch, "master"	
set :deploy_to, 	
	 "/var/www/#{fetch(:application)}"
production.rb
role :app, %w{user@s1.com user@s2.com}	
role :web, %w{user@s1.com}	
role :db, %w{user@s1.com}
Zadania
$ cap -T	
cap deploy	
cap deploy:check	
cap deploy:rollback	
!
$ cap production deploy	
$ cap production deploy:check
Setup serwera
$ mkdir -p /var/www/my_app	
$ chown -R deploy /var/www/my_app
Setup serwera
/var/www/my_app	
"## releases	
%## shared	
"## bin	
"## config	
"## log	
"## public	
"## tmp	
%## vendor
Deployment
/var/www/my_app	
"## current (-> releases/20140521130616)	
"## releases	
$ %## 20140521130616	
"## repo	
"## releases.log 	
%## shared
revisions.log
$ cat revisions.log	
Branch master (at 3fa7748) deployed as
release 20140521130616 by michal
Przydatne opcje
set :linked_files, 	
	 %w{config/database.yml}	
!
set :linked_dirs, 	
	 %w{bin log tmp vendor public/system}	
!
set :keep_releases, 5	
!
ask :branch, "master"
Zadania
namespace :deploy do	
	 task :my_task do	
	 	 # tre	
	 end	
end
check_uptime
on release_roles(:all) do |host|	
info "Running my task on #{host}"	
execute :uptime	
end
Flow
# check everything, start a deployment	
deploy:starting 	
!
# update server(s) with a new release	
deploy:updating 	
!
# publish the new release	
deploy:publishing	
!
# finish the deployment, clean up everything	
deploy:finishing
Flow
deploy:starting	
deploy:started	
deploy:updating 	
deploy:updated	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:finished	
!
before :starting, :my_task	
after :finishing, :my_other_task
Rollback
deploy:starting	
deploy:started	
deploy:reverting	
deploy:reverted	
deploy:publishing	
deploy:published	
deploy:finishing_rollback	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
deploy:updated	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
	 [before]	
deploy:ensure_stage	
deploy:set_shared_assets	
deploy:check	
deploy:started	
deploy:updating	
deploy:updated	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
git:create_release	
deploy:symlink:shared	
deploy:updated	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
deploy:updated	
[before]	
deploy:bundle	
[after]	
deploy:migrate	
deploy:compile_assets	
deploy:normalize_assets	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
deploy:updated 	
deploy:publishing	
deploy:symlink:release	
deploy:restart 	
deploy:published	
deploy:finishing	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
deploy:updated 	
deploy:publishing	
deploy:published	
deploy:finishing	
deploy:cleanup	
deploy:finished
Ruby on Rails Flow
deploy	
deploy:starting	
deploy:started	
deploy:updating	
deploy:updated 	
deploy:publishing 	
deploy:published	
deploy:finishing	
deploy:finished	
deploy:log_revision
Best practices
 Trzyma kon鍖guracj deploymentu w repozytorium
 Nie trzyma wra甜liwych danych w repozytorium, tylko w shared
na serwerze
 Kompilowa kod na serwerze zamiast trzyma skompilowany kod
w repozytorium
 Dla customowych zada napisa hooki do deploy:starting i
deploy:reverting
 Rozbudowa deploy:check o sprawdzanie zale甜nych bibliotek
 Nie pr坦bowa zautomatyzowa absolutnie wszystkiego
Pytania?
Micha Szajbe
!
monterail.com
!
@szajbus

More Related Content

Deployment kodu z Capistrano