OSDN Git Service

improves devops-suite roles.
[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 concourse_cn = host_cn   # e.g. 'concourse.io.example.com'
35 concourse_port    = '8443'
36 docker_reg_cn = host_cn  # e.g. 'registry.docker.example.com'
37 docker_reg_port   = '5000'
38 docker_reg_data_vol = '/opt/docker-compose/app/registry/data'
39 gitlab_cn = host_cn      # e.g. 'gitlab.io.example.com'
40 gitlab_https_port =  '443'
41 gitlab_reg_port   = '5050'
42 jenkins_cn = host_cn     # e.g. 'jenkins.io.example.com'
43 jenkins_port      = '9083'
44 nexus_cn = host_cn       # e.g. 'nexus.io.example.com'
45 dockerd_extra_opts = [
46   '-H fd://',
47   '--bip=192.168.100.1/24 --fixed-cidr=192.168.100.0/24',
48   #"--registry-mirror=https://#{docker_reg_cn}:#{docker_reg_port}",
49 ].join(' ')
50
51 # for debug
52 with_ssl = true
53
54 common_names = [
55   host_cn,
56   aptly_cn,
57   concourse_cn,
58   docker_reg_cn,
59   gitlab_cn,
60   jenkins_cn,
61   nexus_cn,
62 ].compact.uniq
63
64 # for GitLab
65 ldap_servers = <<-'EOS'
66 main: # 'main' is the GitLab 'provider ID' of this LDAP server
67   label: 'LDAP'
68   host: 'ldap.grid.example.com'
69   port: 389
70   uid: 'uid'  # 'sAMAccountName'
71   method: 'tls' # "tls" or "ssl" or "plain"
72   #bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
73   #password: '_the_password_of_the_bind_user'
74   active_directory: false
75   allow_username_or_email_login: false
76   block_auto_created_users: false
77   base: 'ou=Users,dc=grid,dc=example,dc=com'
78   #user_filter: ''
79   attributes:
80     username: ['uid', 'userid', 'sAMAccountName']
81     email:    ['mail', 'email', 'userPrincipalName']
82     name:       'cn'
83     first_name: 'givenName'
84     last_name:  'sn'
85   ## EE only
86   #group_base: ''
87   #admin_group: ''
88   #sync_ssh_keys: false
89 #
90 #secondary: # 'secondary' is the GitLab 'provider ID' of second LDAP server
91 #  label: 'LDAP'
92 #  host: '_your_ldap_server'
93 #  port: 389
94 #  uid: 'sAMAccountName'
95 #  method: 'plain' # "tls" or "ssl" or "plain"
96 #  bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
97 #  password: '_the_password_of_the_bind_user'
98 #  active_directory: true
99 #  allow_username_or_email_login: false
100 #  block_auto_created_users: false
101 #  base: ''
102 #  user_filter: ''
103 #  attributes:
104 #    username: ['uid', 'userid', 'sAMAccountName']
105 #    email:    ['mail', 'email', 'userPrincipalName']
106 #    name:       'cn'
107 #    first_name: 'givenName'
108 #    last_name:  'sn'
109 #  ## EE only
110 #  group_base: ''
111 #  admin_group: ''
112 #  sync_ssh_keys: false
113 EOS
114
115 run_list(
116   'role[devops-suite-on-docker]',
117   'recipe[docker-grid::registry]',
118 )
119
120 #env_run_lists()
121
122 #default_attributes()
123
124 override_attributes(
125   'ssl_cert' => {
126     'ca_names' => [
127       ca_name,
128     ],
129     'common_names' => common_names,
130   },
131   'docker-grid' => {
132     'engine' => {
133       'skip_setup' => false,
134       'daemon_extra_options' => dockerd_extra_opts,
135     },
136     'compose' => {
137       'skip_setup' => false,
138     },
139     'registry' => {
140       'with_ssl_cert_cookbook' => with_ssl,
141       'ssl_cert' => {
142         'common_name' => docker_reg_cn,
143       },
144       'docker-compose' => {
145         'host_data_volume' => docker_reg_data_vol,
146         'config' => {
147           'registry' => {
148             'ports' => [
149               "#{docker_reg_port}:5000",
150             ],
151             'environment' => {
152               #'REGISTRY_AUTH' =>                'htpasswd',
153               #'REGISTRY_AUTH_HTPASSWD_PATH' =>  '/auth/.htpasswd',
154               #'REGISTRY_AUTH_HTPASSWD_REALM' => 'Registry Realm',
155               # proxy cache only.
156               'REGISTRY_PROXY_REMOTEURL' => 'https://registry-1.docker.io',
157             },
158             #'volumes' => [
159             #],
160           },
161         },
162       },
163     },
164   },
165   'apt_utils' => {
166     'aptly' => {
167       'with_ssl_cert_cookbook' => with_ssl,
168       'ssl_cert' => {
169         'common_name' => aptly_cn,
170       },
171       'docker-compose' => {
172         'config' => {
173           'services' => {
174             'reverseproxy' => {
175               #'ports' => [
176               #],
177             },
178             'aptly' => {
179             },
180           },
181         },
182       },
183     },
184   },
185   'concourse-ci' => {
186     'with_ssl_cert_cookbook' => with_ssl,
187     'ssl_cert' => {
188       'ca_names' => [
189         ca_name,
190       ],
191       'common_name' => concourse_cn,
192     },
193     'docker-compose' => {
194       'import_ca' => import_ca,
195       'config' => {
196         # Version 1 docker-compose format
197         'concourse-db' => {
198         },
199         'concourse-web' => {
200           'ports' => [
201             "#{concourse_port}:8443",
202           ],
203           'environment' => {
204             'CONCOURSE_TLS_BIND_PORT' => '8443',
205             'CONCOURSE_EXTERNAL_URL' => "https://#{concourse_cn}:#{concourse_port}",
206           },
207         },
208         'concourse-worker' => {
209           'environment' => {
210           },
211         },
212       },
213     },
214   },
215   'gitlab-grid' => {
216     'with_ssl_cert_cookbook' => with_ssl,
217     'ssl_cert' => {
218       'ca_name' => ca_name,
219       'common_name' => gitlab_cn,
220       'registry' => {
221         'reuse_gitlab_common_name' => true,
222         # or
223         #'reuse_gitlab_common_name' => false,
224         #'common_name' => registry_gitlab_cn,
225       },
226     },
227     'gitlab.rb' => {
228       'external_url' => "https://#{gitlab_cn}:#{gitlab_https_port}",
229       'registry_external_url' => "https://#{gitlab_cn}:#{gitlab_reg_port}",  # not 5000 if same domain (common name)
230       'gitlab_rails' => {
231         #'ldap_enabled' => true,
232         #'ldap_servers' => YAML.load(ldap_servers),
233       },
234       'nginx' => {
235         'redirect_http_to_https' => true,
236       },
237       'registry_nginx' => {
238         'redirect_http_to_https' => true,
239       },
240     },
241     'docker-compose' => {
242       'config' => {
243         'services' => {
244           'gitlab' => {
245             'hostname' => gitlab_cn,
246             'ports' => [
247               "#{gitlab_https_port}:#{gitlab_https_port}",
248               "#{gitlab_reg_port}:#{gitlab_reg_port}",
249             ],
250           },
251         },
252       },
253     },
254     'runner-docker-compose' => {
255       'import_ca' => import_ca,
256     },
257   },
258   'jenkins-grid' => {
259     'with_ssl_cert_cookbook' => with_ssl,
260     'ssl_cert' => {
261       'common_name' => jenkins_cn,
262     },
263     'docker-compose' => {
264       'config' => {
265         'services' => {
266           'jenkins' => {
267             'ports' => [
268               "#{jenkins_port}:8083",
269             ],
270             'environment' => {
271               'JENKINS_OPTS' => [
272                 '--httpPort=-1 --httpsPort=8083',
273                 # These options will be set by the jenkins-grid::docker-compose recipe automatically.
274                 #'--httpsCertificate=/var/lib/jenkins/server.crt',
275                 #'--httpsPrivateKey=/var/lib/jenkins/server.key',
276               ].join(' '),
277             },
278           },
279         },
280       },
281     },
282   },
283   'nexus-grid' => {
284     'with_ssl_cert_cookbook' => with_ssl,
285     'ssl_cert' => {
286       'common_name' => nexus_cn,
287     },
288     'docker-compose' => {
289       'config' => {
290         'services' => {
291           'reverseproxy' => {
292             #'ports' => [
293             #],
294           },
295           'nexus' => {
296           },
297         },
298       },
299     },
300   },
301 )