[英]AWS Opsworks Custom Layer Deployment
我正在嘗試在AWS Opsworks中使用自定義圖層來添加nginx網絡服務器。
我已成功創建了圖層,我通過GIT添加了我的應用程序(repo上沒有密碼),但是當我部署命令時“成功”但我在服務器上看不到任何代碼。
在自定義層中,唯一的部署配方是“deploy :: default”。
我是否需要自定義配方來處理部署?
另外,如何配置部署的“位置”? 我更喜歡選擇我的文檔根目錄,而不是使用Opsworks似乎總是部署到的位置。
感謝您對此的任何幫助。
我寫了一個簡單的配方,它使用Opsworks nginx配方完全自動部署應用程序。 它從您配置的SCM中檢出,創建一個新的nginx vhost,並在需要時重新加載nginx。
將此配方添加到層中的deploy配置:
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'
我的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"
是的,您需要為自定義層編寫自己的自定義部署配方。 部署配方可以配置部署的位置以及部署軟件所需的任何步驟。 或者,您可以擴展部署Nginx的OpsWorks靜態Web服務器層,以滿足您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.