Skip to content

Instantly share code, notes, and snippets.

@noma4i
Forked from Kr00lIX/deploy.rb
Created September 16, 2016 09:55
Show Gist options
  • Save noma4i/9766ed2aff6bcf92280c0493c5febbed to your computer and use it in GitHub Desktop.
Save noma4i/9766ed2aff6bcf92280c0493c5febbed to your computer and use it in GitHub Desktop.
Deploy Phoenix Elixir by mina
require 'mina/bundler'
require 'mina/git'
require 'mina/rbenv'
set :domain, 'your_domain.com'
set :deploy_to, '/home/deployer/app_name'
set :repository, '[email protected]:user_name/app_name'
set :branch, ENV["brunch"] || 'master'
set :app_name, "app_name"
set :shared_paths, %w(
config/prod.secret.exs
node_modules
bower_components
deps
rel
_build
)
set :user, 'deployer'
set :forward_agent, true
#set :identity_file, '~/.ssh/id_rsa.pem'
set :log_path, "#{deploy_to}/#{current_path}/rel/#{app_name}/log"
task :environment do
queue %[source ~/.asdf/asdf.sh]
queue %[export PATH=$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH]
queue %[export MIX_ENV=prod]
end
task :setup => :environment do
queue %[mkdir -p "#{deploy_to}/#{shared_path}/node_modules"]
queue %[mkdir -p "#{deploy_to}/#{shared_path}/bower_components"]
queue %[mkdir -p "#{deploy_to}/#{shared_path}/deps"]
queue %[mkdir -p "#{deploy_to}/#{shared_path}/_build"]
queue %[mkdir -p "#{deploy_to}/#{shared_path}/rel"]
queue %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
queue %[touch "#{deploy_to}/#{shared_path}/config/prod.secret.exs"]
queue %[ if ! asdf plugin-list | grep erlang; then asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git; fi]
queue %[ if ! asdf plugin-list | grep elixir; then asdf plugin-add elixir https://github.com/HashNuke/asdf-elixir.git; fi]
queue %[ erlang_version=$(awk '/erlang/ { print $2 }' .tool-versions) && asdf install erlang ${erlang_version} ]
queue %[ elixir_version=$(awk '/elixir/ { print $2 }' .tool-versions) && asdf install elixir ${elixir_version} ]
queue %[ nodejs_version=$(awk '/nodejs/ { print $2 }' .tool-versions) && asdf install nodejs ${nodejs_version} ]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
queue %[mix local.hex --force]
queue %[mix local.rebar --force]
queue %[mix deps.get --production]
queue %[npm install]
queue %[$(npm bin)/bower install]
queue %[$(npm bin)/brunch build --production]
queue %[mix phoenix.digest]
queue %[mix do compile, release]
queue %[mix ecto.migrate]
#queue %[mix run sitemaps.exs]
to :launch do
invoke :'elixir:stop'
invoke :'elixir:start'
end
to :clean do
queue 'echo "Failed deployment"'
end
end
end
namespace :elixir do
desc "start"
task :start do
queue "echo 'Elixir #{cmd}'"
queue "cd #{deploy_to}/#{current_path}/rel/#{app_name}/bin && ./#{app_name} start"
end
desc "stop"
task :stop do
queue "echo 'Elixir stop'"
queue "cd #{deploy_to}/#{current_path}/rel/#{app_name}/bin && ./#{app_name} stop"
end
desc "restart"
task :restart do
queue "echo 'Elixir restart'"
queue "cd #{deploy_to}/#{current_path}/rel/#{app_name}/bin && ./#{app_name} restart"
end
desc "ping"
task :ping do
queue "echo 'Elixir ping'"
queue "cd #{deploy_to}/#{current_path}/rel/#{app_name}/bin && ./#{app_name} ping"
end
end
desc "Show logs"
task :logs do
queue 'echo "Contents of the log file are as follows:"'
queue "tail -n 100 -f `/bin/ls -1td #{log_path}/*| /usr/bin/head -n1`"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment