nginxbrew 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3799667578a5c727746f7e909d6fed330883248
4
- data.tar.gz: 7dc63e4e01c90743aee52c1e08b851d098672900
3
+ metadata.gz: 2f7df4fe4a967276dae08916ee18bf23ef9e4809
4
+ data.tar.gz: 19513d63f260cb095c430188f351bd67c3216261
5
5
  SHA512:
6
- metadata.gz: b3bed7f44b4598dd7ede862342dfcb5abd8f701617c6154d7124981f530f273a19ac2efe0cf0a4c34111577831af87a136ab8649077109e48627c45b5f1c4f68
7
- data.tar.gz: 39872bdf3f1692d21237469540fa2372111edb2aa740cfaae12be887908a9acbab1c1f3d6526b167142245e16d6ba2e9f3e367e7b605cc5a70c79058c5c31141
6
+ metadata.gz: ae73e62e8c7e7d7ce6243d43c2c9a3646e46f6fbb6b7504aebbc14a12879e9833f5193a064f53b6c226dbca73eb3ee1ac54b89bea98882c9bea2d75445fad219
7
+ data.tar.gz: 8e71707dd3a4580728380bbec00ec163e41ff9f483bd301e95edb4a4583a2de803efafba1738bec3c662f48aee506ce1c306ed39acc6e21fafc9d4e83a418e4c
data/CHANGES.txt CHANGED
@@ -1,5 +1,12 @@
1
1
  Nginxbrew changes
2
2
 
3
+ Nginxbrew 0.0.6
4
+ - You can change ngx-user/group by config file which specified in env {NGINXBREW_CONFIG}.
5
+ - Add/update build options by hash in ruby.
6
+ - Change default conf path to prefix dir.
7
+ - We got new command 'makeconf' to make basic configuration file of nginxbrew.
8
+
9
+
3
10
  Nginxbrew 0.0.5
4
11
  - Changed some directory/path for installation.
5
12
  - Quiet shell outs.
data/README.md CHANGED
@@ -37,7 +37,7 @@ After the command execution, ~/nginxbrew (or path which set NGINXBREW_HOME in en
37
37
  ~/nginxbrew/run/ -- directory for pid file, be shared
38
38
  ~/nginxbrew/logs/<version>/ -- log files
39
39
  ~/nginxbrew/versions/ngx-<version>/ -- $prefix directory of each version
40
- ~/nginxbrew/versions/ngx-<version>/conf/ -- nginx.conf and other configuration files
40
+ ~/nginxbrew/versions/ngx-<version>/nginx.conf -- nginx.conf and also pther .conf files are installed here
41
41
  ~/nginxbrew/versions/ngx-<version>/bin/nginx -- nginx bin for each version
42
42
 
43
43
 
@@ -82,28 +82,47 @@ If you specify prefix of version, the version will be filtered.
82
82
 
83
83
  ## Customize configuration
84
84
 
85
- You can customize Nginxbrew behavior by changing ENV.
85
+ ### Change home directory of nginxbrew
86
+
87
+ You can choose other home dir for nginxbrew by the following env.
86
88
 
87
89
  NGINXBREW_HOME # change nginxbrew root directory from ~/nginxbrew to somewhere
88
- NGINXBREW_USER # linux user for nginx
89
- NGINXBREW_GROUP # linux group for nginx
90
90
 
91
- You can change directory/options for nginx if you write configfile for nginxbrew.
91
+ ### Change options to build nginx
92
+
93
+ Some build options for can be changed by config file.
94
+
95
+ This is in ruby DSL format, so you can change some build options easily.
96
+
97
+ First, you can create new configfile by using *makeconf* command.
98
+
99
+ $ nginxbrew makeconf `pwd`/myconfig.rb
92
100
 
93
- The following my_config.rb is configuration to share $prefix of nginx & nginx.conf troughout all builds of nginx.
101
+ The following myconfig.rb is configuration to share $prefix of nginx & nginx.conf troughout all builds of nginx, and changing user/group, build options.
94
102
 
95
103
  ```ruby
96
104
  Nginxbrew.configure do |config|
105
+
97
106
  config.ngx_prefix = File.join(config.home_dir, "share")
98
107
  config.ngx_conf_path = File.join(config.home_dir, "share/nginx.conf")
99
- config.ngx_configure =<<-EOF
100
- # --- options for ./configure, starts from ./configure ...
101
- EOF
108
+
109
+ config.ngx_user = "somebody"
110
+ config.ngx_group = "somebody"
111
+
112
+ # add(or update) flags in this section
113
+ config.ngx_configure.merge!({
114
+ "--with-lua51" => nil,
115
+ "--pid-path" => "/tmp/nginx.pid",
116
+ "--http-fastcgi-temp-path" => File.join(config.home_dir, "/tmp/fastcgi"),
117
+ "--http-uwsgi-temp-path" => File.join(config.home_dir, "/tmp/uwsgi"),
118
+ "--with-select_module" => nil,
119
+ })
120
+
102
121
  end
103
122
  ```
104
123
 
105
124
 
106
- after that, specify path to config file which you wrote as follows
125
+ then, specify path to config file which you wrote as follows
107
126
 
108
127
  $ export NGINXBREW_CONFIG=/path/to/my_config.rb
109
128
 
@@ -115,11 +134,11 @@ then nginxbrew starts to using this configuration.
115
134
  - write tests completely
116
135
  - installable the same version of nginx with defferent labels like as follows
117
136
 
118
- $ nginxbrew install prj1 1.7.6
137
+ $ nginxbrew install 1.7.6:prj1
119
138
 
120
- $ nginxbrew install prj2 1.7.6
139
+ $ nginxbrew install 1.7.6:prj2
121
140
 
122
- $ nginxbrew use 1.7.6-prj1
141
+ $ nginxbrew use prj1
123
142
 
124
143
  - multiple install
125
144
 
data/bin/nginxbrew CHANGED
@@ -15,11 +15,10 @@ Available subcommands:
15
15
  list Show list of installed nginx versions.
16
16
  nginxes Show list of available nginx versions.
17
17
  openresties Show list of available openresty versions.
18
+ makeconf <path/to/config> Output new configfile for nginxbrew into specified path.
18
19
 
19
20
  Optional environments:
20
21
  NGINXBREW_HOME Path to nginxbrew (will be) installed, ~/nginxbrew is default.
21
- NGINXBREW_USER User for nginx (enabled in `install`), "nginx" is default.
22
- NGINXBREW_GROUP Group for nginx (enable in `install`), "nginx" is default.
23
22
  NGINXBREW_DEBUG if 1, use DEBUG level for logging.
24
23
  NGINXBREW_CONFIG /path/to/configfile written in ruby DSL for build nginx.
25
24
  EOF
@@ -59,6 +58,10 @@ begin
59
58
  Nginxbrew.run(:nginxes, envs={ "HEAD_VERSION" => ARGV.shift })
60
59
  when "openresties"
61
60
  Nginxbrew.run(:openresties, envs={ "HEAD_VERSION" => ARGV.shift })
61
+ when "makeconf"
62
+ output_to = ARGV.shift
63
+ raise Exception.new("output directory/file for config is required!") unless output_to
64
+ Nginxbrew.run(:makeconf, envs={ "makeconf_OUTPUT_TO" => output_to })
62
65
  else
63
66
  raise Exception.new("Unknown command '#{command}'")
64
67
  end
@@ -9,21 +9,21 @@ module Nginxbrew
9
9
  end
10
10
 
11
11
  class Configuration
12
+
12
13
  NGX_URL = "http://nginx.org/download"
14
+
13
15
  OPENRESTY_URL = "http://openresty.org/download"
14
16
 
15
- attr_accessor :ngx_configure, :ngx_conf_path, :ngx_prefix
16
- attr_reader :ngx_user, :ngx_group, :nginx_log_dir,
17
- :builtfile, :dist_to, :tarball, :src, :url, :home_dir, :dist_dir,
18
- :ngx_sbin_path, :package_name
17
+ attr_accessor :ngx_configure, :ngx_conf_path, :ngx_prefix, :ngx_user, :ngx_group
18
+
19
+ attr_reader :ngx_user, :ngx_group, :nginx_log_dir, :ngx_sbin_path, :package_name,
20
+ :builtfile, :dist_to, :tarball, :src, :url, :home_dir, :dist_dir, :is_openresty, :ngx_version
19
21
 
20
22
  def initialize(opts={})
21
23
  @home_dir = opts[:home_dir]
22
24
  @dist_dir = opts[:dist_dir]
23
25
  @ngx_version = opts[:ngx_version]
24
26
  @is_openresty = opts[:is_openresty]
25
- @ngx_user = opts[:ngx_user]
26
- @ngx_group = opts[:ngx_group]
27
27
  @package_name = opts[:package_name]
28
28
  @dist_to = File.join(@dist_dir, @package_name)
29
29
  @nginx_log_dir = File.join(@home_dir, "logs", @package_name)
@@ -32,15 +32,23 @@ module Nginxbrew
32
32
  @url = "#{@is_openresty ? OPENRESTY_URL : NGX_URL}/#{@tarball}"
33
33
  @ngx_sbin_path = File.join(@dist_to, "bin/nginx")
34
34
  @builtfile = File.join(@dist_to, "built")
35
- @ngx_configure = nil
36
- @ngx_conf_path = File.join(@dist_to, "conf/nginx.conf")
35
+ @ngx_conf_path = File.join(@dist_to, "nginx.conf")
36
+ @ngx_configure = {}
37
37
  @ngx_prefix = @dist_to
38
+ @ngx_user = "nginx"
39
+ @ngx_group = "nginx"
38
40
  end
39
41
 
40
42
  def configure_command
41
- return @ngx_configure if @ngx_configure
43
+ dest = ["./configure"]
44
+ configure_options.inject(dest) do |memo, opt|
45
+ memo << "#{opt[0]}" + (opt[1].nil? ? "" : "=#{opt[1]}")
46
+ memo
47
+ end.join(" ")
48
+ end
49
+
50
+ def configure_options
42
51
  cmd =<<-EOF
43
- ./configure \
44
52
  --user=#{@ngx_user} \
45
53
  --group=#{@ngx_group} \
46
54
  --prefix=#{@ngx_prefix} \
@@ -50,11 +58,15 @@ module Nginxbrew
50
58
  --http-log-path=#{@nginx_log_dir}/access.log \
51
59
  --http-client-body-temp-path=#{@home_dir}/tmp/client_body \
52
60
  --http-proxy-temp-path=#{@home_dir}/tmp/proxy \
53
- --http-fastcgi-temp-path=#{@home_dir}/tmp/fastcgi \
54
- --http-uwsgi-temp-path=#{@home_dir}/tmp/uwsgi \
55
61
  --pid-path=#{@home_dir}/run/nginx.pid
56
62
  EOF
57
- cmd.split(" ").join(" ")
63
+ dest = cmd.split(" ").inject({}) do |memo, opt|
64
+ kv = opt.split("=")
65
+ memo[kv[0]] = (kv.size == 2) ? kv[1] : nil
66
+ memo
67
+ end
68
+ dest.merge!(@ngx_configure) if @ngx_configure
69
+ dest
58
70
  end
59
71
 
60
72
  private
@@ -1,5 +1,14 @@
1
1
  Nginxbrew.configure do |config|
2
2
  # config.ngx_prefix = File.join(config.home_dir, "share")
3
3
  # config.ngx_conf_path = File.join(config.home_dir, "conf/nginx.conf")
4
+ # config.ngx_user = "nobody"
5
+ # config.ngx_group = "nobody"
6
+ # config.ngx_configure.merge!({
7
+ # "--with-lua51" => nil,
8
+ # "--pid-path" => "/tmp/nginx.pid",
9
+ # "--http-fastcgi-temp-path" => File.join(config.home_dir, "/tmp/fastcgi"),
10
+ # "--http-uwsgi-temp-path" => File.join(config.home_dir, "/tmp/uwsgi"),
11
+ # "--with-select_module" => nil,
12
+ # })
4
13
  end
5
14
 
@@ -0,0 +1,66 @@
1
+ require "fileutils"
2
+
3
+ module Nginxbrew
4
+
5
+ module Local
6
+
7
+ class Ngx
8
+
9
+ attr_reader :is_openresty, :raw_version, :version
10
+
11
+ def initialize(opts={})
12
+ @is_openresty = opts[:is_openresty]
13
+ @raw_version = opts[:raw_version]
14
+ @version = opts[:version]
15
+ end
16
+
17
+ def is?(version)
18
+ @version == version
19
+ end
20
+
21
+ def openresty?
22
+ @is_openresty
23
+ end
24
+
25
+ def name
26
+ @version
27
+ end
28
+
29
+ end
30
+
31
+ def builds(dist_dir)
32
+ dest = []
33
+ return dest unless FileTest.directory?(dist_dir)
34
+ child_dirs = Pathname.new(dist_dir).children.select{|e| e.directory? }
35
+ child_dirs.inject(dest) do |memo, d|
36
+ version = NamingConvention.version_from_package(File.basename(d))
37
+ is_openresty = NamingConvention.openresty?(version)
38
+ raw_version = is_openresty ?
39
+ NamingConvention.openresty_to_raw_version(version) : version
40
+ $logger.debug("built package: #{d} -> #{is_openresty}, #{raw_version}")
41
+ memo << Ngx.new(
42
+ :is_openresty => is_openresty,
43
+ :raw_version => raw_version,
44
+ :version => version
45
+ )
46
+ memo
47
+ end
48
+ end
49
+
50
+ def find(config)
51
+ builds(config.dist_dir).detect do |b|
52
+ b.raw_version == config.ngx_version &&
53
+ b.is_openresty == config.is_openresty
54
+ end
55
+ end
56
+
57
+ def count_of_builds(dist_dir)
58
+ builds(dist_dir).size
59
+ end
60
+
61
+ module_function :builds, :find, :count_of_builds
62
+
63
+ end
64
+
65
+ end
66
+
@@ -14,48 +14,6 @@ module Nginxbrew
14
14
 
15
15
  end
16
16
 
17
- class LocalEnv
18
-
19
- def initialize(dist_dir)
20
- @dist_dir = dist_dir
21
- end
22
-
23
- def exists?(raw_version, is_openresty)
24
- ret = installed_packages.detect do |v, data|
25
- v == raw_version && data[:openresty] == is_openresty
26
- end
27
- !ret.nil?
28
- end
29
-
30
- def installed_packages
31
- dest = {}
32
- return dest unless FileTest.directory?(@dist_dir)
33
- child_dirs.inject(dest) do |memo, d|
34
- version = NamingConvention.version_from_package(File.basename(d))
35
- is_openresty = NamingConvention.openresty?(version)
36
- raw_version = is_openresty ?
37
- NamingConvention.openresty_to_raw_version(version) : version
38
- memo[version] = {
39
- :openresty => is_openresty,
40
- :raw_version => raw_version,
41
- :version => version
42
- }
43
- memo
44
- end
45
- end
46
-
47
- def has_one_build?
48
- installed_packages.size == 1
49
- end
50
-
51
- private
52
-
53
- def child_dirs
54
- Pathname.new(@dist_dir).children.select{|e| e.directory? }
55
- end
56
-
57
- end
58
-
59
17
  class Nginxes
60
18
 
61
19
  TypeNginx = "nginx"
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require "pathname"
3
2
  require "fileutils"
4
3
 
5
4
  verbose(false) # stop verbosing by rake
6
5
 
7
- VERSION = ENV["VERSION"]
8
6
 
9
7
  HOME_DIR = ENV["NGINXBREW_HOME"] || File.join(ENV["HOME"], "nginxbrew")
10
- NGINX_USER = ENV["NGINXBREW_USER"] || "nginx"
11
- NGINX_GROUP = ENV["NGINXBREW_GROUP"] || "nginx"
8
+ $stdout.puts("using '#{HOME_DIR}' as nginxbrew home") if ENV["NGINXBREW_HOME"]
9
+
12
10
 
13
11
  CONFIG_FILE = ENV["NGINXBREW_CONFIG"]
14
12
  if CONFIG_FILE && !FileTest.file?(CONFIG_FILE)
@@ -26,14 +24,12 @@ NGINX_BIN = "#{BIN_DIR}/nginx"
26
24
  directory dir
27
25
  end
28
26
 
29
- local_env = Nginxbrew::LocalEnv.new(DIST_DIR)
30
-
31
27
 
32
- if VERSION
28
+ if ENV["VERSION"]
33
29
  require "nginxbrew/config/base"
34
30
 
35
31
  $stdout.puts("checking version ...")
36
- raw_version, is_openresty = NamingConvention.resolve(VERSION)
32
+ raw_version, is_openresty = NamingConvention.resolve(ENV["VERSION"])
37
33
  nginxes = is_openresty ? Nginxbrew::Nginxes.openresties : Nginxbrew::Nginxes.nginxes
38
34
  raw_version = nginxes.head_of(raw_version)
39
35
  package_name = NamingConvention.package_name_from(raw_version, is_openresty)
@@ -45,9 +41,7 @@ if VERSION
45
41
  :dist_dir => DIST_DIR,
46
42
  :ngx_version => raw_version,
47
43
  :package_name => package_name,
48
- :is_openresty => is_openresty,
49
- :ngx_user => NGINX_USER,
50
- :ngx_group => NGINX_GROUP
44
+ :is_openresty => is_openresty
51
45
  )
52
46
 
53
47
  require "nginxbrew/config/default"
@@ -92,7 +86,7 @@ if VERSION
92
86
 
93
87
  desc "check nginx version duplication before install"
94
88
  task :check_duplicatate do
95
- if local_env.exists?(raw_version, is_openresty)
89
+ unless Nginxbrew::Local.find(config).nil?
96
90
  warn "#{config.package_name} is already installed"
97
91
  end
98
92
  end
@@ -101,7 +95,7 @@ if VERSION
101
95
  desc "install nginx"
102
96
  task :install => [:check_duplicatate, config.builtfile] do
103
97
  Rake::Task[:chown].invoke
104
- if local_env.has_one_build?
98
+ if Nginxbrew::Local.count_of_builds(config.dist_dir) == 1
105
99
  $stdout.puts("this is first install, use this version as default")
106
100
  Rake::Task[:use].invoke
107
101
  end
@@ -110,6 +104,8 @@ if VERSION
110
104
 
111
105
  desc "switch nginx version"
112
106
  task :use => [BIN_DIR, :chown] do
107
+ ngx = Nginxbrew::Local.find(config)
108
+ puts "ngx=#{ngx}"
113
109
  unless FileTest.directory?(config.dist_to)
114
110
  raise_abort "#{config.package_name} is not installed!"
115
111
  end
@@ -118,6 +114,7 @@ if VERSION
118
114
  $stdout.puts("#{config.package_name} default to use")
119
115
  $stdout.puts("bin linked to #{config.ngx_sbin_path}")
120
116
  end
117
+
121
118
  end
122
119
 
123
120
 
@@ -142,9 +139,9 @@ task :list => DIST_DIR do
142
139
  2.times {|i| path_list.pop } # remove bin/nginx
143
140
  used_version = NamingConvention.version_from_package(path_list.pop)
144
141
  end
145
- local_env.installed_packages.keys.sort.each do |v|
146
- prefix = (v == used_version) ? "*" : " "
147
- $stdout.puts("#{prefix} #{v}")
142
+ Nginxbrew::Local.builds(DIST_DIR).each do |ngx|
143
+ prefix = ngx.is?(used_version) ? "*" : " "
144
+ $stdout.puts("#{prefix} #{ngx.name}")
148
145
  end
149
146
  end
150
147
 
@@ -168,3 +165,34 @@ task :openresties do
168
165
  $stdout.puts("[ngx_openresty-]#{v}")
169
166
  end
170
167
  end
168
+
169
+
170
+ desc "Output new configfile for nginxbrew into specified path as {makeconf_OUTPUT_TO}"
171
+ task :makeconf do
172
+ output_to = ENV["makeconf_OUTPUT_TO"]
173
+
174
+ from_file = File.join(File.dirname(__FILE__), "config/default.rb")
175
+ abort "crit, #{from_file} is not found" unless FileTest.file?(from_file)
176
+
177
+ to_file = FileTest.directory?(output_to) ?
178
+ File.join(output_to, "nginxbrew_conf.rb") : output_to
179
+ to_file = File.expand_path(to_file)
180
+ abort "config:'#{to_file}' is alrady exists!" if FileTest.file?(to_file)
181
+ abort "extname is must be '.rb'" if File.extname(to_file) != ".rb"
182
+
183
+ sh_exc("cp", from_file, to_file)
184
+
185
+ msg =<<-EOF
186
+ '#{to_file}' is created, successfully.
187
+ You can use this configuration by env NGINXBREW_CONFIG like as follows.
188
+
189
+ $ export NGINXBREW_CONFIG=#{to_file}
190
+
191
+ or
192
+
193
+ $ echo "export NGINXBREW_CONFIG=#{to_file}" >> ~/.bashrc && source ~/.bashrc
194
+ EOF
195
+
196
+ $stdout.puts(msg)
197
+ end
198
+
@@ -1,3 +1,3 @@
1
1
  module Nginxbrew
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/nginxbrew.rb CHANGED
@@ -2,6 +2,7 @@ require "rake"
2
2
 
3
3
  require "nginxbrew/version"
4
4
  require "nginxbrew/nginxes"
5
+ require "nginxbrew/local"
5
6
  require "nginxbrew/convention"
6
7
  require "nginxbrew/rake_tools"
7
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginxbrew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - takumakanari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - lib/nginxbrew/config/base.rb
73
73
  - lib/nginxbrew/config/default.rb
74
74
  - lib/nginxbrew/convention.rb
75
+ - lib/nginxbrew/local.rb
75
76
  - lib/nginxbrew/nginxes.rb
76
77
  - lib/nginxbrew/rake_tools.rb
77
78
  - lib/nginxbrew/tasks.rb
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  requirements: []
102
103
  rubyforge_project:
103
- rubygems_version: 2.4.2
104
+ rubygems_version: 2.2.2
104
105
  signing_key:
105
106
  specification_version: 4
106
107
  summary: Multi installation for nginx.