Your browser is unable to load the Impress slideshow.

Deployment-Werkzeug
für Webserver-Anwendungen

Andreas Klunker – 15.12.2014

Inhalt

  1. Anforderungen
  2. Lösung mit Capistrano
  3. Installation und Einrichtung
  4. Allgemeines zu Capistrano

1. Anforderungen bei der Bereitstellung von Webserver-Anwendungen

2. Lösung mit Capistrano

Systemaufbau

 

Entwicklungssystem

Staging-|Produktivsystem

Workflow

 

Entwicklungssystem

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Shiny new code</title>
...

$ git commit && git push

$ cap staging|production deploy

Staging-|Produktivsystem

Verzeichnisstruktur (Beispiel: raw.ur.de)

rzbvm005:/opt/raw_live/current -> /opt/raw_live/releases/20141211171712
                      /releases/20141211171712
                               /20141110092656
                               /20140829114502
                      /shared/foo
                             /bar

Capistrano im Einsatz

Neues Releaseverzeichnis anlegen

$ mkdir releases/[DATUMUHRZEIT]

Bare-Git ins neue Verzeichnis clonen

$ git clone /opt/raw.git releases/[DATUMUHRZEIT]

Symbolischen Link "current" auf den neuen Clone setzen

$ ln -s releases/[DATUMUHRZEIT] current

Benutzerdefinierte Befehle ausführen

$ ln -s shared/spot_of_the_week current/spot_of_the_week

3. Installation und Einrichtung

Systemvoraussetzungen

Installation auf dem Entwicklungssystem

$ gem install capistrano

Vorbereiten des Software-Projekts auf dem Entwicklungssystem

$ cd projektverzeichnis/
$ cap install
├── Capfile
├── config
│   ├── deploy
│   │   ├── production.rb
│   │   └── staging.rb
│   └── deploy.rb
└── lib
    └── capistrano
            └── tasks

Anpassen der Konfigurationsdateien

(Beispiel: raw.ur.de)

 

config/deploy.rb

set :application, 'raw'
set :repo_url, "kaa01744@rzbvm005:/opt/raw.git"
set :keep_releases, 5

# targets for symlinks
set :img_symlink_target, '/opt/raw_live/shared/images/'
set :txt_symlink_target, '/opt/raw_live/shared/text/'
set :sotw_symlink_target, '/opt/raw_live/shared/spot_of_the_week/'

namespace :deploy do
	desc "make a symlink for images, texts and spot of the week dirs"
	task :symlink do
		on roles(:all) do
			execute "ln -s #{fetch(:img_symlink_target)} #{fetch(:img_symlink_name)}; true"
			execute "ln -s #{fetch(:txt_symlink_target)} #{fetch(:txt_symlink_name)}; true"
			execute "ln -s #{fetch(:sotw_symlink_target)} #{fetch(:sotw_symlink_name)}; true"
		end
	end

	desc "make release dir writable for group, chmod files that need to be writable"
	task :chmod do
		on roles(:all) do
			execute "chmod -R g+w #{File.join(fetch(:deploy_to), 'releases')}; true"
			execute "chgrp raw #{File.join(fetch(:deploy_to), 'releases')} -R; true"
			execute "chmod o+rw #{fetch(:writable_file)}; true"
		end
	end

	after :finishing, 'deploy:cleanup'
	after :finishing, 'deploy:symlink'
	after :finishing, 'deploy:chmod'
end

config/deploy/staging.rb

# call: cap staging deploy
set :stage, :staging

server 'rzbvm005', roles: %w{web app db}, port: 22

set :deploy_to, '/opt/raw_test'
set :branch, 'raw_ng'
# linknames for symlinks
# images
set :img_symlink_name, '/var/www/raw_test/images'
# texts
set :txt_symlink_name, '/var/www/raw_test/text'
#spot of the week
set :sotw_symlink_name, '/var/www/raw_test/spot_of_the_week'
# file that needs to be writable by webserver
set :writable_file, '/var/www/raw_test/admin/export.xls'

config/deploy/production.rb

# call: cap production deploy
set :stage, :production

server 'rzbvm005', roles: %w{web app db}, port: 22

set :deploy_to, '/opt/raw_live'
set :branch, 'master'
# linknames for symlinks
# images
set :img_symlink_name, '/var/www/raw_live/images'
# texts
set :txt_symlink_name, '/var/www/raw_live/text'
#spot of the week
set :sotw_symlink_name, '/var/www/raw_live/spot_of_the_week'
# file that needs to be writable by webserver
set :writable_file, '/var/www/raw_live/admin/export.xls'

Wiederherstellen der letzten Softwareversion

$ cap production deploy:rollback

4. Allgemeines zu Capistrano

Danke! Fragen?