[英]AWS Opsworks Custom Layer Deployment
I am trying to use a custom layer in AWS Opsworks to add a nginx webserver. 我正在尝试在AWS Opsworks中使用自定义图层来添加nginx网络服务器。
I have successfully created the layer, I added my app via GIT (no password on repo), but when I deploy the command is "successful" but I don't see any of my code on my server. 我已成功创建了图层,我通过GIT添加了我的应用程序(repo上没有密码),但是当我部署命令时“成功”但我在服务器上看不到任何代码。
In the custom layer, the only deploy recipe is "deploy::default". 在自定义层中,唯一的部署配方是“deploy :: default”。
Do I need a custom recipe to handle the deployment? 我是否需要自定义配方来处理部署?
Also, how do I configure "where" the deployment goes? 另外,如何配置部署的“位置”? I'd prefer to chose my document root rather than using what location Opsworks otherwise seems to always deploy to.
我更喜欢选择我的文档根目录,而不是使用Opsworks似乎总是部署到的位置。
Thanks for ANY help on this. 感谢您对此的任何帮助。
I've written a simple recipe which uses the Opsworks nginx recipe to deploy the app fully automatically. 我写了一个简单的配方,它使用Opsworks nginx配方完全自动部署应用程序。 It checks out from your configured SCM, creates a new nginx vhost and reloads nginx if required.
它从您配置的SCM中检出,创建一个新的nginx vhost,并在需要时重新加载nginx。
Add this recipe to the deploy config in the layer: 将此配方添加到层中的deploy配置:
deploy.rb 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
To overwrite the nginx vhost template, just create a new cookbook called nginx
and add a file site.erb
in templates/default
. 要覆盖nginx vhost模板,只需创建一个名为
nginx
的新手册,并在templates/default
添加一个文件site.erb
。 Opsworks will automatically use this template then. Opsworks将自动使用此模板。
My site.erb looks like this 我的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 %>
My Berksfile (for composer) 我的Berksfile(作曲家)
source "https://supermarket.getchef.com"
cookbook 'composer', '~> 1.0.4'
My metadata.rb in the cookbook for the deploy appserver::deploy recipe 我的metadata.rb在部署appserver :: deploy配方的cookbook中
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"
Yes, you will need to write your own custom deploy recipe for a custom layer. 是的,您需要为自定义层编写自己的自定义部署配方。 Your deploy recipe can configure where the deployment goes and any steps required to deploy your software.
部署配方可以配置部署的位置以及部署软件所需的任何步骤。 Alternatively you can extend the OpsWorks static web server layer, which deploys Nginx, to meet your needs.
或者,您可以扩展部署Nginx的OpsWorks静态Web服务器层,以满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.