From 205a8d337ace303fec57650720acb2682334c182 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Wed, 9 Aug 2017 11:51:56 -0400 Subject: [PATCH 1/3] Updates nginx Formula for 1.12.1 Release --- files/brews/nginx.rb | 243 +++++++++++++++++++++++++++++-------- manifests/init.pp | 2 +- spec/classes/nginx_spec.rb | 2 +- 3 files changed, 193 insertions(+), 54 deletions(-) diff --git a/files/brews/nginx.rb b/files/brews/nginx.rb index c6b8b46..8c6674c 100644 --- a/files/brews/nginx.rb +++ b/files/brews/nginx.rb @@ -1,67 +1,206 @@ require 'formula' class Nginx < Formula - homepage 'https://nginx.org/' - url 'https://nginx.org/download/nginx-1.10.2.tar.gz' - sha256 '1045ac4987a396e2fa5d0011daf8987b612dd2f05181b67507da68cbe7d765c2' - version '1.10.2-boxen1' + desc "HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server" + homepage "https://nginx.org/" + url "https://nginx.org/download/nginx-1.12.1.tar.gz" + sha256 "8793bf426485a30f91021b6b945a9fd8a84d87d17b566562c3797aba8fac76fb" + version '1.12.1-boxen1' - depends_on 'pcre' + head "http://hg.nginx.org/nginx/", :using => :hg - skip_clean 'logs' - - def options - [ - ['--with-passenger', "Compile with support for Phusion Passenger module"], - ['--with-webdav', "Compile with support for WebDAV module"], - ['--with-gzip-static', "Compile with support for Gzip Static module"], - ['--with-http2', "Compile with support for the HTTP/2 module"], - ] + bottle do + sha256 "93bcf8e3aec465c219b6c0b4f4d5437c61bf00f2a930ef5702e0521edc51f20e" => :sierra + sha256 "8a7c3580534aa0854927f750d4f044a2a85f90d4c1936338a4a09fef7db0824e" => :el_capitan + sha256 "0caae754f402abbe1eca413a7f0291fe2499d5779bb1e537d7f80a4d7d3156d3" => :yosemite end - depends_on "pcre" - depends_on "openssl" => :recommended + devel do + url "https://nginx.org/download/nginx-1.13.3.tar.gz" + sha256 "5b73f98004c302fb8e4a172abf046d9ce77739a82487e4873b39f9b0dcbb0d72" + end - def passenger_config_args - passenger_root = `passenger-config --root`.chomp + # Before submitting more options to this formula please check they aren't + # already in Homebrew/homebrew-nginx/nginx-full: + # https://github.com/Homebrew/homebrew-nginx/blob/master/Formula/nginx-full.rb + option "with-passenger", "Compile with support for Phusion Passenger module" + option "with-webdav", "Compile with support for WebDAV module" + option "with-debug", "Compile with support for debug log" + option "with-gunzip", "Compile with support for gunzip module" - if File.directory?(passenger_root) - return "--add-module=#{passenger_root}/ext/nginx" - end + depends_on "pcre" + depends_on "passenger" => :optional - puts "Unable to install nginx with passenger support. The passenger" - puts "gem must be installed and passenger-config must be in your path" - puts "in order to continue." - exit + # passenger uses apr, which uses openssl, so need to keep + # crypto library choice consistent throughout the tree. + if build.with? "passenger" + depends_on "openssl" + else + depends_on "openssl@1.1" end def install + # Changes default port to 8080 + inreplace "conf/nginx.conf" do |s| + s.gsub! "listen 80;", "listen 8080;" + s.gsub! " #}\n\n}", " #}\n include servers/*;\n}" + end + pcre = Formula["pcre"] - openssl = Formula["openssl"] - cc_opt = "-I#{pcre.include} -I#{openssl.include}" - ld_opt = "-L#{pcre.lib} -L#{openssl.lib}" - - args = ["--prefix=#{prefix}", - "--with-http_ssl_module", - "--with-pcre", - "--with-ipv6", - "--with-cc-opt=#{cc_opt}", - "--with-ld-opt=#{ld_opt}", - "--conf-path=/opt/boxen/config/nginx/nginx.conf", - "--pid-path=/opt/boxen/data/nginx/nginx.pid", - "--lock-path=/opt/boxen/data/nginx/nginx.lock"] - - args << passenger_config_args if ARGV.include? '--with-passenger' - args << "--with-http_dav_module" if ARGV.include? '--with-webdav' - args << "--with-http_gzip_static_module" if ARGV.include? '--with-gzip-static' - args << "--with-http_v2_module" if ARGV.include? "--with-http2" - - system "./configure", *args - system "make" - system "make install" - man8.install "objs/nginx.8" - - # remove unnecessary config files - system "rm -rf #{etc}/nginx" + + if build.with? "passenger" + openssl = Formula["openssl"] + else + openssl = Formula["openssl@1.1"] + end + + cc_opt = "-I#{pcre.opt_include} -I#{openssl.opt_include}" + ld_opt = "-L#{pcre.opt_lib} -L#{openssl.opt_lib}" + + args = %W[ + --prefix=#{prefix} + --with-http_ssl_module + --with-pcre + --sbin-path=#{bin}/nginx + --with-cc-opt=#{cc_opt} + --with-ld-opt=#{ld_opt} + --conf-path=#{etc}/nginx/nginx.conf + --pid-path=#{var}/run/nginx.pid + --lock-path=#{var}/run/nginx.lock + --http-client-body-temp-path=#{var}/run/nginx/client_body_temp + --http-proxy-temp-path=#{var}/run/nginx/proxy_temp + --http-fastcgi-temp-path=#{var}/run/nginx/fastcgi_temp + --http-uwsgi-temp-path=#{var}/run/nginx/uwsgi_temp + --http-scgi-temp-path=#{var}/run/nginx/scgi_temp + --http-log-path=#{var}/log/nginx/access.log + --error-log-path=#{var}/log/nginx/error.log + --with-http_gzip_static_module + --with-http_v2_module + ] + + if build.with? "passenger" + nginx_ext = `#{Formula["passenger"].opt_bin}/passenger-config --nginx-addon-dir`.chomp + args << "--add-module=#{nginx_ext}" + end + + args << "--with-http_dav_module" if build.with? "webdav" + args << "--with-debug" if build.with? "debug" + args << "--with-http_gunzip_module" if build.with? "gunzip" + + if build.head? + system "./auto/configure", *args + else + system "./configure", *args + end + + system "make", "install" + if build.head? + man8.install "docs/man/nginx.8" + else + man8.install "man/nginx.8" + end + end + + def post_install + (etc/"nginx/servers").mkpath + (var/"run/nginx").mkpath + + # nginx's docroot is #{prefix}/html, this isn't useful, so we symlink it + # to #{HOMEBREW_PREFIX}/var/www. The reason we symlink instead of patching + # is so the user can redirect it easily to something else if they choose. + html = prefix/"html" + dst = var/"www" + + if dst.exist? + html.rmtree + dst.mkpath + else + dst.dirname.mkpath + html.rename(dst) + end + + prefix.install_symlink dst => "html" + + # for most of this formula's life the binary has been placed in sbin + # and Homebrew used to suggest the user copy the plist for nginx to their + # ~/Library/LaunchAgents directory. So we need to have a symlink there + # for such cases + if rack.subdirs.any? { |d| d.join("sbin").directory? } + sbin.install_symlink bin/"nginx" + end + end + + def passenger_caveats; <<-EOS.undent + To activate Phusion Passenger, add this to #{etc}/nginx/nginx.conf, inside the 'http' context: + passenger_root #{Formula["passenger"].opt_libexec}/src/ruby_supportlib/phusion_passenger/locations.ini; + passenger_ruby /usr/bin/ruby; + EOS + end + + def caveats + s = <<-EOS.undent + Docroot is: #{var}/www + + The default port has been set in #{etc}/nginx/nginx.conf to 8080 so that + nginx can run without sudo. + + nginx will load all files in #{etc}/nginx/servers/. + EOS + s << "\n" << passenger_caveats if build.with? "passenger" + s + end + + plist_options :manual => "nginx" + + def plist; <<-EOS.undent + + + + + Label + #{plist_name} + RunAtLoad + + KeepAlive + + ProgramArguments + + #{opt_bin}/nginx + -g + daemon off; + + WorkingDirectory + #{HOMEBREW_PREFIX} + + + EOS + end + + test do + (testpath/"nginx.conf").write <<-EOS + worker_processes 4; + error_log #{testpath}/error.log; + pid #{testpath}/nginx.pid; + + events { + worker_connections 1024; + } + + http { + client_body_temp_path #{testpath}/client_body_temp; + fastcgi_temp_path #{testpath}/fastcgi_temp; + proxy_temp_path #{testpath}/proxy_temp; + scgi_temp_path #{testpath}/scgi_temp; + uwsgi_temp_path #{testpath}/uwsgi_temp; + + server { + listen 8080; + root #{testpath}; + access_log #{testpath}/access.log; + error_log #{testpath}/error.log; + } + } + EOS + system bin/"nginx", "-t", "-c", testpath/"nginx.conf" end -end +end \ No newline at end of file diff --git a/manifests/init.pp b/manifests/init.pp index 067945b..0558c6a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -56,7 +56,7 @@ } package { 'boxen/brews/nginx': - ensure => '1.10.2-boxen1', + ensure => '1.12.1-boxen1', install_options => [ '--with-http2', ], diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 07ddb87..5bbbf2f 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -41,7 +41,7 @@ with_before('Package[boxen/brews/nginx]') should contain_package('boxen/brews/nginx').with({ - :ensure => '1.10.2-boxen1', + :ensure => '1.12.1-boxen1', :notify => 'Service[dev.nginx]' }) From 77913a51deb62dfdd035f6a3f3d5933829ccd747 Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Wed, 16 Aug 2017 19:52:11 -0400 Subject: [PATCH 2/3] Updates Custom Formula Boxen itself handles customizations to the default port, plist generation, and directory structure, obsolescing these portions of the base Homebrew formula. --- files/brews/nginx.rb | 59 -------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/files/brews/nginx.rb b/files/brews/nginx.rb index 8c6674c..9b735af 100644 --- a/files/brews/nginx.rb +++ b/files/brews/nginx.rb @@ -40,12 +40,6 @@ class Nginx < Formula end def install - # Changes default port to 8080 - inreplace "conf/nginx.conf" do |s| - s.gsub! "listen 80;", "listen 8080;" - s.gsub! " #}\n\n}", " #}\n include servers/*;\n}" - end - pcre = Formula["pcre"] if build.with? "passenger" @@ -101,35 +95,6 @@ def install end end - def post_install - (etc/"nginx/servers").mkpath - (var/"run/nginx").mkpath - - # nginx's docroot is #{prefix}/html, this isn't useful, so we symlink it - # to #{HOMEBREW_PREFIX}/var/www. The reason we symlink instead of patching - # is so the user can redirect it easily to something else if they choose. - html = prefix/"html" - dst = var/"www" - - if dst.exist? - html.rmtree - dst.mkpath - else - dst.dirname.mkpath - html.rename(dst) - end - - prefix.install_symlink dst => "html" - - # for most of this formula's life the binary has been placed in sbin - # and Homebrew used to suggest the user copy the plist for nginx to their - # ~/Library/LaunchAgents directory. So we need to have a symlink there - # for such cases - if rack.subdirs.any? { |d| d.join("sbin").directory? } - sbin.install_symlink bin/"nginx" - end - end - def passenger_caveats; <<-EOS.undent To activate Phusion Passenger, add this to #{etc}/nginx/nginx.conf, inside the 'http' context: passenger_root #{Formula["passenger"].opt_libexec}/src/ruby_supportlib/phusion_passenger/locations.ini; @@ -152,30 +117,6 @@ def caveats plist_options :manual => "nginx" - def plist; <<-EOS.undent - - - - - Label - #{plist_name} - RunAtLoad - - KeepAlive - - ProgramArguments - - #{opt_bin}/nginx - -g - daemon off; - - WorkingDirectory - #{HOMEBREW_PREFIX} - - - EOS - end - test do (testpath/"nginx.conf").write <<-EOS worker_processes 4; From 030fac95e60e63019e04f822f500904b20a8585e Mon Sep 17 00:00:00 2001 From: Daniel Wright Date: Thu, 17 Aug 2017 11:57:41 -0400 Subject: [PATCH 3/3] Removes HEAD/development Branches of Custom Formula The HEAD and development branches are unnecessary, given the purpose of the custom formula (i.e. to pin a specific package version). If an end-user would like to replace their nginx installation with a HEAD or development version, this can be done easily enough directly through Homebrew. --- files/brews/nginx.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/files/brews/nginx.rb b/files/brews/nginx.rb index 9b735af..5f84a43 100644 --- a/files/brews/nginx.rb +++ b/files/brews/nginx.rb @@ -7,19 +7,12 @@ class Nginx < Formula sha256 "8793bf426485a30f91021b6b945a9fd8a84d87d17b566562c3797aba8fac76fb" version '1.12.1-boxen1' - head "http://hg.nginx.org/nginx/", :using => :hg - bottle do sha256 "93bcf8e3aec465c219b6c0b4f4d5437c61bf00f2a930ef5702e0521edc51f20e" => :sierra sha256 "8a7c3580534aa0854927f750d4f044a2a85f90d4c1936338a4a09fef7db0824e" => :el_capitan sha256 "0caae754f402abbe1eca413a7f0291fe2499d5779bb1e537d7f80a4d7d3156d3" => :yosemite end - devel do - url "https://nginx.org/download/nginx-1.13.3.tar.gz" - sha256 "5b73f98004c302fb8e4a172abf046d9ce77739a82487e4873b39f9b0dcbb0d72" - end - # Before submitting more options to this formula please check they aren't # already in Homebrew/homebrew-nginx/nginx-full: # https://github.com/Homebrew/homebrew-nginx/blob/master/Formula/nginx-full.rb @@ -81,18 +74,10 @@ def install args << "--with-debug" if build.with? "debug" args << "--with-http_gunzip_module" if build.with? "gunzip" - if build.head? - system "./auto/configure", *args - else - system "./configure", *args - end + system "./configure", *args system "make", "install" - if build.head? - man8.install "docs/man/nginx.8" - else - man8.install "man/nginx.8" - end + man8.install "man/nginx.8" end def passenger_caveats; <<-EOS.undent