From 93064a94d41634751272da6e90cad2399786445d Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 3 Nov 2021 12:31:31 +0900 Subject: [PATCH 1/3] Use `.deb` package to install `vector`. --- cookbooks/vector/install.rb | 51 +++++++++++++------------------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/cookbooks/vector/install.rb b/cookbooks/vector/install.rb index 389ee76..b6424b3 100644 --- a/cookbooks/vector/install.rb +++ b/cookbooks/vector/install.rb @@ -1,37 +1,22 @@ -vector_url = '' -vector_deb = '' +KEY='https://repositories.timber.io/public/vector/gpg.3543DB2D0A2BC4B8.key' -tag = '' -vtag = '' - -# Calculate the Download URL: -begin - require 'net/http' - - - uri = URI.parse('https://github.com/vectordotdev/vector/releases/latest') - - Timeout.timeout(3) do - response = Net::HTTP.get_response(uri) - - vtag = $1 if response.body =~ %r{tag\/(v\d+\.\d+\.\d+)} - tag = vtag.sub(/^v/, '') - - vector_deb = "#{node['vector']['debPrefix']}#{tag}#{node['vector']['debPostfix']}" - vector_url = "#{node['vector']['url']}/#{vtag}/#{vector_deb}" - end -rescue - # Abort the chef client process: - raise 'Cannot connect to http://github.com.' +execute "wget -O /tmp/vector.key #{KEY}" do + not_if 'apt-key list | grep "1E46 C153"' end -# バージョン確認して、アップデート必要かどうか確認 -result = run_command("vector --version 2>&1 | grep #{tag}", error: false) -if result.exit_status != 0 - # Download: - TMP = "/tmp/#{vector_deb}" - - execute "wget #{vector_url} -O #{TMP}" - - execute "dpkg -i #{TMP}" +execute 'apt-key add /tmp/vector.key' do + not_if 'apt-key list | grep "1E46 C153"' end + +# Retrieve the Ubuntu code: +DIST = run_command('lsb_release -cs').stdout.chomp + +# Deploy the `apt` sources: +template '/etc/apt/sources.list.d/timber-vector.list' do + action :create + variables(distribution: DIST) +end + +execute 'apt update' + +package 'vector' From a81dc16e905a546d2c8c9d93a016ee84765aea28 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 3 Nov 2021 12:32:32 +0900 Subject: [PATCH 2/3] Add template for the apt source. --- .../vector/templates/etc/apt/sources.list.d/timber-vector.list | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 cookbooks/vector/templates/etc/apt/sources.list.d/timber-vector.list diff --git a/cookbooks/vector/templates/etc/apt/sources.list.d/timber-vector.list b/cookbooks/vector/templates/etc/apt/sources.list.d/timber-vector.list new file mode 100644 index 0000000..a692b57 --- /dev/null +++ b/cookbooks/vector/templates/etc/apt/sources.list.d/timber-vector.list @@ -0,0 +1,3 @@ +deb https://repositories.timber.io/public/vector/deb/ubuntu <%= @distribution %> main + +deb-src https://repositories.timber.io/public/vector/deb/ubuntu <%= @distribution %> main From 3d981799b6ba205ee794329607a92043337987c5 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Wed, 3 Nov 2021 12:33:02 +0900 Subject: [PATCH 3/3] Stop `vector` service. --- cookbooks/vector/setup.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cookbooks/vector/setup.rb b/cookbooks/vector/setup.rb index ea2e32f..af29c6b 100644 --- a/cookbooks/vector/setup.rb +++ b/cookbooks/vector/setup.rb @@ -6,3 +6,8 @@ mode '0755' end end + +# Stop vector default service: +service 'vector' do + action :disable +end