2014-01-24 41 views
2

我想将一个django应用程序部署到远程服务器。在轨道他们capistrano,处理安装的依赖,宝石更新,更新的git,shell命令等什么是部署django应用程序的最简单最完整的解决方案?

是否有django建什么,是完整的,那么容易,因为capistrano使用?

注:我想你也可以使用capistranodjango,但有什么特别建成pythondjango

关闭?:许多人提出的解决方案是2010年问题。除非你们对解决方案有绝对的信心,否则请不要关闭这个问题。软件不断变化,始终存在创新。自2010年以来有没有新的/增加的解决方案?

+0

@gawel yea,我听说过面料。想知道自2010年以来是否还有其他问题出现,当时提出这个问题。 – Derek

+1

ansible&salt但织物仍然是最容易使用的 – gawel

+0

+1。例如,关闭的第二个部署将部署到Heroku或OpenShift,很难打败“git push heroku master”部署代码,但我想这取决于你部署的位置。 – iandouglas

回答

0

使用Fabric将django应用程序部署到远程服务器。 Fabric是一个Python库和命令行工具,用于简化应用程序部署或系统管理任务的SSH使用。您可以使用与Capistrano宝石相同的面料。看看这个实时代码。

from fabric.api import * 


def dev(): 
    env.user = "example" 
    env.hosts = ["example.com", ] 
    env.dev = True 
    env.prod = False 


def prod(): 
    env.user = "example" 
    env.hosts = ["192.68.1.23", ] 
    env.dev = False 
    env.prod = True 


def start_virtualenv(): 
    local("workon django_test") 

# Local developent 
def start_dev_server(): 
    local("python manage.py runserver_plus --settings django_test.settings.dev") 

def start_dev_server_z(): 
    local("python manage.py runserver_plus --settings django_test.settings.dev 0.0.0.0:9000") 

def start_dev_shell(): 
    local("python manage.py shell --settings django_test.settings.dev") 

def start_dev_dbshell(): 
    local("python manage.py dbshell --settings django_test.settings.dev") 

def run_dev_command(command_name=""): 
    """Run a command with the settings thing already setup""" 
    local("python manage.py %s --settings django_test.settings.dev" % command_name) 

# Remote serving 
def run_prod_command(command_name=""): 
    """ Just run this command on remote server """ 
    with cd("/srv/www/django_test/app/"): 
     with prefix("source /home/user/.virtualenvs/agn/bin/activate"): 
      run("python manage.py %s --settings django_test.settings.prod" % command_name) 

def restart_prod_server(): 
    """ Start a gunicorn instance using the supervisor daemon from the server """ 
    run("sudo supervisorctl restart django_test") 

# Deploy and shit 
def deploy(commit="true"): 
    """ 
    TODO: there is sure a better way to set that prefix thing 
    """ 
    if commit == "true": 
     local("git add .") 
     local("git commit -a") 
     local("git push") 

    with cd("/srv/www/agn/app"): 
     run("git pull") 

    if env.dev: 
     account_name = 'exampledev' 
    else: 
     account_name = 'user' 
    prefix_string = 'source /home/%s/.virtualenvs/django_test/bin/activate' % account_name 

    with cd("/srv/www/django_test/app/requirements"): 
     with prefix(prefix_string): 
      run("pip install -r prod.txt") 

    with cd("/srv/www/django_test/app"): 
     with prefix(prefix_string): 
      run("python manage.py migrate --settings django_test.settings.prod") 
      run("python manage.py collectstatic --settings django_test.settings.prod --noinput") 

    restart_prod_server() 
相关问题