OSDN Git Service

bc2dfdfc1a7703dbb4f0d0e3232fb60e01125d12
[metasearch/grid-chef-repo.git] / cookbooks / nexus-grid / README.md
1 nexus-grid Cookbook
2 ===================
3
4 This cookbook sets up a Sonatype Nexus Repository Manager by Docker Compose.
5
6 ## Contents
7
8 - [Requirements](#requirements)
9     - [platforms](#platforms)
10     - [packages](#packages)
11     - [cookbooks](#cookbooks)
12 - [Attributes](#attributes)
13 - [Usage](#usage)
14     - [Recipes](#recipes)
15         - [nexus-grid::default](#nexus-griddefault)
16         - [nexus-grid::docker-compose](#nexus-griddocker-compose)
17     - [Role Examples](#role-examples)
18     - [SSL server keys and certificates management by ssl_cert cookbook](#ssl-server-keys-and-certificates-management-by-ssl_cert-cookbook)
19 - [License and Authors](#license-and-authors)
20
21 ## Requirements
22
23 ### platforms
24 - RHEL, CentOS >= 7.0
25 - Debian >= 8.0
26 - Ubuntu >= 14.04
27
28 ### packages
29 - none.
30
31 ### cookbooks
32 - `docker-grid`
33 - `platform_utils`
34 - `ssl_cert`
35
36 ## Attributes
37
38 |Key|Type|Description, example|Default|
39 |:--|:--|:--|:--|
40 |`['nexus-grid']['with_ssl_cert_cookbook']`|Boolean|Activates TLS configurations by the `ssl_cert` cookbook. See `attributes/default.rb`|`false`|
41 |`['nexus-grid']['ssl_cert']['common_name']`|String|Server common name for TLS|`node['fqdn']`|
42 |`['nexus-grid']['docker-compose']['app_dir']`|String||`"#{node['docker-grid']['compose']['app_dir']}/nexus"`|
43 |`['nexus-grid']['docker-compose']['etc_dir']`|String||`"#{node['nexus-grid']['docker-compose']['app_dir']}/etc"`|
44 |`['nexus-grid']['docker-compose']['data_dir']`|String|Path string or nil (unset).|`"#{node['nexus-grid']['docker-compose']['app_dir']}/data"`|
45 |`['nexus-grid']['docker-compose']['config']`|Hash|`docker-compose.yml` configurations.|See `attributes/default.rb`|
46
47 ## Usage
48
49 ### Recipes
50
51 #### nexus-grid::default
52
53 This recipe does nothing.
54
55 #### nexus-grid::docker-compose
56
57 This recipe generates a `docker-compose.yml` file for the Sonatype Nexus Repository Manager service.
58
59 ### Role Examples
60
61 - `roles/nexus.rb`
62
63 ```ruby
64 name 'nexus'
65 description 'Nexus'
66
67 run_list(
68   # see https://osdn.net/projects/metasearch/scm/git/grid-chef-repo/blobs/master/roles/docker-new-repo.rb
69   'role[docker]',
70   'recipe[nexus-grid::docker-compose]',
71 )
72
73 image = 'sonatype/nexus3'
74 #image = 'sonatype/nexus'  # Nexus2
75 port = '8081'
76
77 override_attributes(
78   'nexus-grid' => {
79     'docker-compose' => {
80       'config' => {
81         'version' => '2',
82         'services' => {
83           'reverseproxy' => {
84             'ports' => [
85               "#{port}:8081",
86             ],
87             'volumes' => [
88               # This volume will be set by the nexus-grid::docker-compose recipe automatically.
89               #"#{node['nexus-grid']['docker-compose']['etc_dir']}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro",
90             ],
91           },
92           'nexus' => {
93             'restart' => 'always',
94             'image' => image,
95             'volumes' => [
96               # This volume will be set by the nexus-grid::docker-compose recipe automatically.
97               # * Nexus3
98               #"#{node['nexus-grid']['docker-compose']['data_dir']}:/nexus-data:rw",
99               # * Nexus2
100               #"#{node['nexus-grid']['docker-compose']['data_dir']}:/sonatype-work:rw",
101             ],
102             'environment' => {
103               # * Nexus3
104               #'JAVA_MAX_HEAP' => '1200m',  # passed as -Xmx. Defaults to 1200m.
105               #'JAVA_MIN_HEAP' => '1200m',  # passed as -Xms. Defaults to 1200m.
106               #'EXTRA_JAVA_OPTS' => '',  # Additional options can be passed to the JVM via this variable.
107               # * Nexus2
108               #'CONTEXT_PATH' => '/nexus',
109               #'MAX_HEAP' => '768m',
110               #'MIN_HEAP' => '256m',
111               #'JAVA_OPTS' => '-server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true',
112               #'LAUNCHER_CONF' => './conf/jetty.xml ./conf/jetty-requestlog.xml',
113             },
114           },
115         },
116       },
117     },
118   },
119 )
120 ```
121
122 - `roles/nexus-with-ssl.rb`
123
124 ```ruby
125 name 'nexus-with-ssl'
126 description 'Nexus with SSL by reverse proxy (nginx)'
127
128 run_list(
129   #'recipe[ssl_cert::server_key_pairs]',  # nexus-grid cookbook < 0.1.3
130   'role[docker]',
131   'recipe[nexus-grid::docker-compose]',
132 )
133
134 image = 'sonatype/nexus3'
135 #image = 'sonatype/nexus'  # Nexus2
136 port = '8081'
137 cn = 'nexus.io.example.com'
138
139 override_attributes(
140   'ssl_cert' => {
141     #'common_names' => [
142     #  cn,  # nexus-grid cookbook < 0.1.4
143     #],
144   },
145   'nexus-grid' => {
146     'with_ssl_cert_cookbook' => true,
147     'ssl_cert' => {
148       'common_name' => cn,
149     },
150     'docker-compose' => {
151       'config' => {
152         'version' => '2',
153         'services' => {
154           'reverseproxy' => {
155             'ports' => [
156               "#{port}:8081",
157             ],
158             'volumes' => [
159               # These volumes will be set by the nexus-grid::docker-compose recipe automatically.
160               #"#{node['nexus-grid']['docker-compose']['etc_dir']}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro",
161               # and server key pair volume conf.
162             ],
163           },
164           'nexus' => {
165             'restart' => 'always',
166             'image' => image,
167             'volumes' => [
168               # This volume will be set by the nexus-grid::docker-compose recipe automatically.
169               # * Nexus3
170               #"#{node['nexus-grid']['docker-compose']['data_dir']}:/nexus-data:rw",
171               # * Nexus2
172               #"#{node['nexus-grid']['docker-compose']['data_dir']}:/sonatype-work:rw",
173             ],
174             'environment' => {
175               # * Nexus3
176               #'JAVA_MAX_HEAP' => '1200m',  # passed as -Xmx. Defaults to 1200m.
177               #'JAVA_MIN_HEAP' => '1200m',  # passed as -Xms. Defaults to 1200m.
178               #'EXTRA_JAVA_OPTS' => '',  # Additional options can be passed to the JVM via this variable.
179               # * Nexus2
180               #'CONTEXT_PATH' => '/nexus',
181               #'MAX_HEAP' => '768m',
182               #'MIN_HEAP' => '256m',
183               #'JAVA_OPTS' => '-server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true',
184               #'LAUNCHER_CONF' => './conf/jetty.xml ./conf/jetty-requestlog.xml',
185             },
186           },
187         },
188       },
189     },
190   },
191 )
192 ```
193
194 ### SSL server keys and certificates management by the `ssl_cert` cookbook
195
196 - create vault items.
197
198 ```text
199 $ ruby -rjson -e 'puts JSON.generate({"private" => File.read("nexus.io.example.com.prod.key")})' \
200 > > ~/tmp/nexus.io.example.com.prod.key.json
201
202 $ ruby -rjson -e 'puts JSON.generate({"public" => File.read("nexus.io.example.com.prod.crt")})' \
203 > > ~/tmp/nexus.io.example.com.prod.crt.json
204
205 $ cd $CHEF_REPO_PATH
206
207 $ knife vault create ssl_server_keys nexus.io.example.com.prod \
208 > --json ~/tmp/nexus.io.example.com.prod.key.json
209
210 $ knife vault create ssl_server_certs nexus.io.example.com.prod \
211 > --json ~/tmp/nexus.io.example.com.prod.crt.json
212 ```
213
214 - grant reference permission to the Concourse host
215
216 ```text
217 $ knife vault update ssl_server_keys  nexus.io.example.com.prod -S 'name:nexus-host.example.com'
218 $ knife vault update ssl_server_certs nexus.io.example.com.prod -S 'name:nexus-host.example.com'
219 ```
220
221 - modify run_list and attributes
222
223 ```ruby
224 run_list(
225   #'recipe[ssl_cert::server_key_pairs]',  # nexus-grid cookbook < 0.1.3
226   'recipe[nexus-grid::docker-compose]',
227 )
228
229 override_attributes(
230   'ssl_cert' => {
231     #'common_names' => [
232     #  'nexus.io.example.com',  # nexus-grid cookbook < 0.1.4
233     #],
234   },
235   'nexus-grid' => {
236     'with_ssl_cert_cookbook' => true,
237     'ssl_cert' => {
238       'common_name' => 'nexus.io.example.com',
239     },
240     # ...
241   },
242 )
243 ```
244
245 ## License and Authors
246
247 - Author:: whitestar at osdn.jp
248
249 ```text
250 Copyright 2017, whitestar
251
252 Licensed under the Apache License, Version 2.0 (the "License");
253 you may not use this file except in compliance with the License.
254 You may obtain a copy of the License at
255
256     http://www.apache.org/licenses/LICENSE-2.0
257
258 Unless required by applicable law or agreed to in writing, software
259 distributed under the License is distributed on an "AS IS" BASIS,
260 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
261 See the License for the specific language governing permissions and
262 limitations under the License.
263 ```