【问题标题】:OpsWorks Django DeploymentOpsWorks Django 部署
【发布时间】:2015-02-21 22:02:51
【问题描述】:

我正在尝试使用 AWS OpsWorks 部署 Django 应用程序。我对任何类型的 DevOps 工作都是全新的,所以我遇到了相当大的困难。

我正在尝试使用this cookbook 来自动化我的部署。我需要Python3.4,所以我修改了cookbook中的一些内容。现在在部署挂钩期间,我收到以下代码的错误:

    # install requirements
  requirements = Helpers.django_setting(deploy, 'requirements', node)
  if requirements
    Chef::Log.info("Installing using requirements file: #{requirements}")
    pip_cmd = ::File.join(deploy["venv"], 'bin', 'pip')
    execute "#{pip_cmd} install --source=#{Dir.tmpdir} -r #{::File.join(deploy[:deploy_to], 'current', requirements)}" do
      cwd ::File.join(deploy[:deploy_to], 'current')
      user deploy[:user]
      group deploy[:group]
      environment 'HOME' => ::File.join(deploy[:deploy_to], 'shared')
    end
  else
    Chef::Log.debug("No requirements file found")
  end

错误报告:

STDERR: /opt/aws/opsworks/releases/20141216163306_33300020141216163306/vendor/bundle/ruby/2.0.0/gems/mixlib-shellout-1.4.0/lib/mixlib/shellout/unix.rb:147:in `chdir': No such file or directory - /srv/www/django/current (Errno::ENOENT)

我知道这段代码试图从我的 requirements.txt 文件中安装需求,但是 tmp 目录和 current 目录是怎么回事?显然,在我进行部署时没有创建 current 目录。从部署中将代码拉入 OpsWorks 的文件结构通常是什么样的?此外,我该如何解决这个错误?

几天来,我一直在阅读有关 Chef、OpsWorks、KitchenCI、Berksfile 和其他技术的文档,感觉被 DevOps 世界中的一切所淹没。我只想让我的应用程序运行!

编辑

自定义json是:

{
    "deploy" : { 
        "django" : {
            "django_settings_template" : null,
            "django_settings_file" : "settings.py",
            "django_collect_static" : "true",
            "python_major_version" : "3.4",
            "venv_options" : "--python=$(which python3.4) --no-site-packages",
        "custom_type" : "django"
        }
    }
}

【问题讨论】:

    标签: django amazon-web-services deployment chef-infra aws-opsworks


    【解决方案1】:

    如果没有当前目录,那是因为它不是在部署期间创建的。您的脚本实际上确实引用了该目录。

    下面的这段代码是您遇到错误的地方。如果您参考有关执行资源块https://docs.chef.io/resource_execute.html 的文档,您会看到如果您不向执行资源提供命令,那么块的名称将是执行的命令。因此,在您的情况下,您正在通过 Ruby 的 file.join 生成 pip 命令的路径,因此 pip_cmd 应该类似于 /usr/bin/pip ,然后块的名称就是命令应该类似于

    #Mind you I'm not sure if the /tmp dir is correct, but if not it might also be the chef tmp directory
    /usr/bin/pip install --source=/tmp -r /srv/www/django/current/requirements
    

    现在在资源中有 cwd 属性,即“当前工作目录”或执行命令的目录。因此,当执行此命令时,它正在 /srv/www/django/current 中执行

    pip_cmd = ::File.join(deploy["venv"], 'bin', 'pip')
    execute "#{pip_cmd} install --source=#{Dir.tmpdir} -r #{::File.join(deploy[:deploy_to], 'current', requirements)}" do
      cwd ::File.join(deploy[:deploy_to], 'current')
      user deploy[:user]
      group deploy[:group]
      environment 'HOME' => ::File.join(deploy[:deploy_to], 'shared')
    end
    

    现在,在不了解您的部署的情况下,如果不了解有关您的部署的更多信息,我无法真正告诉您如何修复它。您能否发布您的实际说明书代码,以便我们了解您如何使用此说明书来部署您的代码?

    {
      'deploy': {
        'django': {
                           'repository': 'Your github URL',
                           'revision': 'your revision number'
                           },
                   }
    }
    

    【讨论】:

    • 在进行更多挖掘之后,我的代码似乎没有部署到 SCM。我正在使用的食谱可以在这个 repo 中找到:github.com/alecpm/opsworks-web-python/tree/master/… 我在python_base_deploy.rbdefinition 的第 196 行收到一条消息,表明没有设置 scm 存储库……但是,我正在为我的OpsWorks 控制台中的应用程序,并且 deploy[:my_app][:scm] 设置正确。
    • @rfj001 那么您的部署设置看起来像 github 页面上的使用示例吗?可以发一下吗?
    • 您的意思是我要发送到堆栈的自定义部署 JSON?
    • 是的,github.com/alecpm/opsworks-web-python/tree/master/… 底部表示的 JSON,您使用的是正确的吗?
    • 您在其中缺少您的 SCM 信息。请参阅 github 页面底部的示例以获取确切的键,但如果您不确定我的意思,我会编辑我的帖子为您添加它。
    猜你喜欢
    • 2017-08-16
    • 2016-09-26
    • 2014-11-18
    • 1970-01-01
    • 2014-05-25
    • 2015-03-20
    • 2015-03-18
    • 2016-05-22
    • 2013-08-07
    相关资源
    最近更新 更多