From 882a31223044d289728fbd66588d732e09e7b679 Mon Sep 17 00:00:00 2001 From: whitestar Date: Thu, 19 Jul 2018 17:46:28 +0900 Subject: [PATCH] add repository update flag. --- cookbooks/kata-containers/CHANGELOG.md | 4 +++ cookbooks/kata-containers/README.md | 1 + cookbooks/kata-containers/attributes/default.rb | 20 ++++++++++++ cookbooks/kata-containers/recipes/default.rb | 15 +++++++-- cookbooks/kata-containers/version | 2 +- nodes/local-kata-containers.json | 5 +++ roles/kata-containers.rb | 41 +++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 cookbooks/kata-containers/attributes/default.rb create mode 100644 nodes/local-kata-containers.json create mode 100644 roles/kata-containers.rb diff --git a/cookbooks/kata-containers/CHANGELOG.md b/cookbooks/kata-containers/CHANGELOG.md index 1e220c4..720ab3c 100644 --- a/cookbooks/kata-containers/CHANGELOG.md +++ b/cookbooks/kata-containers/CHANGELOG.md @@ -1,5 +1,9 @@ # kata-containers CHANGELOG +0.3.0 +----- +- add repository update flag + 0.2.1 ----- - update documents. diff --git a/cookbooks/kata-containers/README.md b/cookbooks/kata-containers/README.md index 54d0ce1..b37be75 100644 --- a/cookbooks/kata-containers/README.md +++ b/cookbooks/kata-containers/README.md @@ -29,6 +29,7 @@ This cookbook installs Kata Containers. |Key|Type|Description, example|Default| |:--|:--|:--|:--| +|`['kata-containers']['repo']['update']`|Boolean|Repository update flag.|`false`| ## Usage diff --git a/cookbooks/kata-containers/attributes/default.rb b/cookbooks/kata-containers/attributes/default.rb new file mode 100644 index 0000000..cd6904e --- /dev/null +++ b/cookbooks/kata-containers/attributes/default.rb @@ -0,0 +1,20 @@ +# +# Cookbook Name:: kata-containers +# Attributes:: default +# +# Copyright 2018, whitestar +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default['kata-containers']['repo']['update'] = false diff --git a/cookbooks/kata-containers/recipes/default.rb b/cookbooks/kata-containers/recipes/default.rb index 6439de0..6ba707f 100644 --- a/cookbooks/kata-containers/recipes/default.rb +++ b/cookbooks/kata-containers/recipes/default.rb @@ -32,10 +32,13 @@ when 'centos', 'redhat' bash 'add_kata-containers_repo' do code <<-"EOH" source /etc/os-release + if [ -f /etc/yum.repos.d/*katacontainers*.repo ]; then + rm /etc/yum.repos.d/*katacontainers*.repo + fi yum-config-manager --add-repo "http://download.opensuse.org/repositories/home:/katacontainers:/release/CentOS_${VERSION_ID}/home:katacontainers:release.repo" EOH action :nothing - not_if "yum repolist | grep 'katacontainers'" + not_if "yum repolist | grep 'katacontainers'" unless node['kata-containers']['repo']['update'] end [ @@ -49,6 +52,14 @@ when 'centos', 'redhat' end } when 'ubuntu' + [ + 'curl', + ].each {|pkg_name| + resources(package: pkg_name) rescue package pkg_name do + action :install + end + } + apt_get_update = 'apt-get_update' resources(execute: apt_get_update) rescue execute apt_get_update do command 'apt-get update' @@ -68,7 +79,7 @@ when 'ubuntu' echo "deb http://download.opensuse.org/repositories/home:/katacontainers:/release/xUbuntu_$(lsb_release -rs)/ /" > /etc/apt/sources.list.d/kata-containers.list EOH action :nothing - not_if { File.exist?('/etc/apt/sources.list.d/kata-containers.list') } + not_if { File.exist?('/etc/apt/sources.list.d/kata-containers.list') } unless node['kata-containers']['repo']['update'] notifies :run, 'bash[add_kata-containers_apt_key]', :before notifies :run, "execute[#{apt_get_update}]", :immediately end diff --git a/cookbooks/kata-containers/version b/cookbooks/kata-containers/version index 0c62199..0d91a54 100644 --- a/cookbooks/kata-containers/version +++ b/cookbooks/kata-containers/version @@ -1 +1 @@ -0.2.1 +0.3.0 diff --git a/nodes/local-kata-containers.json b/nodes/local-kata-containers.json new file mode 100644 index 0000000..0e12e20 --- /dev/null +++ b/nodes/local-kata-containers.json @@ -0,0 +1,5 @@ +{ + "run_list": [ + "role[kata-containers]" + ] +} diff --git a/roles/kata-containers.rb b/roles/kata-containers.rb new file mode 100644 index 0000000..0cb8cdf --- /dev/null +++ b/roles/kata-containers.rb @@ -0,0 +1,41 @@ +# +# Copyright 2018, whitestar +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name 'kata-containers' +description 'Kata Containers' + +run_list( + 'recipe[kata-containers::default]', + # with docker-grid cookbook + #'recipe[docker-grid::engine]', +) + +#env_run_lists + +default_attributes( +) + +override_attributes( + # with docker-grid cookbook + 'docker-grid' => { + 'engine' => { + 'daemon_extra_options' => [ + '--add-runtime kata-runtime=/usr/bin/kata-runtime', + '--default-runtime=kata-runtime', + ].join(' '), + }, + }, +) -- 2.11.0