远程部署python程序

发布时间:2019-06-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了远程部署python程序脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

接着上一篇管理python程序的db schema, 本篇介绍远程部署到指定环境(PRod or staging).
使用的技Capistrano.

环境准备

Clone Template

使用下面的命名获得模版,里面有准备好的各个config以及基本bin包。

gIT clone https://github.COM/flying-bird/python-db-schema

Install Package

cd python-db-schema
bundle install

Change Config

@H_777_50@Update config/deploy/production.rb

default config in python-db-schema/config/deploy/production.rb:

➜  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定制成你需要的参数就好。

Update config/deploy.rb

➜  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定制成你需要的参数就好。

Deploy

你可以在本地使用下面的command,将code部署到production环境。

cap production deploy

在上述命令运行成功之后,登录到prouction env上check下目录结构,如下所示:

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

Migrate DB Schema

将code部署到production之后,apply db schema到production环境。

更新config/database.yML

只要将username/password/database改成特定值就好,笔者的配置如下:

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

Apply Schema in Production Env

rake db:migrate RaiLS_ENV=production

输出结果如下:

== 20170405024951 CreatePipelineTable: migrating ==============================
-- create_table(:d_pipeline)
   -> 0.0355s
== 20170405024951 CreatePipelineTable: migrated (0.0356s) =====================

脚本宝典总结

以上是脚本宝典为你收集整理的远程部署python程序全部内容,希望文章能够帮你解决远程部署python程序所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。