Share
Embed
Transcript
21 slides
-
Capistrano • Deployanje aplikacije ne mora biti komplicirano! • Capistano
nije build alat • Deployanje na *nix poslužitelje • Ruby • Client-side aplikacija -
Ideja • razdvojiti foldere i datoteke prema namjeni ◦ aplikacija
(PHP, templates, ...) ◦ site-specific (config, logs, user uploads) • update-ati aplikacijske datoteke • polinkati site-specific datoteke i foldere • promijeniti symbolic link da pokazuje na novu verziju • maintenance (clear cache, APC, reload web servera, ...) -
Implementacija /var/www/example.com/ |--current -> s. l. na zadnji release |--releases
|-----20121124172616 |-----20121124172617 |-----20121124172618 |--shared |----cached-copy -> git cache |----system -> site specific files |------data |--------logs |------public |--------images -
Prednosti • one step deployment • atomic operacija • automatizacija
maintenance poslova • deployanje na više poslužitelja od jednom • različiti procesi u ovisnosti o namjeni poslužitelja • mogućnost rollback-a -
Priprema ./ Capfile |- config/ |- deploy/ | |- production.rb
| |- staging.rb |- deploy.rb |- railsless-deploy.rb -
Priprema #2 Capfile 1 require "./config/railsless-deploy.rb" 2 load 'config/deploy' if
respond_to?(:namespace) railsless-deploy.rb https://github.com/leehambley/railsless-deploy -
Environments production.rb 1 set :production1, "172.16.20.1" 2 set :production2, "172.16.20.2"
3 set :deploy_to, "/var/www/#{application}" 4 set :port, 12345 5 6 server production1, :web, :app, :db 7 server production2, :web, :app, :db staging.rb 1 set :staging1, "192.168.5.1" 2 set :deploy_to, "/var/www/#{application}" 3 set :port, 22 4 5 server staging1, :web, :app, :db -
deploy.rb 1 set :default_stage, "staging" 2 set :stages, %w(production staging)
3 require 'capistrano/ext/multistage' 4 5 set :application, "example.com" #ime foldera!! 6 7 # SCM OPTIONS 8 set :scm, :git # Može i :svn ili :copy 9 set :repository, "[email protected]:repo.git" 10 set :branch, 'master' 11 #set :scm_password, "some-password" # optional 12 default_run_options[:pty] = true 13 14 # SSH OPTIONS 15 set :user, "root" 16 set :use_sudo, false -
deploy.rb #2 1 # CAPISTRANO OPTIONS 2 set :keep_releases, 3
3 set :deploy_via, :remote_cache 4 set :copy_exclude, [".git", ".gitignore"] 5 6 # APPLICATION SYMBOLIC LINKS 7 set :app_symlink_folders, ["vendor", "public/images", "data/logs"] 8 set :app_symlink_files, ["config.php"] 9 10 # CUSTOMIZE TASKS 11 namespace :deploy do 12 13 desc "Symlink directories that need to remain between deployments." 14 task :create_shared_resources do 15 if app_symlink_folders 16 app_symlink_folders.each do |link| 17 run "mkdir -p #{shared_path}/system/#{link}" 18 end 19 end 20 end -
deploy.rb #3 1 desc "Customize the finalize_update task" 2 task
:finalize_update, :except => { :no_release => true } do 3 run "chown -R www-data:www-data #{latest_release}" 4 5 symlink_shared_resources 6 cleanup 7 end 8 9 desc "Symlink folders" 10 task :symlink_shared_resources, :except => { :no_release => true } do 11 if app_symlink_folders 12 app_symlink_folders.each do |link| 13 run "rm -rf #{latest_release}/#{link}" 14 run "ln -s #{shared_path}/system/#{link} #{latest_release}/#{link}" 15 end 16 end 17 end 18 19 desc "Symlink folders" 20 .... 21 end -
Finalni koraci • Prije prvog deploy-a: ◦ Promijeniti DocumentRoot (Apache)
ili root (nginx) direktivu ◦ $ cap production deploy:setup ◦ $ cap deploy:setup -
Napokon • Deployanje nove verije: ◦ git commit -a -m
"Nova verzija" ◦ git push ◦ cap production deploy • Rollback: ◦ cap production deploy:rollback -
Ideje • DB migracije (up & down) • maintenance stranica
prilikom migracija baza • composer.phar install/update • cache cleanup & warmup -
FPM Effing Package Management • https://github.com/jordansissel/fpm • Creating packages easily
(deb, rpm, etc) • Tweaking existing packages (removing files, changing metadata/dependencies) • Stripping pre/post/maintainer scripts from packages -
Izvori • gem (autodownloaded) • python modules (autodownload) • pear
(autodownload) • directories • rpm • deb • node packages (npm) -
Destinacije • deb • rpm • solaris • tar •
directories -
Oneliner 1 gem install fpm 2 cd /moj-projekt/ 3 fpm
-s dir -t deb -a i386 -n rac-api -v ${version} --vendor Ccentar / 4 --prefix /var/www ./ Na serveru 1 dpkg -i rac-api_0.3.5_i386.deb -
The end Hvala * mail: [email protected] * twitter: @goran_juric *
blog: http://gogs.info/ Built with Landslide: https://github.com/adamzap/landslide