简体   繁体   English

OpsWorks厨师将自定义json部署到php

[英]OpsWorks chef deploy custom json to php

I'm trying to pass sensitive app config data to instances when they get deployed, like db connection info. 我正在尝试在部署实例时将敏感的应用程序配置数据传递给实例,例如数据库连接信息。

Heres the custom stack json string 继承自定义堆栈json字符串

{
  "deploy": {
    "development": {
      "app" : {
        "api_key" : "data",
        "api_secret" : "data",
        "gmail_account" : "data",
        "gmail_account_password" : "data"
      },
      "database" : {
        "db_hostname" : "data",
        "db_username" : "data",
        "db_password" : "data",
        "db_database" : "data"
      }
    }
  }
}

I have my repo setup like this 我有这样的回购设置

recipes/appsetup.rb 配方/appsetup.rb

node[:deploy].each do |application, config|
  template "#{deploy[:deploy_to]}/current/config.php" do
    source "config.php.erb"
    mode 0660
    group deploy[:group]

    if platform?("ubuntu")
      owner "www-data"
    elsif platform?("amazon")   
      owner "apache"
    end

    variables(
      :api_key    => (deploy[:app][:api_key] rescue nil),
      :api_secret => (deploy[:app][:api_secret] rescue nil),
      :gmail_account          => (deploy[:app][:gmail_account] rescue nil),
      :gmail_account_password => (deploy[:app][:gmail_account_password] rescue nil),
      :db_hostname => (deploy[:database][:db_hostname] rescue nil),
      :db_username => (deploy[:database][:db_username] rescue nil),
      :db_password => (deploy[:database][:db_password] rescue nil),
      :db_database => (deploy[:database][:db_database] rescue nil)
    )
  end
end

and then the php template at templates/default/config.php.erb 然后是位于template / default / config.php.erb的php模板

$config = array();
$config['api_key'] = '<%= @api_key%>';
$config['api_secret'] = '<%= @api_secret%>';
$config['gmail_account'] = '<%= @gmail_account%>';
$config['gmail_account_password'] = '<%= @gmail_account_password%>';

$db = array();
$db['default']['hostname'] = '<%= @db_hostname%>';
$db['default']['username'] = '<%= @db_username%>';
$db['default']['password'] = '<%= @db_password%>';
$db['default']['database'] = '<%= @db_database%>';

What would I put under Custom Chef Recipes Deploy? 我将在“自定义厨师食谱部署”下放什么? I have tried lots of things but I can't seem to get my recipe loaded. 我已经尝试了很多东西,但似乎无法加载食谱。

Your repo setup appears to be configured to contain a single cookbook. 您的存储库设置似乎已配置为包含一个食谱。 OpsWorks requires your Custom Cookbooks Repository to contain a collection of cookbooks. OpsWorks要求您的“自定义食谱”存储库包含一系列食谱。

Have a look at the official AWS OpsWorks Cookbooks folder structure: https://github.com/aws/opsworks-cookbooks 查看官方的AWS OpsWorks Cookbooks文件夹结构: https : //github.com/aws/opsworks-cookbooks

In your case: 在您的情况下:

  1. Create a new folder inside your repo and give a name that describes the recipes functionality. 在您的仓库中创建一个新文件夹,并提供一个描述配方功能的名称。 In this example, we'll call the folder 'php_app_config'. 在此示例中,我们将文件夹称为“ php_app_config”。
  2. Move your recipes and templates into this folder, resulting in the following paths from the base of your repo: 将您的配方和模板移到该文件夹​​中,从而从存储库的底部获得以下路径:
    • php_app_config/recipes/appsetup.rb php_app_config / recipes / appsetup.rb
    • php_app_config/templates/default/config.php.erb php_app_config / templates / default / config.php.erb
  3. Commit your changes to your remote repository and instruct your existing OpsWorks instances to download the latest custom cookbooks . 将更改提交到远程存储库,并指示现有的OpsWorks实例下载最新的自定义食谱
  4. In your Layer's Custom Chef Recipes, add the recipe to the Deploy Lifecycle event using the following name: php_app_config::appsetup 在图层的“自定义厨师食谱”中,使用以下名称将食谱添加到“部署生命周期”事件中:php_app_config :: appsetup
  5. Deploy your application. 部署您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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