简体   繁体   中英

Fabric and Django deployment scenario

My deployment scenario involves a typical Django setup, but runs on multiple servers. Basically, I upload the source code, perform several build steps (compile .pyc files, collectstatic, etc.), then rung syncdb and migrate , finally reload apache2.

My problem is that I deploy the code to 4-5 servers with more planned in the future and the deploy takes a long time (more than a minute per server). Almost all the steps in the deploy process can be done in parallel, except syncdb/migrate. Is there a way using Fabric to only run those on one of the machines (the DB server is separate from the rest), and run the rest of the tasks in parallel?

Have you tried create a function for each task and another task to call them all?

Example:

@task
@parallel
copy_files():
    run('cp *')
    ...

@task
@parallel
restart_apache():
    run('/etc/init.d/httpd restart')
    ...

@task
syncdb_app():
    run('python manage.py syncdb')
    ...

@task
deploy():
    copy_files()
    restart_apache()
    syncdb_app()
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM