OSDN Git Service

removes an extra attribute.
[metasearch/grid-chef-repo.git] / roles / devops-suite-with-ssl-on-docker.rb
1 #
2 # Copyright 2017, whitestar
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 name 'devops-suite-with-ssl-on-docker'
18 description 'DevOps Suite with SSL on Docker'
19
20 host_cn = nil
21 ca_name = nil
22 #ca_name = 'grid_ca'
23 import_ca = false
24 # chef-solo or chef-client local mode
25 if $0.split.include?('chef-solo') || ($0.split.include?('chef-client') && ARGV.include?('-z'))
26   require 'ohai'
27   node = Ohai::System.new
28   node.all_plugins
29
30   host_cn = node['fqdn'] if host_cn.nil?
31 end
32 host_cn = 'devops.io.example.com' if host_cn.nil?
33 aptly_cn = host_cn        # e.g. 'aptly.io.example.com'
34 athenz_cn = host_cn       # e.g. 'athenz.io.example.com'
35 concourse_cn = host_cn    # e.g. 'concourse.io.example.com'
36 concourse_port      = '8443'
37 docker_reg_cn = host_cn   # e.g. 'registry.docker.example.com'
38 docker_reg_port     = '5000'
39 docker_reg_data_vol = '/opt/docker-compose/app/registry/data'
40 gitlab_cn = host_cn       # e.g. 'gitlab.io.example.com'
41 gitlab_https_port   =  '443'
42 gitlab_reg_port     = '5050'
43 jenkins_cn = host_cn      # e.g. 'jenkins.io.example.com'
44 jenkins_port        = '9083'
45 nexus_cn = host_cn        # e.g. 'nexus.io.example.com'
46 screwdriver_cn = host_cn  # e.g. 'screwdriver.io.example.com'
47 screwdriver_ui_port = '9000'  # default: 9000
48 vault_cn = host_cn        # e.g. 'vault.io.example.com'
49 dockerd_extra_opts = [
50   '-H fd://',
51   '--bip=192.168.100.1/24 --fixed-cidr=192.168.100.0/24',
52   #"--registry-mirror=https://#{docker_reg_cn}:#{docker_reg_port}",
53 ].join(' ')
54
55 # for debug
56 with_ssl = true
57
58 common_names = [
59   host_cn,
60 ].compact.uniq
61 common_names = nil if common_names.empty?
62
63 # for GitLab
64 ldap_servers = <<-'EOS'
65 main: # 'main' is the GitLab 'provider ID' of this LDAP server
66   label: 'LDAP'
67   host: 'ldap.grid.example.com'
68   port: 389
69   uid: 'uid'  # 'sAMAccountName'
70   method: 'tls' # "tls" or "ssl" or "plain"
71   #bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
72   #password: '_the_password_of_the_bind_user'
73   active_directory: false
74   allow_username_or_email_login: false
75   block_auto_created_users: false
76   base: 'ou=Users,dc=grid,dc=example,dc=com'
77   #user_filter: ''
78   attributes:
79     username: ['uid', 'userid', 'sAMAccountName']
80     email:    ['mail', 'email', 'userPrincipalName']
81     name:       'cn'
82     first_name: 'givenName'
83     last_name:  'sn'
84   ## EE only
85   #group_base: ''
86   #admin_group: ''
87   #sync_ssh_keys: false
88 #
89 #secondary: # 'secondary' is the GitLab 'provider ID' of second LDAP server
90 #  label: 'LDAP'
91 #  host: '_your_ldap_server'
92 #  port: 389
93 #  uid: 'sAMAccountName'
94 #  method: 'plain' # "tls" or "ssl" or "plain"
95 #  bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
96 #  password: '_the_password_of_the_bind_user'
97 #  active_directory: true
98 #  allow_username_or_email_login: false
99 #  block_auto_created_users: false
100 #  base: ''
101 #  user_filter: ''
102 #  attributes:
103 #    username: ['uid', 'userid', 'sAMAccountName']
104 #    email:    ['mail', 'email', 'userPrincipalName']
105 #    name:       'cn'
106 #    first_name: 'givenName'
107 #    last_name:  'sn'
108 #  ## EE only
109 #  group_base: ''
110 #  admin_group: ''
111 #  sync_ssh_keys: false
112 EOS
113
114 run_list(
115   'role[devops-suite-on-docker]',
116   'recipe[docker-grid::registry]',
117 )
118
119 #env_run_lists()
120
121 #default_attributes()
122
123 override_attributes(
124   'ssl_cert' => {
125     'ca_names' => [
126       ca_name,
127     ],
128     'common_names' => common_names,
129   },
130   'docker-grid' => {
131     'engine' => {
132       'skip_setup' => false,
133       'daemon_extra_options' => dockerd_extra_opts,
134     },
135     'compose' => {
136       'skip_setup' => false,
137     },
138     'registry' => {
139       'with_ssl_cert_cookbook' => with_ssl,
140       'ssl_cert' => {
141         'common_name' => docker_reg_cn,
142       },
143       'docker-compose' => {
144         'host_data_volume' => docker_reg_data_vol,
145         'config' => {
146           'registry' => {
147             'ports' => [
148               "#{docker_reg_port}:5000",
149             ],
150             'environment' => {
151               #'REGISTRY_AUTH' =>                'htpasswd',
152               #'REGISTRY_AUTH_HTPASSWD_PATH' =>  '/auth/.htpasswd',
153               #'REGISTRY_AUTH_HTPASSWD_REALM' => 'Registry Realm',
154               # proxy cache only.
155               'REGISTRY_PROXY_REMOTEURL' => 'https://registry-1.docker.io',
156             },
157             #'volumes' => [
158             #],
159           },
160         },
161       },
162     },
163   },
164   'apt_utils' => {
165     'aptly' => {
166       'with_ssl_cert_cookbook' => with_ssl,
167       'ssl_cert' => {
168         'common_name' => aptly_cn,
169       },
170       'docker-compose' => {
171         'config' => {
172           'services' => {
173             'reverseproxy' => {
174               #'ports' => [
175               #],
176             },
177             'aptly' => {
178             },
179           },
180         },
181       },
182     },
183   },
184   'concourse-ci' => {
185     'with_ssl_cert_cookbook' => with_ssl,
186     'ssl_cert' => {
187       'ca_names' => [
188         ca_name,
189       ],
190       'common_name' => concourse_cn,
191     },
192     'docker-compose' => {
193       'import_ca' => import_ca,
194       # 'web_encryption_key_vault_item' => {
195       #   'vault' => 'concourse',
196       #   'name' => 'web_encryption_key',
197       #   'env_context' => false,
198       #   'key' => 'ekey',  # real hash path: "/ekey"
199       # },
200       # 'web_oauth_client_id_vault_item' => {
201       #   'vault' => 'concourse',
202       #   'name' => 'web_oauth_client_id',
203       #   'env_context' => false,
204       #   'key' => 'cid',  # real hash path: "/cid"
205       # },
206       # 'web_oauth_client_secret_vault_item' => {
207       #   'vault' => 'concourse',
208       #   'name' => 'web_oauth_client_secret',
209       #   'env_context' => false,
210       #   'key' => 'secret',  # real hash path: "/secret"
211       # },
212       'config' => {
213         # Version 1 docker-compose format
214         'concourse-db' => {
215         },
216         'concourse-web' => {
217           'ports' => [
218             "#{concourse_port}:8443",
219           ],
220           'environment' => {
221             'CONCOURSE_TLS_BIND_PORT' => '8443',
222             'CONCOURSE_EXTERNAL_URL' => "https://#{concourse_cn}:#{concourse_port}",
223             # OAuth for the default `main`` team
224             #'CONCOURSE_GENERIC_OAUTH_DISPLAY_NAME' => 'GitLab',
225             #'CONCOURSE_GENERIC_OAUTH_AUTH_URL' => "https://#{gitlab_cn}/oauth/authorize",
226             #'CONCOURSE_GENERIC_OAUTH_TOKEN_URL' => "https://#{gitlab_cn}/oauth/token",
227           },
228         },
229         'concourse-worker' => {
230           'environment' => {
231           },
232         },
233       },
234     },
235   },
236   'gitlab-grid' => {
237     'with_ssl_cert_cookbook' => with_ssl,
238     'ssl_cert' => {
239       'ca_name' => ca_name,
240       'common_name' => gitlab_cn,
241       'registry' => {
242         'reuse_gitlab_common_name' => true,
243         # or
244         #'reuse_gitlab_common_name' => false,
245         #'common_name' => registry_gitlab_cn,
246       },
247     },
248     'gitlab.rb' => {
249       'external_url' => "https://#{gitlab_cn}:#{gitlab_https_port}",
250       'registry_external_url' => "https://#{gitlab_cn}:#{gitlab_reg_port}",  # not 5000 if same domain (common name)
251       'gitlab_rails' => {
252         #'ldap_enabled' => true,
253         #'ldap_servers' => YAML.load(ldap_servers),
254       },
255       'nginx' => {
256         'redirect_http_to_https' => true,
257       },
258       'registry_nginx' => {
259         'redirect_http_to_https' => true,
260       },
261     },
262     'docker-compose' => {
263       'config' => {
264         'services' => {
265           'gitlab' => {
266             'hostname' => gitlab_cn,
267             'ports' => [
268               "#{gitlab_https_port}:#{gitlab_https_port}",
269               "#{gitlab_reg_port}:#{gitlab_reg_port}",
270             ],
271           },
272         },
273       },
274     },
275     'runner-docker-compose' => {
276       'import_ca' => import_ca,
277     },
278   },
279   'jenkins-grid' => {
280     'with_ssl_cert_cookbook' => with_ssl,
281     'ssl_cert' => {
282       'common_name' => jenkins_cn,
283     },
284     'docker-compose' => {
285       'config' => {
286         'services' => {
287           'jenkins' => {
288             'ports' => [
289               "#{jenkins_port}:8083",
290             ],
291             'environment' => {
292               'JENKINS_OPTS' => [
293                 '--httpPort=-1 --httpsPort=8083',
294                 # These options will be set by the jenkins-grid::docker-compose recipe automatically.
295                 #'--httpsCertificate=/var/lib/jenkins/server.crt',
296                 #'--httpsPrivateKey=/var/lib/jenkins/server.key',
297               ].join(' '),
298             },
299           },
300         },
301       },
302     },
303   },
304   'nexus-grid' => {
305     'with_ssl_cert_cookbook' => with_ssl,
306     'ssl_cert' => {
307       'common_name' => nexus_cn,
308     },
309     'docker-compose' => {
310       'config' => {
311         'services' => {
312           'reverseproxy' => {
313             #'ports' => [
314             #],
315           },
316           'nexus' => {
317           },
318         },
319       },
320     },
321   },
322   'screwdriver' => {
323     'with_ssl_cert_cookbook' => with_ssl,
324     'ssl_cert' => {
325       'common_name' => screwdriver_cn,
326     },
327     'docker-compose' => {
328       'config' => {
329         'services' => {
330           'reverseproxy' => {
331             'ports' => [
332               "#{screwdriver_ui_port}:9000"
333             ],
334             'environment' => {
335             },
336           },
337           'api' => {
338             #'ports' => [
339             #],
340             'environment' => {
341             },
342           },
343           'ui' => {
344             #'ports' => [
345             #],
346             'environment' => {
347             },
348           },
349           'store' => {
350             #'ports' => [
351             #],
352             'environment' => {
353             },
354           },
355         },
356       },
357     },
358   },
359   'hc-vault' => {
360     'with_ssl_cert_cookbook' => with_ssl,
361     'ssl_cert' => {
362       'common_name' => vault_cn,
363     },
364     'config' => {
365     },
366     'docker-compose' => {
367       'config' => {
368         'services' => {
369           'vault' => {
370             #'ports' => [
371             #],
372             'environment' => {
373               #'VAULT_LOCAL_CONFIG' => '',  # expanded to /vault/config/local.json
374             },
375           },
376         },
377       },
378     },
379   },
380 )