Created
October 12, 2017 20:43
-
-
Save gilcierweb/75fafeaf72e28e2f69db18bba19609f2 to your computer and use it in GitHub Desktop.
Mina deploy ruby on rails 5.1 ++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mina/rails' | |
require 'mina/git' | |
require 'mina/rbenv' # for rbenv support. (https://rbenv.org) | |
# require 'mina/rvm' # for rvm support. (https://rvm.io) | |
set :application_name, 'my_app' | |
set :domain, 'my_server' | |
set :deploy_to, '/home/rails/my_app' | |
set :repository, '[email protected]:my_user/my_app.git' | |
set :branch, 'master' | |
set :rails_env, 'production' | |
# set :rails_env, 'development' | |
set :user, "deployer" | |
set :forward_agent, true | |
set :bundle_gemfile, "Gemfile" | |
desc "Deploys the current version to the server." | |
# shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step. | |
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'node_modules') | |
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml') | |
# This task is the environment that is loaded for all remote run commands, such as | |
# `mina deploy` or `mina rake`. | |
task :environment do | |
# If you're using rbenv, use this to load the rbenv environment. | |
# Be sure to commit your .ruby-version or .rbenv-version to your repository. | |
# invoke :'rbenv:load' | |
# For those using RVM, use this to load an RVM version@gemset. | |
# invoke :'rvm:use', 'ruby-1.9.3-p125@default' | |
# queue! %[mkdir -p "#{deploy_to}/shared/log"] | |
# queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"] | |
# | |
# queue! %[mkdir -p "#{deploy_to}/shared/config"] | |
# queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"] | |
# | |
# queue! %[touch "#{deploy_to}/shared/config/database.yml"] | |
# queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."] | |
end | |
# rbenv_path = "$HOME/.rbenv" | |
set :rbenv_path, "/root/.rbenv" | |
task :'rbenv:load' do | |
comment %{Loading rbenv} | |
command %{export RBENV_ROOT="#{fetch(:rbenv_path)}"} | |
command %{export PATH="#{fetch(:rbenv_path)}/bin:$PATH"} | |
command %{ | |
if ! which rbenv >/dev/null; then | |
echo "! rbenv not found" | |
echo "! If rbenv is installed, check your :rbenv_path setting." | |
exit 1 | |
fi | |
} | |
command %{eval "$(rbenv init -)"} | |
end | |
# Put any custom commands you need to run at setup | |
# All paths in `shared_dirs` and `shared_paths` will be created on their own. | |
task :setup do | |
# command %{rbenv install 2.3.0} | |
command %[touch "#{fetch(:shared_path)}/config/database.yml"] | |
command %[touch "#{fetch(:shared_path)}/config/secrets.yml"] | |
command %[mkdir -p "#{fetch(:shared_path)}/node_modules"] | |
# command %[touch "#{fetch(:shared_path)}/config/puma.rb"] | |
comment "Be sure to edit '#{fetch(:shared_path)}/config/database.yml', 'secrets.yml' and puma.rb." | |
end | |
desc "Deploys the current version to the server." | |
task :deploy do | |
# uncomment this line to make sure you pushed your local branch to the remote origin | |
# invoke :'git:ensure_pushed' | |
deploy do | |
# Put things that will set up an empty directory into a fully set-up | |
# instance of your project. | |
comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}" | |
invoke :'git:clone' | |
invoke :'deploy:link_shared_paths' | |
invoke :'rbenv:load' | |
invoke :'bundle:install' | |
invoke :'rails:db_migrate' | |
# command %{bundle exec rails webpacker:install} | |
# command %{bundle exec rails webpacker:check_yarn} | |
# command %{bundle exec rails webpacker:install:vue} | |
# command %{bundle exec bin/rails app:update:bin} | |
# command %{sudo mkdir node_modules} | |
# command %{sudo chmod 777 -R node_modules} | |
# command %{sudo npm install -g yarn} | |
# command %{yarn install} | |
# command %{cd #{fetch(:releases_path)} && yarn install} | |
command %{#{fetch(:rails)} webpacker:install:vue} | |
# command %{#{fetch(:rails)} webpacker:check_yarn} | |
# command %{NODE_ENV=production RAILS_ENV=production rails assets:precompile --trace} | |
# command %{NODE_ENV=production RAILS_ENV=production bundle exec rails webpacker:compile} | |
command %{sudo chmod 777 -R tmp/} | |
command %{sudo chown -R deployer:deployers tmp/} | |
# command %{NODE_ENV=production bundle exec rails webpacker:compile} | |
# command %{bundle exec rails webpacker:install} | |
# command %{NODE_ENV=production} | |
invoke :'rails:assets_precompile' | |
invoke :'deploy:cleanup' | |
on :launch do | |
in_path(fetch(:current_path)) do | |
command %{mkdir -p tmp/} | |
command %{chown -R deployer:deployers tmp/} | |
command %{chmod 777 -R tmp/} | |
# command %{touch tmp/restart.txt} | |
end | |
end | |
end | |
# you can use `run :local` to run tasks on local machine before of after the deploy scripts | |
# run(:local){ say 'done' } | |
end | |
=begin | |
# For help in making your deploy script, see the Mina documentation: | |
# | |
# - https://github.com/mina-deploy/mina/tree/master/docs | |
require 'mina/rails' | |
require 'mina/git' | |
require 'mina/rbenv' # for rbenv support. (https://rbenv.org) | |
# Basic settings: | |
# domain - The hostname to SSH to. | |
# deploy_to - Path to deploy into. | |
# repository - Git repo to clone from. (needed by mina/git) | |
# branch - Branch name to deploy. (needed by mina/git) | |
set :application_name, 'rails-demo' | |
set :domain, 'example.com' | |
set :user, fetch(:application_name) | |
set :deploy_to, "/home/#{fetch(:user)}/app" | |
set :repository, '[email protected]:example/rails-demo.git' | |
set :branch, 'master' | |
set :rvm_use_path, '/etc/profile.d/rvm.sh' | |
# Optional settings: | |
# set :user, 'foobar' # Username in the server to SSH to. | |
# set :port, '30000' # SSH port number. | |
# set :forward_agent, true # SSH forward_agent. | |
# shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step. | |
# set :shared_dirs, fetch(:shared_dirs, []).push('somedir') | |
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml') | |
# This task is the environment that is loaded for all remote run commands, such as | |
# `mina deploy` or `mina rake`. | |
task :environment do | |
ruby_version = File.read('.ruby-version').strip | |
raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty? | |
invoke :'rvm:use', ruby_version | |
end | |
task :setup do | |
in_path(fetch(:shared_path)) do | |
command %[mkdir -p config] | |
# Create database.yml for Postgres if it doesn't exist | |
path_database_yml = "config/database.yml" | |
database_yml = %[production: | |
database: #{fetch(:user)} | |
adapter: postgresql | |
pool: 5 | |
timeout: 5000] | |
command %[test -e #{path_database_yml} || echo "#{database_yml}" > #{path_database_yml}] | |
# Create secrets.yml if it doesn't exist | |
path_secrets_yml = "config/secrets.yml" | |
secrets_yml = %[production:\n secret_key_base:\n #{`rake secret`.strip}] | |
command %[test -e #{path_secrets_yml} || echo "#{secrets_yml}" > #{path_secrets_yml}] | |
# Remove others-permission for config directory | |
command %[chmod -R o-rwx config] | |
end | |
end | |
desc "Deploys the current version to the server." | |
task :deploy do | |
# uncomment this line to make sure you pushed your local branch to the remote origin | |
# invoke :'git:ensure_pushed' | |
deploy do | |
# Put things that will set up an empty directory into a fully set-up | |
# instance of your project. | |
invoke :'git:clone' | |
invoke :'deploy:link_shared_paths' | |
invoke :'bundle:install' | |
invoke :'rails:db_migrate' | |
invoke :'rails:assets_precompile' | |
invoke :'deploy:cleanup' | |
on :launch do | |
# command "sudo service #{fetch(:user)} restart" | |
end | |
end | |
# you can use `run :local` to run tasks on local machine before of after the deploy scripts | |
# run(:local){ say 'done' } | |
end | |
# For help in making your deploy script, see the Mina documentation: | |
# | |
# - https://github.com/mina-deploy/mina/tree/master/docs | |
# mina setup --verbose | |
# mina deploy --verbose | |
# mina deploy:force_unlock --verbose | |
# mina rollback --verbose | |
# mina "rake[db:seed]" | |
# mina console | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment