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 include_recipe 'ssl_cert::server_key_pairs'
74 ::Chef::Recipe.send(:include, SSLCert::Helper)
75 cn = node['jenkins-grid']['ssl_cert']['common_name']
76 key_path = server_key_path(cn)
78 bash 'copy_ssl_server_key_for_jenkins' do
80 cp #{key_path} #{certs_dir}/server.key
81 chown #{jenkins_owner} #{certs_dir}/server.key
82 chmod 600 #{certs_dir}/server.key
86 not_if "cmp #{key_path} #{certs_dir}/server.key"
88 #subscribes :run, "file[#{key_path}]"
91 vols.push("#{server_cert_path(cn)}:/var/lib/jenkins/server.crt:ro")
92 vols.push("#{certs_dir}/server.key:/var/lib/jenkins/server.key:ro")
93 jenkins_opts.push('--httpsCertificate=/var/lib/jenkins/server.crt')
94 jenkins_opts.push('--httpsPrivateKey=/var/lib/jenkins/server.key')
97 executors_conf = 'ref/init.groovy.d/executors.groovy'
98 vols.push("#{app_dir}/#{executors_conf}:/usr/share/jenkins/#{executors_conf}:ro")
100 unless jenkins_opts.empty?
101 if !config['services']['jenkins']['environment'].nil? \
102 && !config['services']['jenkins']['environment']['JENKINS_OPTS'].nil?
103 jenkins_opts.unshift(config['services']['jenkins']['environment']['JENKINS_OPTS'])
105 envs['JENKINS_OPTS'] = jenkins_opts.join(' ')
108 unless java_opts.empty?
109 if !config['services']['jenkins']['environment'].nil? \
110 && !config['services']['jenkins']['environment']['JAVA_OPTS'].nil?
111 java_opts.unshift(config['services']['jenkins']['environment']['JAVA_OPTS'])
113 envs['JAVA_OPTS'] = java_opts.join(' ')
116 # force_override for merging JENKINS_OPTS and JAVA_OPTS attributes' value.
117 force_override_config['services']['jenkins']['environment'] = envs unless envs.empty?
118 override_config['services']['jenkins']['volumes'] = vols unless vols.empty?
121 'docker-compose.yml',
122 'ref/init.groovy.d/executors.groovy',
124 template "#{app_dir}/#{conf_file}" do
125 source "opt/docker-compose/app/jenkins/#{conf_file}"
133 Note: You must execute the following command manually.
137 $ docker-compose up -d
139 $ docker-compose down