接着上一篇管理python程序的db schema, 本篇介绍远程部署到指定环境(prod or staging).
使用的技术是Capistrano.python
使用下面的命名得到模版,里面有准备好的各个config以及基本bin包。mysql
git clone https://github.com/flying-bird/python-db-schema
cd python-db-schema bundle install
default config in python-db-schema/config/deploy/production.rb:git
➜ python-db-schema git:(master) less config/deploy/production.rb # Simple Role Syntax # ================== # Supports bulk-adding hosts to roles, the primary server in each group # is considered to be the first unless any hosts have the primary # property set. Don't declare `role :all`, it's a meta role. role :app, %w{your_name@prod_env_ip_or_host} role :web, %w{your_name@prod_env_ip_or_host} role :db, %w{your_name@prod_env_ip_or_host}
将上面的config的your_name和prod_env_ip_or_host定制成你须要的参数就好。github
➜ python-db-schema git:(master) less config/deploy.rb set :application, 'python-db-schema' set :repo_url, 'https://github.com/flying-bird/python-db-schema' set :branch, "master" set :user, "your_account" set :deploy_via, :copy set :linked_dirs, %w{log} set :deploy_to, '/tmp/your_deploy_path'
将上面的config的your_account,your_deploy_path和repo_url定制成你须要的参数就好。web
你能够在本地使用下面的command,将code部署到production环境。sql
cap production deploy
在上述命令运行成功以后,登陆到prouction env上check下目录结构,以下所示:segmentfault
your_account@production_host: ls /tmp/python-db-schema current git-ssh.sh releases repo revisions.log shared your_account@production_host: ls /tmp/python-db-schema/current Gemfile Gemfile.lock README.md REVISION Rakefile bin config log src
将code部署到production以后,apply db schema到production环境。api
只要将username/password/database改为特定值就好,笔者的配置以下:app
staging: adapter: mysql2 encoding: utf8 pool: 20 username: mysql password: 123456 socket: /var/lib/mysql/mysql.sock host: 192.168.10.111 port: 3306 database: dashboard_test production: adapter: mysql2 encoding: utf8 pool: 20 username: mysql password: 123456 socket: /var/lib/mysql/mysql.sock host: 192.168.10.222 port: 3306 database: dashboard_production
rake db:migrate RAILS_ENV=production
输出结果以下:less
== 20170405024951 CreatePipelineTable: migrating ============================== -- create_table(:d_pipeline) -> 0.0355s == 20170405024951 CreatePipelineTable: migrated (0.0356s) =====================