How to recover from failed builds?


#1

Hi all,
A bit of a newbie question. I’m using chef solo and vagrant to deploy a
django app. I didn’t write the recipes, but tweaked them a bit to work on
Ubuntu. I’ve finally got to the point where the app deploys correctly,
first time. But one thing I noticed in that process is if the build fails
some reason (generally while running buildout), then the "before_symlink"
step doesn’t get run again.

Not being a Rails developer, I don’t really understand the deployment model
(ie, directories ‘shared’, ‘release’, ‘current’) that is apparently assumed
by Chef and followed implicitly. For example, I don’t see an explicit step
that creates a symlink ‘current’ to the release - it just happens. (The
documentation http://wiki.opscode.com/display/chef/Deploy+Resource is a bit
unclear )

So, I was wondering if someone could suggest changes to make to this script
so that it would repeat the ‘bash’ block if there has not been a successful
build. Thanks!

Steve


deploy_revision “mytardis” do
action :deploy
deploy_to "/opt/mytardis"
repository node[‘mytardis’][‘repo’]
branch node[‘mytardis’][‘branch’]
user "mytardis"
group "mytardis"
symlink_before_migrate(app_symlinks.merge({
“data” => “var”,
“log” => “log”,
“buildout.cfg” => “buildout-prod.cfg”,
settings.py” => “tardis/settings.py”
}))
purge_before_symlink([])
create_dirs_before_symlink([])
symlinks({})
before_symlink do
current_release = release_path

bash "mytardis_buildout_install" do
  user "mytardis"
  cwd current_release
  code <<-EOH
    export PYTHON_EGG_CACHE=/opt/mytardis/shared/egg-cache
    python setup.py clean
    find . -name '*.py[co]' -delete
    python bootstrap.py
    bin/buildout -c buildout-prod.cfg install
    bin/django syncdb --noinput --migrate
    bin/django collectstatic -l --noinput
  EOH
end

end
restart_command do
current_release = release_path

bash "mytardis_foreman_install_and_restart" do
  cwd "/opt/mytardis/current"
  code <<-EOH
    foreman export upstart /etc/init -a mytardis -p 3031 -u mytardis -l

/var/log/mytardis -t ./foreman
restart mytardis || start mytardis
EOH
end
end
end