2013-08-06 40 views
9

Tôi đang cố gắng sử dụng lớp tùy chỉnh trong AWS Opsworks để thêm máy chủ web nginx.AWS Opsworks Triển khai lớp tùy chỉnh

Tôi đã tạo thành công lớp, tôi đã thêm ứng dụng của mình qua GIT (không có mật khẩu trên repo), nhưng khi triển khai lệnh là "thành công" nhưng tôi không thấy bất kỳ mã nào trên máy chủ của mình.

Trong lớp tùy chỉnh, công thức triển khai duy nhất là "deploy :: default".

Tôi có cần một công thức tùy chỉnh để xử lý việc triển khai không?

Ngoài ra, làm cách nào để định cấu hình "nơi" triển khai sẽ đi? Tôi muốn chọn tài liệu gốc của tôi hơn là sử dụng Opsworks vị trí nào khác dường như luôn triển khai.

Cảm ơn BẤT CỨ trợ giúp về điều này.

Trả lời

1

Có, bạn sẽ cần phải viết công thức triển khai tùy chỉnh của riêng mình cho một lớp tùy chỉnh. Công thức triển khai của bạn có thể định cấu hình nơi triển khai và bất kỳ bước nào cần thiết để triển khai phần mềm của bạn. Ngoài ra, bạn có thể mở rộng lớp máy chủ web tĩnh của OpsWorks, triển khai Nginx, để đáp ứng nhu cầu của bạn.

13

Tôi đã viết một công thức đơn giản sử dụng công thức ngụy trang Opsworks để triển khai ứng dụng hoàn toàn tự động. Nó kiểm tra từ cấu hình SCM của bạn, tạo ra một vin nginx mới và tải lại nginx nếu cần thiết.

Thêm công thức này để cấu hình triển khai trong lớp:

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 

Để ghi đè lên mẫu nginx vhost, chỉ cần tạo một sách dạy nấu ăn mới gọi là nginx và thêm một tập tin site.erb trong templates/default. Opsworks sẽ tự động sử dụng mẫu này sau đó.

site.erb của tôi trông như thế này

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 (đối với nhà soạn nhạc)

source "https://supermarket.getchef.com" 

cookbook 'composer', '~> 1.0.4' 

metadata.rb của tôi trong sách dạy nấu ăn cho triển khai appserver :: triển khai recipe

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" 
+6

Nó thực sự hút khi bạn trả lời một câu hỏi rất chi tiết nhưng câu trả lời của bạn không được chấp nhận hoặc bạn chỉ đơn giản là nói 'cảm ơn'. Vâng .. Cảm ơn bạn thay mặt cho những người dùng SOF khác. – scaryguy

Các vấn đề liên quan