【问题标题】:AWS Opsworks Custom Layer DeploymentAWS Opsworks 自定义层部署
【发布时间】:2013-08-07 19:42:18
【问题描述】:

我正在尝试使用 AWS Opsworks 中的自定义层来添加 nginx 网络服务器。

我已成功创建图层,我通过 GIT 添加了我的应用程序(在 repo 上没有密码),但是当我部署命令时“成功”,但我在服务器上看不到任何代码。

在自定义层中,唯一的部署配方是“deploy::default”。

我是否需要自定义配方来处理部署?

另外,我如何配置部署的“位置”?我更愿意选择我的文档根目录,而不是使用 Opsworks 似乎总是部署到的位置。

感谢您对此的任何帮助。

【问题讨论】:

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


    【解决方案1】:

    我编写了一个简单的配方,它使用 Opsworks nginx 配方来全自动部署应用程序。它会从您配置的 SCM 中签出,创建一个新的 nginx 虚拟主机并在需要时重新加载 nginx。

    将此配方添加到层中的部署配置中:

    deploy.rb

    include_recipe "deploy"
    include_recipe "php5"
    
    node[:deploy].each do |application, deploy|
    
      Chef::Log.info("Deploying application #{application} on #{node[:opsworks][:instance][:hostname]}")
    
      if deploy[:application_type] != 'php'
        Chef::Log.warn("Skipping deploy::web application #{application} as it is not a PHP app")
        next
      end
    
      opsworks_deploy_dir do
        user deploy[:user]
        group deploy[:group]
        path deploy[:deploy_to]
      end
    
      opsworks_deploy do
        app application
        deploy_data deploy
      end
    
      nginx_web_app application do
        application deploy
      end
    
      Chef::Log.info("Running composer update on #{deploy[:deploy_to]}")
      composer_update do
        path deploy[:deploy_to]}
      end
    end
    

    要覆盖 nginx vhost 模板,只需创建一个名为 nginx 的新说明书并在 templates/default 中添加一个文件 site.erb。 Opsworks 将自动使用此模板。

    我的 site.erb 看起来像这样

    server {
      listen   80;
      server_name  <%= @application[:domains].join(" ") %> <%= node[:hostname] %>;
      access_log  <%= node[:nginx][:log_dir] %>/<%= @application[:domains].first %>.access.log;
    
      root   <%= @application[:absolute_document_root] %>;
    
      location / {
         try_files $uri /index.php?url=$uri&$args;
      }
    
      location ~ \.php {
          try_files $uri =404;
    
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
          include fastcgi_params;
      }
    
      # Block all svn access
      if ($request_uri ~* ^.*\.svn.*$) {
         return 404;
      }
    
      # Block all git access
      if ($request_uri ~* ^.*\.git.*$) {
         return 404;
      }
    
      location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
      }
    
    }
    
    <% if @application[:ssl_support] %>
    server {
      listen   443;
      server_name  <%= @application[:domains].join(" ") %> <%= node[:hostname] %>;
      access_log  <%= node[:nginx][:log_dir] %>/<%= @application[:domains].first %>-ssl.access.log;
    
      ssl on;
      ssl_certificate <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.crt;
      ssl_certificate_key <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.key;
      <% if @application[:ssl_certificate_ca] -%>
      ssl_client_certificate <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.ca;
      <% end -%>
    
      location / {
         try_files $uri /index.php?url=$uri&$args;
      }
    
      location ~ \.php {
          try_files $uri =404;
    
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
          include fastcgi_params;
      }
    
      # Block all svn access
      if ($request_uri ~* ^.*\.svn.*$) {
         return 404;
      }
    
      # Block all git access
      if ($request_uri ~* ^.*\.git.*$) {
         return 404;
      }
    }
    <% end %>
    

    我的 Berksfile(作曲家)

    source "https://supermarket.getchef.com"
    
    cookbook 'composer', '~> 1.0.4'
    

    我在部署 appserver::deploy recipe 的说明书中的 metadata.rb

    name             'appserver'
    maintainer       'Michel Feldheim'
    description      'Setting up the appserver environment'
    long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
    version          '0.1.0'
    
    depends          "nginx"
    depends          "php5"
    

    【讨论】:

    • 当您非常详细地回答问题但您的回答既不被接受也不被简单地说“谢谢”时,这真的很糟糕。好吧.. 代表其他 SOF 用户感谢您。
    【解决方案2】:

    是的,您需要为自定义层编写自己的自定义部署配方。您的部署配方可以配置部署的去向以及部署软件所需的任何步骤。或者,您可以扩展部署 Nginx 的 OpsWorks 静态 Web 服务器层以满足您的需求。

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 2015-05-01
      • 2014-01-27
      • 2016-09-26
      • 2014-09-06
      • 2016-01-10
      • 2014-05-21
      • 2016-10-05
      • 2015-05-04
      相关资源
      最近更新 更多