OSDN Git Service

adds the ['docker-grid']['registry']['docker-compose']['host_data_volume'] attribute.
[metasearch/grid-chef-repo.git] / cookbooks / docker-grid / recipes / registry.rb
1 #
2 # Cookbook Name:: docker-grid
3 # Recipe:: registry
4 #
5 # Copyright 2016, 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 doc_url = 'https://docs.docker.com/registry/deploying/#/managing-with-compose'
21
22 include_recipe 'docker-grid::compose'
23
24 app_dir = node['docker-grid']['registry']['docker-compose']['app_dir']
25 auth_dir = "#{app_dir}/auth"
26 etc_dir = "#{app_dir}/etc"
27 [
28   app_dir,
29   auth_dir,
30   etc_dir,
31 ].each {|dir|
32   resources(directory: dir) rescue directory dir do
33     owner 'root'
34     group 'root'
35     mode '0755'
36     recursive true
37   end
38 }
39
40 environment = {}
41 volumes = []
42
43 host_data_volume = node['docker-grid']['registry']['docker-compose']['host_data_volume']
44 unless host_data_volume.nil?
45   directory host_data_volume do
46     owner 'root'
47     group 'root'
48     mode '0755'
49     recursive true
50   end
51
52   volumes.push("#{host_data_volume}:/var/lib/registry")
53 end
54
55 if node['docker-grid']['registry']['with_ssl_cert_cookbook']
56   ::Chef::Recipe.send(:include, SSLCert::Helper)
57   cn = node['docker-grid']['registry']['ssl_cert']['common_name']
58
59   environment['REGISTRY_HTTP_TLS_CERTIFICATE'] = '/certs/domain.crt'
60   environment['REGISTRY_HTTP_TLS_KEY'] = '/certs/domain.key'
61   volumes.push("#{server_cert_path(cn)}:/certs/domain.crt:ro")
62   volumes.push("#{server_key_path(cn)}:/certs/domain.key:ro")
63 end
64
65 unless node['docker-grid']['registry']['docker-compose']['registry-config'].nil?
66   template "#{app_dir}/etc/config.yml" do
67     source  'opt/docker-compose/app/registry/etc/config.yml'
68     owner 'root'
69     group 'root'
70     mode '0644'
71   end
72
73   volumes.push('./etc/config.yml:/etc/docker/registry/config.yml:ro')
74 end
75
76 service_name = node['docker-grid']['registry']['docker-compose']['service_name']
77 version_1_config = {
78   service_name => {
79   },
80 }
81
82 version_1_config[service_name]['environment'] = environment unless environment.empty?
83 version_1_config[service_name]['volumes'] = volumes unless volumes.empty?
84
85 version_2_config = {
86   'services' => version_1_config,
87 }
88
89 node.override['docker-grid']['registry']['docker-compose']['config'] = \
90   node['docker-grid']['registry']['docker-compose']['config_format_version'] == '2' ? version_2_config : version_1_config
91
92 [
93   'docker-compose.yml',
94 ].each {|conf_file|
95   template "#{app_dir}/#{conf_file}" do
96     source  "opt/docker-compose/app/registry/#{conf_file}"
97     owner 'root'
98     group 'root'
99     mode '0644'
100   end
101 }
102
103 log <<-"EOM"
104 Note: You must execute the following command manually.
105   See #{doc_url}
106   - Start:
107     $ cd #{app_dir}
108     $ docker-compose up -d
109   - Stop
110     $ docker-compose down
111 EOM