Created
October 5, 2017 11:07
-
-
Save satchinjoshi/22e2ede784b9e867c65674b0513e9f05 to your computer and use it in GitHub Desktop.
mina multi stage deploy
This file contains hidden or 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 'time' | |
| require 'mina/rails' | |
| require 'mina/git' | |
| require 'mina/rbenv' # for rbenv support. (https://rbenv.org) | |
| set :application_name, 'ug' | |
| set :repository, 'git@bitbucket.org:xxx/xxx.git' | |
| set :branch, ENV['BRANCH'] || 'master' | |
| set :build_assets, ENV['ASSETS'] || 'no' | |
| task :staging do | |
| set :domain, 'xxxxxxx' | |
| set :deploy_to, '/home/ubuntu/staging/urbangirl' | |
| set :rails_env, 'staging' | |
| end | |
| task :production do | |
| set :domain, '52.77.43.87' | |
| set :deploy_to, '/home/ubuntu/production/urbangirl' | |
| set :rails_env, 'production' | |
| end | |
| # Optional settings: | |
| set :user, 'ubuntu' # 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('uploads', 'tmp/pids', 'tmp/sockets') | |
| set :shared_files, fetch(:shared_files, []).push('.env') | |
| # 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' | |
| 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/bin/rbenv install 2.4.1} | |
| end | |
| desc 'Deploys the current version to the server.' | |
| task :deploy do | |
| # invoke :'git:ensure_pushed' | |
| deploy do | |
| invoke :'git:clone' | |
| invoke :'deploy:link_shared_paths' | |
| invoke :'bundle:install' | |
| invoke :'assets:copy_assets_from_s3' | |
| if fetch(:build_assets) == 'yes' | |
| invoke :'assets:yarn' | |
| invoke :'assets:webpacker_compile' | |
| end | |
| invoke :'rails:db_migrate' | |
| invoke :'app:deploy_info' | |
| invoke :'deploy:cleanup' | |
| on :launch do | |
| invoke :'ops:restart_sidekiq' | |
| invoke :'notify:slack' | |
| in_path(fetch(:current_path)) do | |
| command %{mkdir -p tmp/} | |
| command %{touch tmp/restart.txt} | |
| comment '-------------- restart passenger -----------' | |
| 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 | |
| namespace :assets do | |
| task :copy_assets_from_s3 do | |
| comment '-------- copying asset from s3 ----------' | |
| command %{REVISION=`cat #{fetch(:current_path)}/.mina_git_revision`} | |
| command %{FILES_COUNT=`aws s3 ls s3://ug-assets/$REVISION/ | wc -l`} | |
| # if file_count.to_i == 0 | |
| # command "exit 1" | |
| # end | |
| command "aws s3 sync s3://ug-assets/$REVISION/ #{fetch(:shared_path)}/public/assets/" | |
| end | |
| task :yarn do | |
| comment '-------- installing assets depedencies ----------' | |
| command 'yarn install --no-progress' | |
| end | |
| task :webpacker_compile do | |
| comment '-------- running webpacker ------' | |
| command "bundle exec rails webpacker:compile RAILS_ENV=#{fetch(:rails_env)}" | |
| end | |
| task :clean_old_files do | |
| command "find #{fetch(:shared_path)}/public/assets/* -type f -ctime +10 | xargs rm" | |
| end | |
| end | |
| namespace :app do | |
| task :deploy_info do | |
| comment '--------- adds deploy info ---------' | |
| release_file = 'public/v.txt' | |
| command %{REVISION=`cat #{fetch(:current_path)}/.mina_git_revision`} | |
| command "touch #{release_file} | |
| echo 'Date:' #{Time.now.iso8601.to_s} >> #{release_file} | |
| echo 'Branch:' #{fetch(:branch)} >> #{release_file} | |
| echo 'Revision:' $REVISION >> #{release_file} | |
| echo 'Deployed By:' #{fetch(:user)} >> #{release_file}" | |
| end | |
| end | |
| namespace :ops do | |
| task :restart_sidekiq do | |
| comment '--------- restart sidekiq ---------' | |
| command %{sudo systemctl restart sidekiq} | |
| end | |
| end | |
| namespace :notify do | |
| task :slack do | |
| command %{} | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment