OSDN Git Service

add RHEL family support.
[metasearch/grid-chef-repo.git] / cookbooks / kata-containers / recipes / default.rb
1 #
2 # Cookbook Name:: kata-containers
3 # Recipe:: default
4 #
5 # Copyright 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 platform = node['platform']
21
22 case platform
23 when 'centos', 'redhat'
24   [
25     'yum-utils',
26   ].each {|pkg_name|
27     resources(package: pkg_name) rescue package pkg_name do
28       action :install
29     end
30   }
31
32   bash 'add_kata-containers_repo' do
33     code <<-"EOH"
34       source /etc/os-release
35       yum-config-manager --add-repo "http://download.opensuse.org/repositories/home:/katacontainers:/release/CentOS_${VERSION_ID}/home:katacontainers:release.repo"
36     EOH
37     action :nothing
38     not_if "yum repolist | grep 'katacontainers'"
39   end
40
41   [
42     'kata-runtime',
43     'kata-proxy',
44     'kata-shim',
45   ].each {|pkg_name|
46     resources(package: pkg_name) rescue package pkg_name do
47       action :install
48       notifies :run, 'bash[add_kata-containers_repo]', :before
49     end
50   }
51 when 'ubuntu'
52   apt_get_update = 'apt-get_update'
53   resources(execute: apt_get_update) rescue execute apt_get_update do
54     command 'apt-get update'
55     action :nothing
56   end
57
58   bash 'add_kata-containers_apt_key' do
59     code <<-"EOH"
60       curl -sL http://download.opensuse.org/repositories/home:/katacontainers:/release/xUbuntu_$(lsb_release -rs)/Release.key | apt-key add -
61     EOH
62     action :nothing
63     not_if "apt-key list | grep 'katacontainers'"
64   end
65
66   bash 'add_kata-containers_apt_line' do
67     code <<-"EOH"
68       echo "deb http://download.opensuse.org/repositories/home:/katacontainers:/release/xUbuntu_$(lsb_release -rs)/ /" > /etc/apt/sources.list.d/kata-containers.list
69     EOH
70     action :nothing
71     not_if { File.exist?('/etc/apt/sources.list.d/kata-containers.list') }
72     notifies :run, 'bash[add_kata-containers_apt_key]', :before
73     notifies :run, "execute[#{apt_get_update}]", :immediately
74   end
75
76   [
77     'kata-runtime',
78     'kata-proxy',
79     'kata-shim',
80   ].each {|pkg_name|
81     resources(package: pkg_name) rescue package pkg_name do
82       action :install
83       notifies :run, 'bash[add_kata-containers_apt_line]', :before
84     end
85   }
86 end