Skip to content

Instantly share code, notes, and snippets.

@drbraden
Forked from alediaferia/go.rake
Created May 9, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drbraden/b965f1800d01ad8eb073769344419eb8 to your computer and use it in GitHub Desktop.
Save drbraden/b965f1800d01ad8eb073769344419eb8 to your computer and use it in GitHub Desktop.
A couple of rake tasks to handle Go projects deployment
namespace :go do
task :upload do
on release_roles :all do
upload! "#{repo_path}/#{fetch(:application)}", release_path
end
end
task :build do
run_locally do
within repo_path do
with fetch(:go_build_env) do
execute :go, :build, :'-v'
end
end
end
end
task :run do
on release_roles :all do
with fetch(:go_run_env) do
within release_path do
if test "[ -f pid/#{fetch(:application)}.pid ]"
execute :kill, "`cat pid/#{fetch(:application)}.pid`"
end
execute :nohup, "./#{fetch(:application)}", "#{fetch(:go_run_args, '')} 2>&1 > #{shared_path}/log/#{fetch(:application)}.log & (echo $! > #{shared_path}/pid/#{fetch(:application)}.pid)"
end
end
end
end
end
after 'deploy:updating', 'go:build'
after 'go:build', 'go:upload'
after 'deploy:finished', 'go:run'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment