OSDN Git Service

adds a oauth setting example.
[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       # 'web_encryption_key_vault_item' => {
196       #   'vault' => 'concourse',
197       #   'name' => 'web_encryption_key',
198       #   'env_context' => false,
199       #   'key' => 'ekey',  # real hash path: "/ekey"
200       # },
201       # 'web_oauth_client_id_vault_item' => {
202       #   'vault' => 'concourse',
203       #   'name' => 'web_oauth_client_id',
204       #   'env_context' => false,
205       #   'key' => 'cid',  # real hash path: "/cid"
206       # },
207       # 'web_oauth_client_secret_vault_item' => {
208       #   'vault' => 'concourse',
209       #   'name' => 'web_oauth_client_secret',
210       #   'env_context' => false,
211       #   'key' => 'secret',  # real hash path: "/secret"
212       # },
213       'config' => {
214         # Version 1 docker-compose format
215         'concourse-db' => {
216         },
217         'concourse-web' => {
218           'ports' => [
219             "#{concourse_port}:8443",
220           ],
221           'environment' => {
222             'CONCOURSE_TLS_BIND_PORT' => '8443',
223             'CONCOURSE_EXTERNAL_URL' => "https://#{concourse_cn}:#{concourse_port}",
224             # OAuth for the default `main`` team
225             #'CONCOURSE_GENERIC_OAUTH_DISPLAY_NAME' => 'GitLab',
226             #'CONCOURSE_GENERIC_OAUTH_AUTH_URL' => "https://#{gitlab_cn}/oauth/authorize",
227             #'CONCOURSE_GENERIC_OAUTH_TOKEN_URL' => "https://#{gitlab_cn}/oauth/token",
228           },
229         },
230         'concourse-worker' => {
231           'environment' => {
232           },
233         },
234       },
235     },
236   },
237   'gitlab-grid' => {
238     'with_ssl_cert_cookbook' => with_ssl,
239     'ssl_cert' => {
240       'ca_name' => ca_name,
241       'common_name' => gitlab_cn,
242       'registry' => {
243         'reuse_gitlab_common_name' => true,
244         # or
245         #'reuse_gitlab_common_name' => false,
246         #'common_name' => registry_gitlab_cn,
247       },
248     },
249     'gitlab.rb' => {
250       'external_url' => "https://#{gitlab_cn}:#{gitlab_https_port}",
251       'registry_external_url' => "https://#{gitlab_cn}:#{gitlab_reg_port}",  # not 5000 if same domain (common name)
252       'gitlab_rails' => {
253         #'ldap_enabled' => true,
254         #'ldap_servers' => YAML.load(ldap_servers),
255       },
256       'nginx' => {
257         'redirect_http_to_https' => true,
258       },
259       'registry_nginx' => {
260         'redirect_http_to_https' => true,
261       },
262     },
263     'docker-compose' => {
264       'config' => {
265         'services' => {
266           'gitlab' => {
267             'hostname' => gitlab_cn,
268             'ports' => [
269               "#{gitlab_https_port}:#{gitlab_https_port}",
270               "#{gitlab_reg_port}:#{gitlab_reg_port}",
271             ],
272           },
273         },
274       },
275     },
276     'runner-docker-compose' => {
277       'import_ca' => import_ca,
278     },
279   },
280   'jenkins-grid' => {
281     'with_ssl_cert_cookbook' => with_ssl,
282     'ssl_cert' => {
283       'common_name' => jenkins_cn,
284     },
285     'docker-compose' => {
286       'config' => {
287         'services' => {
288           'jenkins' => {
289             'ports' => [
290               "#{jenkins_port}:8083",
291             ],
292             'environment' => {
293               'JENKINS_OPTS' => [
294                 '--httpPort=-1 --httpsPort=8083',
295                 # These options will be set by the jenkins-grid::docker-compose recipe automatically.
296                 #'--httpsCertificate=/var/lib/jenkins/server.crt',
297                 #'--httpsPrivateKey=/var/lib/jenkins/server.key',
298               ].join(' '),
299             },
300           },
301         },
302       },
303     },
304   },
305   'nexus-grid' => {
306     'with_ssl_cert_cookbook' => with_ssl,
307     'ssl_cert' => {
308       'common_name' => nexus_cn,
309     },
310     'docker-compose' => {
311       'config' => {
312         'services' => {
313           'reverseproxy' => {
314             #'ports' => [
315             #],
316           },
317           'nexus' => {
318           },
319         },
320       },
321     },
322   },
323 )