2 # Cookbook Name:: jenkins-grid
3 # Recipe:: docker-compose
5 # Copyright 2016-2017, whitestar
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 doc_url = 'https://hub.docker.com/_/jenkins/'
22 include_recipe 'docker-grid::compose'
24 config = node['jenkins-grid']['docker-compose']['config']
25 override_config = node.override['jenkins-grid']['docker-compose']['config']
26 force_override_config = node.force_override['jenkins-grid']['docker-compose']['config']
27 app_dir = node['jenkins-grid']['docker-compose']['app_dir']
28 certs_dir = "#{app_dir}/certs"
29 groovy_dir = "#{app_dir}/ref/init.groovy.d"
34 vols = config['services']['jenkins']['volumes'].to_a
41 resources(directory: dir) rescue directory dir do
49 ports = config['services']['jenkins']['ports']
50 override_config['services']['jenkins']['ports'] = ['8080:8080', '50000:50000'] if ports.empty?
52 jenkins_owner = node['jenkins-grid']['docker-compose']['jenkins_home']['owner']
53 jenkins_home_path = node['jenkins-grid']['docker-compose']['jenkins_home']['path']
54 unless jenkins_home_path.nil?
55 directory jenkins_home_path do
61 vols.push("#{jenkins_home_path}:/var/jenkins_home")
63 template "#{jenkins_home_path}/log.properties" do
64 source 'var/lib/jenkins_home/log.properties'
69 java_opts.push('-Djava.util.logging.config.file=/var/jenkins_home/log.properties')
72 if node['jenkins-grid']['with_ssl_cert_cookbook']
73 ::Chef::Recipe.send(:include, SSLCert::Helper)
74 cn = node['jenkins-grid']['ssl_cert']['common_name']
75 append_server_ssl_cn(cn)
76 include_recipe 'ssl_cert::server_key_pairs'
77 key_path = server_key_path(cn)
79 bash 'copy_ssl_server_key_for_jenkins' do
81 cp #{key_path} #{certs_dir}/server.key
82 chown #{jenkins_owner} #{certs_dir}/server.key
83 chmod 600 #{certs_dir}/server.key
87 not_if "cmp #{key_path} #{certs_dir}/server.key"
89 #subscribes :run, "file[#{key_path}]"
92 vols.push("#{server_cert_path(cn)}:/var/lib/jenkins/server.crt:ro")
93 vols.push("#{certs_dir}/server.key:/var/lib/jenkins/server.key:ro")
94 jenkins_opts.push('--httpsCertificate=/var/lib/jenkins/server.crt')
95 jenkins_opts.push('--httpsPrivateKey=/var/lib/jenkins/server.key')
98 executors_conf = 'ref/init.groovy.d/executors.groovy'
99 vols.push("#{app_dir}/#{executors_conf}:/usr/share/jenkins/#{executors_conf}:ro")
101 unless jenkins_opts.empty?
102 if !config['services']['jenkins']['environment'].nil? \
103 && !config['services']['jenkins']['environment']['JENKINS_OPTS'].nil?
104 jenkins_opts.unshift(config['services']['jenkins']['environment']['JENKINS_OPTS'])
106 envs['JENKINS_OPTS'] = jenkins_opts.join(' ')
109 unless java_opts.empty?
110 if !config['services']['jenkins']['environment'].nil? \
111 && !config['services']['jenkins']['environment']['JAVA_OPTS'].nil?
112 java_opts.unshift(config['services']['jenkins']['environment']['JAVA_OPTS'])
114 envs['JAVA_OPTS'] = java_opts.join(' ')
117 # force_override for merging JENKINS_OPTS and JAVA_OPTS attributes' value.
118 force_override_config['services']['jenkins']['environment'] = envs unless envs.empty?
119 override_config['services']['jenkins']['volumes'] = vols unless vols.empty?
122 'docker-compose.yml',
123 'ref/init.groovy.d/executors.groovy',
125 template "#{app_dir}/#{conf_file}" do
126 source "opt/docker-compose/app/jenkins/#{conf_file}"
134 Note: You must execute the following command manually.
138 $ docker-compose up -d
140 $ docker-compose down