【问题标题】:chef. how to set/use local_settings in application_python 4.0 cookbook?厨师。如何在 application_python 4.0 食谱中设置/使用 local_settings?
【发布时间】:2015-11-09 01:02:53
【问题描述】:

我正在使用application_python v4.0 食谱,大部分成功, 但在 local_settings 生成时遇到了一些障碍。

基本上,我想更改 settings.py.erb 的内容 正在使用。

这是食谱的 berkshelf 源位置:

.berkshelf/cookbooks/application_python-4.0.0/templates/settings.py.erb

我在自己的食谱上添加了修改后的 settings.py.erb,但它是 没有被拿起,默认的 .berkshelf 文件总是 用过。

myrepo/cookbooks/basedjango/templates/settings.py.erb

然后我阅读了 local_settings 属性并认为我会 将其修改为指向重命名的文件 settings2.py.erb 。最初,我的想法只是跟踪它将在哪些模板目录中搜索。但从未设法修改 local_settings。

这些是我尝试的各种调整,导致错误 大多数情况。

# local_settings 'foo' do
#   source 'settings2.py.erb'
# end
#   resulting error => undefined method `local_settings' for PoiseApplicationPython::Resources::Django::Resource

# local_settings do
#   source 'settings2.py.erb'
# end
#   resulting error => undefined method `local_settings' for PoiseApplicationPython::Resources::Django::Resource

# local_settings 'settings2.py.erb'
#                     undefined method `local_settings' for PoiseApplicationPython::Resources::Django::Resource

# file 'local_settings' do
#   source 'settings2.py.erb'
# end

问题:为什么我自己的食谱模板没有被提取和使用,而不是 berkshelf 版本?适用于其他食谱,不在这里。 如果做不到这一点,我该如何调整 local_settings?

Chef 开发套件版本:0.7.0 厨师客户端版本:12.4.1 伯克斯版本:3.2.4 厨房版:1.4.2

host mac osx guest ubuntu 14.04

【问题讨论】:

    标签: django chef-infra


    【解决方案1】:

    正确的语法是这样的:

    application "/var/www/myproj" do
      application_git do
        deploy_key repo_key
        repository repo_url
        revision repo_rev
      end
      virtualenv do
        path "/var/www/myproj/ve"
      end
      pip_requirements "/var/www/myproj/requirements/cpython2.txt"
      django do
        database "postgres://#{dbuser}:#{dbpassword}@#{dbserver}/#{dbname}"
        secret_key django_secret_key
        local_settings_source 'host_settings.py.erb'
        local_settings_options setting1: my_secret_1, setting2: my_secret_2
        local_settings_path "/var/www/myproj/settings/host_settings.py"
        migrate true
      end
    end
    

    应该创建一个名为“host_settings.py.erb”的模板(在这种情况下),如下所示:

    DEBUG = <%= PoisePython::Utils.to_python(@debug) %>
    
    <%- unless @allowed_hosts.empty? -%>
    ALLOWED_HOSTS = <%= PoisePython::Utils.to_python(@allowed_hosts) %>
    <%- end -%>
    
    # database connection information
    DATABASES = <%= PoisePython::Utils.to_python(@databases) %>
    
    # Django secret key
    <%- if @secret_key -%>
    SECRET_KEY = <%= PoisePython::Utils.to_python(@secret_key) %>
    <%- end -%>
    
    <%- if ! @setting1.to_s == '' -%>
    # Setting #1
    SECRET_1 = '<%= PoisePython::Utils.to_python(@setting1) %>'
    <%- end -%>
    
    <%- if ! @setting2.to_s == '' -%>
    # Setting #2
    SECRET_2 = '<%= PoisePython::Utils.to_python(@setting2) %>'
    <%- end -%>
    

    来源:https://github.com/poise/application_python/issues/59

    【讨论】:

    • txs 获取信息。我现在正在处理应用程序代码,而不是 Chef,我通过从头开始编写我的整个 settings.py 而不是使用 PoisePython 的东西来解决整个问题。大概几周后,当我回到 Chef 那里时,我会看看是否可以快速尝试您的建议。
    • 它应该可以工作 - 我已经在几个不同的部署中使用过它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 2018-07-05
    相关资源
    最近更新 更多