V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
banxi1988
V2EX  ›  Python

Hi,你的发布脚本是怎么样的?

  •  
  •   banxi1988 ·
    banxi1988 · 2015-09-15 08:04:37 +08:00 · 4994 次点击
    这是一个创建于 3155 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我昨天写了个简单的发布脚本。

    #!/bin/bash
    git pull
    dest_tar='cool_project.tar.gz'
    dest_dir='/var/www/'
    tar zcf $dest_tar cool_project requirements.txt  app.py
    echo 'tar done'
    cp $dest_tar $dest_dir
    (cd $dest_dir;tar zxf $dest_tar )
    echo 'untar done'
    rm $dest_tar
    supervisorctl restart cool_project
    

    以前的发布脚本工作主要是由 fabric 完成的。
    但是使用 fabric 上传整个项目太慢了。
    现在改成在服务器 clone 项目,然后再更新发布,虽然也算有一点改进。
    但是我感觉还是很 ugly.

    求吐槽,求指点。

    23 条回复    2015-09-16 07:24:33 +08:00
    workwonder
        1
    workwonder  
       2015-09-15 08:25:24 +08:00 via Android   ❤️ 1
    步骤很多余。
    我们直接 rsync 增量同步,秒级发布到阿里云。
    noahzh
        2
    noahzh  
       2015-09-15 08:43:09 +08:00   ❤️ 1
    为什么不用 ansible?
    kongkongyzt
        3
    kongkongyzt  
       2015-09-15 08:44:03 +08:00   ❤️ 1
    github/oschina 上面创建私人 repo

    配置 git hook 和 server ssh 和 Server 的接口

    每次 git push 触发 git hook,git hook 请求 Server 的接口

    接口执行 git pull,重启服务器

    部署结束
    TangMonk
        4
    TangMonk  
       2015-09-15 08:48:14 +08:00
    git-deploy 去看看
    kikyous
        5
    kikyous  
       2015-09-15 08:55:15 +08:00   ❤️ 1
    require 'mina/git'
    # 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 :user, 'deploy'
    set :domain, 'antesky.com'
    set :deploy_to, '/home/deploy/www/AceAttorney'
    set :repository, '[email protected]:plamed/AceAttorney.git'
    set :branch, 'master'

    set :shared_paths, ['.env', 'storage', 'vendor', 'node_modules', 'public/uploads']

    task :environment do
    end

    # Put any custom mkdir's in here for when `mina setup` is ran.
    # For Rails apps, we'll make some of the shared paths that are shared between
    # all releases.
    task :setup => :environment do
    end

    desc "Deploys the current version to the server."
    task :deploy => :environment do
    to :before_hook do
    # Put things to run locally before ssh
    end
    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'

    queue 'composer install'
    queue 'php artisan migrate'
    queue 'php artisan optimize'
    queue 'npm install'
    queue 'gulp --production'

    invoke :'deploy:cleanup'
    to :launch do
    queue 'composer dumpautoload'
    end
    end
    end
    kikyous
        6
    kikyous  
       2015-09-15 08:56:18 +08:00   ❤️ 1
    rails 项目和 laravel 项目我都用 mina 部署,很方便
    bcxx
        7
    bcxx  
       2015-09-15 09:04:45 +08:00   ❤️ 2
    https://github.com/bcho/flaskr/blob/master/fabfile.py 目前在用的 fabric 脚本,使用 platter 来打包依赖
    r00tt
        8
    r00tt  
       2015-09-15 09:47:27 +08:00   ❤️ 1
    我用 capistrano 简直就是一键,配置好之后 cap production deploy 直接去 git 拉取代码,部署,还可以保留版本,回滚,同时亦可以部署到集群上
    zhicheng
        9
    zhicheng  
       2015-09-15 10:00:12 +08:00 via Android
    fabfile 路过下。
    Theo14
        10
    Theo14  
       2015-09-15 10:06:15 +08:00   ❤️ 1
    rundeck ,你值得拥有
    9hills
        11
    9hills  
       2015-09-15 10:10:01 +08:00
    fabric 也可以做到你这个啊。。
    maemual
        12
    maemual  
       2015-09-15 10:18:07 +08:00
    目测是你的 fabric 用的不对,你写的 fabric 都能做。
    shawshank
        13
    shawshank  
       2015-09-15 11:08:27 +08:00
    用 saltstack 管理,一条命令把代码推到所有机器然后重启。在每台机器上都用 git ,感觉速度受网络影响很大。
    WildCat
        14
    WildCat  
       2015-09-15 11:11:20 +08:00 via iPhone
    Docker 党何在?
    WKPlus
        15
    WKPlus  
       2015-09-15 12:27:52 +08:00
    有个疑问,为啥需要先打包再解包?
    suckMyballs
        16
    suckMyballs  
       2015-09-15 13:02:12 +08:00
    @kongkongyzt git pull 完为什么要重启服务器
    cosmosz
        17
    cosmosz  
       2015-09-15 13:05:29 +08:00
    capistrano RoR
    crazyxin1988
        18
    crazyxin1988  
       2015-09-15 13:05:47 +08:00
    用 fabric 直接拉 git 的代码 不行么
    为啥要打包啊
    gaitana
        19
    gaitana  
       2015-09-15 13:06:32 +08:00
    还用啥 github ,直接 git push 到服务器
    kongkongyzt
        20
    kongkongyzt  
       2015-09-15 13:57:07 +08:00 via Android
    @suckMyballs 手快打错了-_-||不是重启服务器
    ChoateYao
        21
    ChoateYao  
       2015-09-15 14:55:49 +08:00
    #!/bin/bash
    r=''
    s=''
    path='/data/web/aaa'
    d='/data/release/bbbb'
    m=''
    command='svn log -v'
    publish=''
    if [[ ! $* ]]
    then
    echo '输入 bbb-commit -h 来查看帮助'
    exit
    fi
    while getopts ":r:s:Pm:p:hd:l:" opt;
    do
    case $opt in
    r )
    r=$OPTARG
    ;;
    s )
    s=$OPTARG
    ;;
    P )
    publish=true
    ;;
    p )
    path=$OPTARG
    ;;
    m )
    m=$OPTARG
    ;;
    d )
    d=$OPTARG
    ;;
    l )
    l=$OPTARG
    ;;
    h )
    echo -e " -m 发布时需要的注释\n -p 搜索路径\n -P 发布\n -d 提交版本>库路径\n -s 搜索\n -r 版本或日期参照 svn log -r\n -l 条数"
    exit
    ;;
    ?)
    echo '输入 bbb-commit -h 来查看帮助'
    exit
    ;;
    esac
    done
    if [ $r ]
    then
    command="${command} -r${r}"
    fi
    if [[ $s ]]
    then
    command="${command} --search \"${s}\""
    fi
    if [ $l ]
    then
    command="${command} -l${l}"
    fi

    if [ $publish ]
    then
    if [[ $m ]]
    then
    command="${command} ${path} | grep '[AM] ' | awk -v path=${d} '{print path substr (\$2, 1 )}'"
    eval "svn ci \`${command}\` -m\"${m}\""
    else
    echo 'Error Options -m'
    fi
    else
    eval $command ${path}
    fi
    vivisidea
        22
    vivisidea  
       2015-09-15 22:15:45 +08:00
    我们厂自己做了一套自动部署平台, push 代码上去点点就发布完了。。
    metrue
        23
    metrue  
       2015-09-16 07:24:33 +08:00 via iPhone
    capistrano 即可,一键方便快捷。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2446 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:04 · PVG 18:04 · LAX 03:04 · JFK 06:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.