OSDN Git Service

symlinks docker-compose for sudo secure_path on RHEL family OS.
[metasearch/grid-chef-repo.git] / cookbooks / docker-grid / recipes / compose.rb
1 #
2 # Cookbook Name:: docker-grid
3 # Recipe:: compose
4 #
5 # Copyright 2016-2018, 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 # See: https://docs.docker.com/compose/install/
21
22 install_flavor = node['docker-grid']['compose']['install_flavor']
23
24 if node['docker-grid']['compose']['skip_setup']
25   log 'Skip the Docker Compose setup.'
26   return
27 end
28
29 include_recipe 'docker-grid::engine'
30
31 home_dir = node['docker-grid']['compose']['home_dir']
32 app_dir = node['docker-grid']['compose']['app_dir']
33 [
34   home_dir,
35   app_dir,
36 ].each {|dir|
37   resources(directory: dir) rescue directory dir do
38     owner 'root'
39     group 'root'
40     mode '0755'
41     recursive true
42   end
43 }
44
45 case install_flavor
46 when 'dockerproject'
47   docker_compose_path = '/usr/local/bin/docker-compose'
48   excepted_ver = node['docker-grid']['compose']['release_url'].match(/(\d+\.\d+.\d+)/)[1]
49
50   execute 'install_docker_compose' do
51     user 'root'
52     command "curl -L \"#{node['docker-grid']['compose']['release_url']}\" -o #{docker_compose_path} && chmod +x #{docker_compose_path}"
53     action :run
54     not_if "#{docker_compose_path} -v | grep #{excepted_ver},"
55     not_if { ::File.exist?(docker_compose_path) } unless node['docker-grid']['compose']['auto_upgrade']
56   end
57
58   # for sudo secure_path on RHEL family OS
59   link '/usr/sbin/docker-compose' do
60     to docker_compose_path
61     only_if { node['platform_family'] == 'rhel' }
62   end
63 when 'os-repository'
64   package 'docker-compose' do
65     action :install
66   end
67 end