OSDN Git Service

adds MySQL support.
[metasearch/grid-chef-repo.git] / cookbooks / screwdriver / attributes / default.rb
1 #
2 # Cookbook Name:: screwdriver
3 # Attributes:: default
4 #
5 # Copyright 2017, whitestar
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 default['screwdriver']['with_ssl_cert_cookbook'] = false
21 # If ['screwdriver']['with_ssl_cert_cookbook'] is true,
22 # node['screwdriver']['docker-compose']['config']
23 # are overridden by the following 'common_name' attributes.
24 default['screwdriver']['ssl_cert']['ca_names'] = []
25 default['screwdriver']['ssl_cert']['common_name'] = node['fqdn']
26 cn = node['screwdriver']['ssl_cert']['common_name']
27 cn = node['ipaddress'] if cn.nil? || cn.empty?
28
29 default['screwdriver']['jwt_private_key_vault_item'] = {
30 =begin
31   'vault' => 'screwdriver',
32   'name' => 'jwt_private_key',
33   # single password or nested hash password path delimited by slash
34   'env_context' => false,
35   'key' => 'private',  # real hash path: "/password"
36   # or nested hash password path delimited by slash
37   #'env_context' => true,
38   #'key' => 'hash/path/to/private',  # real hash path: "/#{node.chef_environment}/hash/path/to/private"
39 =end
40 }
41 default['screwdriver']['jwt_public_key_vault_item'] = {
42 =begin
43   'vault' => 'screwdriver',
44   'name' => 'jwt_public_key',
45   # single password or nested hash password path delimited by slash
46   'env_context' => false,
47   'key' => 'public',  # real hash path: "/password"
48   # or nested hash password path delimited by slash
49   #'env_context' => true,
50   #'key' => 'hash/path/to/public',  # real hash path: "/#{node.chef_environment}/hash/path/to/public"
51 =end
52 }
53 # A password used for encrypting session data. Needs to be minimum 32 characters
54 default['screwdriver']['cookie_password_vault_item'] = {
55 =begin
56   'vault' => 'screwdriver',
57   'name' => 'cookie_password',
58   # single password or nested hash password path delimited by slash
59   'env_context' => false,
60   'key' => 'password',  # real hash path: "/password"
61   # or nested hash password path delimited by slash
62   #'env_context' => true,
63   #'key' => 'hash/path/to/password',  # real hash path: "/#{node.chef_environment}/hash/path/to/password"
64 =end
65 }
66 # A password used for encrypting stored secrets. Needs to be minimum 32 characters
67 default['screwdriver']['password_vault_item'] = {
68 =begin
69   'vault' => 'screwdriver',
70   'name' => 'password',
71   # single password or nested hash password path delimited by slash
72   'env_context' => false,
73   'key' => 'password',  # real hash path: "/password"
74   # or nested hash password path delimited by slash
75   #'env_context' => true,
76   #'key' => 'hash/path/to/password',  # real hash path: "/#{node.chef_environment}/hash/path/to/password"
77 =end
78 }
79 default['screwdriver']['db_username_vault_item'] = {
80 =begin
81   'vault' => 'screwdriver',
82   'name' => 'db_username',
83   # single usernaem or nested hash username path delimited by slash
84   'env_context' => false,
85   'key' => 'username',  # real hash path: "/username"
86   # or nested hash password path delimited by slash
87   #'env_context' => true,
88   #'key' => 'hash/path/to/username',  # real hash path: "/#{node.chef_environment}/hash/path/to/username"
89 =end
90 }
91 default['screwdriver']['db_password_vault_item'] = {
92 =begin
93   'vault' => 'screwdriver',
94   'name' => 'db_password',
95   # single password or nested hash password path delimited by slash
96   'env_context' => false,
97   'key' => 'password',  # real hash path: "/password"
98   # or nested hash password path delimited by slash
99   #'env_context' => true,
100   #'key' => 'hash/path/to/password',  # real hash path: "/#{node.chef_environment}/hash/path/to/password"
101 =end
102 }
103 default['screwdriver']['db_root_password_vault_item'] = {
104 =begin
105   'vault' => 'screwdriver',
106   'name' => 'db_root_password',
107   # single password or nested hash password path delimited by slash
108   'env_context' => false,
109   'key' => 'password',  # real hash path: "/password"
110   # or nested hash password path delimited by slash
111   #'env_context' => true,
112   #'key' => 'hash/path/to/password',  # real hash path: "/#{node.chef_environment}/hash/path/to/password"
113 =end
114 }
115
116 force_override['screwdriver']['ui']['tls_setup_mode'] = 'reverseproxy'
117 # These hash objects are expanded to a `/config/local.yaml` file in each Docker container.
118 default['screwdriver']['api']['config'] = {
119   'auth' => {},
120   'httpd' => {
121     'tls' => false,
122   },
123   'executor' => {
124 =begin
125     # default
126     'plugin' => 'docker',
127     'docker' => {
128       'options' => {
129         'docker' => {
130           'socketPath' => '/var/run/docker.sock',
131         },
132         'launchVersion' => 'stable',
133       },
134     },
135 =end
136   },
137   'scms' => {
138 =begin
139     'scm_a' => {  # id and display name
140       'plugin' => 'github',
141       'config' => {
142         # These 3 secrets should be set by the following `['screwdriver']['api']['scms_vault_items']` attribute.
143         'oauthClientId' => 'YOU-PROBABLY-WANT-SOMETHING-HERE',  # The client id used for OAuth with github. GitHub OAuth (https://developer.github.com/v3/oauth/)
144         'oauthClientSecret' => 'AGAIN-SOMETHING-HERE-IS-USEFUL',  # The client secret used for OAuth with github
145         'secret' => 'SUPER-SECRET-SIGNING-THING',  # Secret to add to GitHub webhooks so that we can validate them
146         'gheHost' => 'github.screwdriver.cd',  # [Optional] GitHub enterprise host
147         'username' => 'sd-buildbot',  # [Optional] Username for code checkout
148         'email' => 'dev-null@screwdriver.cd',  # [Optional] Email for code checkout
149         'privateRepo' => false,  # [Optional] Set to true to support private repo; will need read and write access to public and private repos (https://developer.github.com/v3/oauth/#scopes)
150       },
151     },
152     'scm_b' => {  # id and display name
153       'plugin' => 'bitbucket',
154       'config' => {
155         'oauthClientId' => 'YOUR-APP-KEY',
156         'oauthClientSecret' => 'YOUR-APP-SECRET',
157       },
158     },
159 =end
160   },
161 }
162 default['screwdriver']['api']['scms_vault_items'] = {
163 =begin
164   'scm_a' => {
165     'oauthClientId' => {
166       'vault' => 'screwdriver',
167       'name' => 'scm_a',
168       # single oauthClientId or nested hash oauthClientId path delimited by slash
169       'env_context' => false,
170       'key' => 'oauthClientId',  # real hash path: "/oauthClientId", Note: do not use `id`, which is preserved by Chef Vault.
171       # or nested hash id path delimited by slash
172       #'env_context' => true,
173       #'key' => 'hash/path/to/oauthClientId',  # real hash path: "/#{node.chef_environment}/hash/path/to/oauthClientId"
174     },
175     'oauthClientSecret' => {
176       'vault' => 'screwdriver',
177       'name' => 'scm_a',
178       # single oauthClientSecret or nested hash oauthClientSecret path delimited by slash
179       'env_context' => false,
180       'key' => 'oauthClientSecret',  # real hash path: "/oauthClientSecret"
181       # or nested hash secret path delimited by slash
182       #'env_context' => true,
183       #'key' => 'hash/path/to/oauthClientSecret',  # real hash path: "/#{node.chef_environment}/hash/path/to/oauthClientSecret"
184     },
185     # GitHub only.
186     'secret' => {
187       'vault' => 'screwdriver',
188       'name' => 'scm_a',
189       # single secret or nested hash secret path delimited by slash
190       'env_context' => false,
191       'key' => 'secret',  # real hash path: "/secret"
192       # or nested hash password path delimited by slash
193       #'env_context' => true,
194       #'key' => 'hash/path/to/secret',  # real hash path: "/#{node.chef_environment}/hash/path/to/secret"
195     },
196   },
197   'scm_b' => {
198     # ...
199   },
200   # ...
201 =end
202 }
203
204 default['screwdriver']['store']['config'] = {
205   'auth' => {},
206   'httpd' => {
207     'tls' => false,
208   },
209 }
210
211 # Useless?!
212 force_override['screwdriver']['docker-compose']['import_ca'] = false
213 default['screwdriver']['docker-compose']['app_dir'] = "#{node['docker-grid']['compose']['app_dir']}/screwdriver"
214 default['screwdriver']['docker-compose']['bin_dir'] = "#{node['screwdriver']['docker-compose']['app_dir']}/bin"
215 default['screwdriver']['docker-compose']['config_dir'] = "#{node['screwdriver']['docker-compose']['app_dir']}/config"
216 default['screwdriver']['docker-compose']['data_dir'] = "#{node['screwdriver']['docker-compose']['app_dir']}/data"
217 default['screwdriver']['docker-compose']['etc_dir'] = "#{node['screwdriver']['docker-compose']['app_dir']}/etc"
218 default['screwdriver']['docker-compose']['jwt_private_key_reset'] = false
219
220 # **DEPRECATED**: use ['screwdriver']['(jwt|cookie|password)_*_vault_item'] attributes.
221 default['screwdriver']['docker-compose']['jwt_private_key_vault_item'] = {}
222 default['screwdriver']['docker-compose']['jwt_public_key_vault_item'] = {}
223 default['screwdriver']['docker-compose']['cookie_password_vault_item'] = {}
224 default['screwdriver']['docker-compose']['password_vault_item'] = {}
225
226 # **DEPRECATED**: use the above `['screwdriver']['api']['scms_vault_items']` attribute.
227 default['screwdriver']['docker-compose']['oauth_client_id_vault_item'] = {
228 =begin
229   'vault' => 'screwdriver',
230   'name' => 'oauth_client_id',
231   # single cid or nested hash cid path delimited by slash
232   'env_context' => false,
233   'key' => 'cid',  # real hash path: "/cid", Note: do not use `id`, which is preserved by Chef Vault.
234   # or nested hash id path delimited by slash
235   #'env_context' => true,
236   #'key' => 'hash/path/to/cid',  # real hash path: "/#{node.chef_environment}/hash/path/to/cid"
237 =end
238 }
239 # **DEPRECATED**: use the above `['screwdriver']['api']['scms_vault_items']` attribute.
240 default['screwdriver']['docker-compose']['oauth_client_secret_vault_item'] = {
241 =begin
242   'vault' => 'screwdriver',
243   'name' => 'oauth_client_secret',
244   # single secret or nested hash secret path delimited by slash
245   'env_context' => false,
246   'key' => 'secret',  # real hash path: "/secret"
247   # or nested hash secret path delimited by slash
248   #'env_context' => true,
249   #'key' => 'hash/path/to/secret',  # real hash path: "/#{node.chef_environment}/hash/path/to/secret"
250 =end
251 }
252 # **DEPRECATED**: use the above `['screwdriver']['api']['scms_vault_items']` attribute.
253 default['screwdriver']['docker-compose']['webhook_github_secret_vault_item'] = {
254 =begin
255   'vault' => 'screwdriver',
256   'name' => 'webhook_github_secret',
257   # single password or nested hash password path delimited by slash
258   'env_context' => false,
259   'key' => 'secret',  # real hash path: "/secret"
260   # or nested hash password path delimited by slash
261   #'env_context' => true,
262   #'key' => 'hash/path/to/secret',  # real hash path: "/#{node.chef_environment}/hash/path/to/secret"
263 =end
264 }
265
266 # ref: https://github.com/screwdriver-cd/screwdriver/blob/master/in-a-box.py
267 force_override['screwdriver']['docker-compose']['config_format_version'] = '2'
268 version_2_config = {
269   # Version 2 docker-compose format
270   'version' => '2',
271   'services' => {
272     # this service will be active if the `['screwdriver']['with_ssl_cert_cookbook']` attribute is true.
273     'reverseproxy' => {
274       'depends_on' => [
275         'ui',
276       ],
277       'restart' => 'always',
278       'image' => 'nginx:alpine',
279       'expose' => [
280         '9000',
281       ],
282       'ports' => [
283         #'9000:9000',  # default
284       ],
285       'volumes' => [
286         # This volume will be set by the screwdriver::docker-compose recipe automatically.
287         #"#{node['screwdriver']['docker-compose']['etc_dir']}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro",
288       ],
289     },
290     'api' => {
291       'image' => 'screwdrivercd/screwdriver:latest',
292       'command' => 'npm start',  # the original command in the Dockerfile.
293       'ports' => [
294         #'9001:80',  # default
295       ],
296       'volumes' => [
297         '/var/run/docker.sock:/var/run/docker.sock:rw',
298         # This volume will be set by the screwdriver::docker-compose recipe automatically.
299         #"#{node['screwdriver']['docker-compose']['data_dir']}:/sd-data:rw",  # for sqlite
300       ],
301       'environment' => {
302         # See:
303         # http://docs.screwdriver.cd/cluster-management/configure-api
304         # https://github.com/screwdriver-cd/screwdriver/blob/master/config/custom-environment-variables.yaml
305         'PORT' => '80',
306         'URI' => "http://#{cn}:9001",
307         #'URI' => "http://#{node['ipaddress']}:9001",  # unrecommended
308         # These vriables will be set by the screwdriver::docker-compose recipe automatically.
309         #'ECOSYSTEM_UI' => "http://#{cn}:9000",                 # Better
310         #'ECOSYSTEM_UI' => "http://#{node['ipaddress']}:9000",  # unrecommended
311         #'ECOSYSTEM_UI' => 'http://ui',                         # NG: for an access from a client.
312         #'ECOSYSTEM_STORE' => "http://#{cn}:9002",                 # Better
313         #'ECOSYSTEM_STORE' => "http://#{node['ipaddress']}:9002",  # unrecommended
314         #'ECOSYSTEM_STORE' => 'http://store',
315         'SECRET_WHITELIST' => '[]',
316         'SECRET_ADMINS' => '[]',
317         'DATASTORE_PLUGIN' => 'sequelize',
318         'DATASTORE_SEQUELIZE_DATABASE' => 'screwdriver',
319         'DATASTORE_SEQUELIZE_DIALECT' => 'sqlite',
320         # This variable will be set by the screwdriver::docker-compose recipe automatically.
321         #'DATASTORE_SEQUELIZE_STORAGE' => '/sd-data/storage.db',
322         # for MySQL
323         #'DATASTORE_SEQUELIZE_DIALECT' => 'mysql',
324         # These variables will be set by the screwdriver::docker-compose recipe automatically.
325         #'DATASTORE_SEQUELIZE_USERNAME' => '${DB_USERNAME}',
326         #'DATASTORE_SEQUELIZE_PASSWORD' => '${DB_PASSWORD}',
327         #'DATASTORE_SEQUELIZE_HOST' => 'db',
328         # This variable will be set by the screwdriver::docker-compose recipe automatically.
329         #'IS_HTTPS' => 'false',
330         #'NODE_TLS_REJECT_UNAUTHORIZED' => '0',  # workaround for self-signed cetificates
331 =begin
332         # **DEPRECATED**: use the `['screwdriver']['api']['config']['executor']` attribute.
333         'EXECUTOR_PLUGIN' => 'docker',
334         'EXECUTOR_DOCKER_DOCKER' => <<-'EOS',
335 {
336   "socketPath": "/var/run/docker.sock"
337 }
338 EOS
339 =end
340 =begin
341         # SCM settings
342         # **DEPRECATED**: Please use the above `['screwdriver']['api']['config']['scms']` attribute
343         # instead of `SCM_SETTINGS` env. variable.
344         # 'SCM_SETTINGS' => '{}',
345         #
346         # **DEPRECATED**: Non-Multiple SCMs setting format.
347         #   - Note: Multiple SCMs not supported yet.
348         #     https://github.com/screwdriver-cd/screwdriver/issues/365
349         #   - OAuth Callback URL: "http://#{cn}:9001/v4/auth/login/web"
350         'SCM_PLUGIN' => 'github',  # or 'gitlab' or 'bitbucket'
351         # * Commons
352         'SCM_USERNAME' => 'sd-buildbot',
353         'SCM_EMAIL' => 'dev-null@screwdriver.cd',
354         # The following variables will be set by the screwdriver::docker-compose recipe automatically.
355         'SECRET_OAUTH_CLIENT_ID' => '${SECRET_OAUTH_CLIENT_ID}',
356         'SECRET_OAUTH_CLIENT_SECRET' => '${SECRET_OAUTH_CLIENT_SECRET}',
357         # * GitHub only
358         'WEBHOOK_GITHUB_SECRET' => '${WEBHOOK_GITHUB_SECRET}',  #'SUPER-SECRET-SIGNING-THING'
359         'SCM_GITHUB_GHE_HOST' => 'gitlab.io.example.com',  # for GHE
360         'SCM_PRIVATE_REPO_SUPPORT' => 'false',
361         # * GitLab only
362         #'SCM_GITLAB_HOST' => 'gitlab.io.example.com',
363         #'SCM_GITLAB_PROTOCOL' => 'https',
364         # * Bitbucket only
365         #   None.
366 =end
367       },
368     },
369     'ui' => {
370       'image' => 'screwdrivercd/ui:latest',
371       'ports' => [
372         #'9000:80',  # default
373       ],
374       'environment' => {
375         # These variables will be set by the screwdriver::docker-compose recipe automatically.
376         #'ECOSYSTEM_API' => 'http://api',                        # NG: for an access from a client.
377         #'ECOSYSTEM_API' => "http://#{cn}:9001",                 # Better
378         #'ECOSYSTEM_API' => "http://#{node['ipaddress']}:9001",  # unrecommended
379         #'ECOSYSTEM_STORE' => 'http://store',
380         #'ECOSYSTEM_STORE' => "http://#{cn}:9002",                 # Better
381         #'ECOSYSTEM_STORE' => "http://#{node['ipaddress']}:9002",  # unrecommended
382       },
383     },
384     'store' => {
385       'image' => 'screwdrivercd/store:latest',
386       'ports' => [
387         #'9002:80',  # default
388       ],
389       'environment' => {
390         # See https://github.com/screwdriver-cd/store/blob/master/config/custom-environment-variables.yaml
391         'PORT' => '80',
392         'URI' => "http://#{cn}:9002",
393         #'URI' => "http://#{node['ipaddress']}:9002",  # unrecommended
394         #'STRATEGY' => 'memory',
395         # This variable will be set by the screwdriver::docker-compose recipe automatically.
396         #'ECOSYSTEM_UI' => "http://#{cn}:9000",  # Better
397         #'ECOSYSTEM_UI' => "http://#{node['ipaddress']}:9000",
398         #'ECOSYSTEM_UI' => 'http://ui',          # NG for an access from a client.
399       },
400     },
401   },
402 }
403
404 config_srvs = node['screwdriver']['docker-compose']['config']['services']
405 case config_srvs['api']['environment']['DATASTORE_SEQUELIZE_DIALECT']
406 when 'mysql'
407   version_2_config['services']['db'] = {
408     'image' => 'mysql:5',
409     'volumes' => [
410       # This variable will be set by the screwdriver::docker-compose recipe automatically.
411       #"#{node['screwdriver']['docker-compose']['data_dir']}/mysql:/var/lib/mysql:rw",
412     ],
413     'environment' => {
414       # These variables will be set by the screwdriver::docker-compose recipe automatically.
415       #'MYSQL_ROOT_PASSWORD' => '${DB_ROOT_PASSWORD}',
416       #'MYSQL_USER' => '${DB_USERNAME}',
417       #'MYSQL_PASSWORD' => '${DB_PASSWORD}',
418       #'MYSQL_DATABASE' => 'screwdriver',
419     },
420   }
421 end
422
423 default['screwdriver']['docker-compose']['config'] = version_2_config