项目作者: DeployRB

项目描述 :
Simple Rails 5 deploy tool
高级语言: Ruby
项目地址: git://github.com/DeployRB/DeployTool.git
创建时间: 2016-09-18T11:04:10Z
项目社区:https://github.com/DeployRB/DeployTool

开源协议:MIT License

下载


Deploy.RB / Deploy Tool

This is a part of the Deploy.RB project.

Deploy.RB consists of:

  1. Rails 5 App
  2. Server Installation Script & Manual
  3. Deployment Tool (You are here)

Please, visit Deploy.RB page to get more information.

  1. ```
  2. # Deploy Tool
  3. Simple but effective Deploy Tool is written in Ruby in procedure-oriented style.
  4. This tool is a good choice for simple projects based on the just server and for education & demonstrative purposes.
  5. ## Deploy of an example project "Rails 5 App"
  6. <details>
  7. <summary>How to deploy Rails 5 App</summary>
  8. ### 1. Clone the Deploy Tool and install gems
  9. ```sh
  10. git clone https://github.com/DeployRB/DeployTool.git
  11. cd DeployTool
  12. gem install bundler
  13. bundle install

2. Copy templates & config files

  1. cp -Rv __ENV__/production.example __ENV__/production

3. Set up access parameters in server_access.yml config file

EDIT: __ENV__/production/__SETTINGS__/server_access.yml

4. Check and Edit important templates & config files

EDIT: __ENV__/production/__SETTINGS__/database.yml

EDIT: __ENV__/production/__SETTINGS__/deploy_params.yml

EDIT: __ENV__/production/__TEMPLATES__/settings/app.yml

5. Deploy!

  1. DEPLOY_ENV=production ruby deploy.rb

6. Edit NginX config file

Run command. This command will show you an address of NginX config files

  1. DEPLOY_ENV=production ruby deploy.rb nginx_info

Go to the server and edit:

  1. ssh root@257.123.45.67
  2. edit /etc/nginx/nginx.conf

Add the line with include PATH/TO/NGINX/CONFIG


See example image
pic

Save and Exit

7. Restart NginX

  1. DEPLOY_ENV=production ruby deploy.rb nginx_restart

8. Run rake task on the server

  1. DEPLOY_ENV=production ruby deploy.rb rake_task
  2. db:seed

9. Visit the App by IP or Domain name


See example image
pic

How does Deploy Tool work?

The Entry point of the project is method deploy! in file kit/rails/deploy.rb

Method deploy! looks like this:

  1. def deploy!
  2. startup_authorize_deployer
  3. startup_create_base_dirs
  4. startup_copy_ssh_files
  5. ...
  6. app_bundle
  7. app_database_create
  8. app_database_migrate
  9. app_assets_precompile
  10. link_current_release
  11. puma_restart
  12. release_cleanup
  13. end

To run this method you can use the following command:

  1. DEPLOY_ENV=production ruby deploy.rb deploy!

Method deploy! provides deployment process in procedure-like style. You will not find here after and before hooks. Everything is just a set of ruby methods. You can manage an order of an execution of the methods manually.

You can use binding.pry to stop a deployment process at any point if you want to check what specific method does.

This project uses really simple approaches and code base. You can learn how it works in minutes!

Project’s stucture

  1. ├── __ENV__
  2. ├── production
  3. ├── __SETTINGS__
  4. ├── database.yml
  5. ├── deploy_params.yml
  6. └── ssh_ssl.yml
  7. ├── __TEMPLATES__
  8. ├── database.yml
  9. ├── services/*
  10. ├── settings/*
  11. └── ssh_ssl/*
  12. ├── deploy.rb
  13. └── kit
  14. ├── base/*
  15. ├── common/*
  16. ├── custom/*
  17. ├── rails/*
  18. └── kit.rb
  • deploy.rb main entry point of Deploy Tool
  • __ENV__ Folder for keeping Settings snd Templates for a specific environment
  • __SETTINGS__ Settings for the Deploy Tool
  • __TEMPLATES__ Templates to configure external services (DB (database.yml), Redis, Sidekiq, Thinkig Sphinx, etc.)
  • kit folder with methods to provide a deployment process
  • kit/base common methods to provide a deployment process
  • kit/rails methods to provide a deployment process for Rails app

Execution of specific methods

To execute specific a method you can use the following way:

  1. DEPLOY_ENV=ENVIRONMENT ruby deploy.rb METHOD_NAME

where ENVIRONMENT is a name of a required environment (development by default)

where METHOD_NAME is a name of a required method to execute (deploy! by default)

Additional params

Deploy debugging

DEPLOY_DEBUG=true will run a method, but ssh calls will not be executed

Specific release directory

DEPLOY_DIR=DIRECTORY_NAME will run a method inside a specific release folder. The list of the folders of releases you will find in the file RELEASES.txt which will be created right after a first deploy.

This option can be helpful if you want to update the code of an existed release, but don’t want to re-deploy all the project.

  1. DEPLOY_ENV=production DEPLOY_DIR=2016-10-03--23-33-14--master ruby deploy.rb deploy_backend_changes!