itamae-plugin-recipe-selenium 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/itamae/plugin/recipe/selenium.rb +0 -1
- data/lib/itamae/plugin/recipe/selenium/chrome.rb +1 -1
- data/lib/itamae/plugin/recipe/selenium/chromedriver.rb +5 -27
- data/lib/itamae/plugin/recipe/selenium/geckodriver.rb +5 -29
- data/lib/itamae/plugin/recipe/selenium/version.rb +1 -1
- data/lib/itamae/plugin/resource/setup_selenium_driver.rb +125 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 266fd46e7428c08bec4871130a5290635cc1e7ca4eb6191d95ba1369d5a740e6
|
4
|
+
data.tar.gz: 876bf970a45124ef9311eb76cf0244bbfb68408f22c39771090e06f48b4a771d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56bcdc35abd5372c0217bd5dd57b3a2009c1b12b9a44f3e7d3014c1b7385686f2dcfd746ffe4cd5b625c1c5105c3d98390ce37701cfc18066fcde17109108b9
|
7
|
+
data.tar.gz: a374a57eb663f3a6f4337af46492ebb73a30a07761e421fd13e138ef892b6d6cec1c1c671c885047abf13577fbdd85c429ae32f525abfc39fa13ffb1fa51c259
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Include this recpie as:
|
|
24
24
|
|
25
25
|
include_recipe 'selenium'
|
26
26
|
|
27
|
-
This recipe will install chrome web
|
27
|
+
This recipe will install chrome web browser and selenium webdriver for chrome and gecko.
|
28
28
|
|
29
29
|
## Development
|
30
30
|
|
@@ -11,5 +11,5 @@ end
|
|
11
11
|
|
12
12
|
execute 'yum update -y google-chrome-stable' do
|
13
13
|
user 'root'
|
14
|
-
not_if "which google-chrome-stable && google-chrome-stable --version | egrep 'Google Chrome (
|
14
|
+
not_if "which google-chrome-stable && google-chrome-stable --version | egrep 'Google Chrome (81|82|83|84|85)\.'"
|
15
15
|
end
|
@@ -1,29 +1,7 @@
|
|
1
|
-
|
1
|
+
include_recipe './tmp_directory'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
driver_version_url = base_url + "/LATEST_RELEASE_#{browser_version}"
|
8
|
-
version = Net::HTTP.get_response(URI(driver_version_url)).body
|
9
|
-
download_url = base_url + "/#{version}/chromedriver_linux64.zip"
|
10
|
-
header = Net::HTTP.start(host) { |http| http.head("/#{version}/chromedriver_linux64.zip") }
|
11
|
-
etag = header['etag'][1...-1]
|
12
|
-
|
13
|
-
execute "download chromedriver-#{version}" do
|
14
|
-
cwd '/tmp/itamae-plugin-recipe-selenium'
|
15
|
-
command <<-EOF
|
16
|
-
rm -Rf chromedriver_linux64-#{version}*
|
17
|
-
curl -o chromedriver_linux64-#{version}.zip #{download_url}
|
18
|
-
EOF
|
19
|
-
not_if "echo '#{etag} chromedriver_linux64-#{version}.zip' | md5sum -c -"
|
20
|
-
end
|
21
|
-
|
22
|
-
execute "install chromedriver-#{version}" do
|
23
|
-
cwd '/tmp/itamae-plugin-recipe-selenium'
|
24
|
-
command <<-EOF
|
25
|
-
unzip chromedriver_linux64-#{version}.zip
|
26
|
-
sudo mv -f chromedriver /usr/local/bin/
|
27
|
-
EOF
|
28
|
-
not_if "/usr/local/bin/chromedriver -v | grep 'ChromeDriver #{version}'"
|
3
|
+
setup_selenium_driver "setup chromedriver" do
|
4
|
+
type :chrome
|
5
|
+
tmp_dir '/tmp/itamae-plugin-recipe-selenium'
|
6
|
+
install_dir '/usr/local/bin'
|
29
7
|
end
|
@@ -1,31 +1,7 @@
|
|
1
|
-
|
1
|
+
include_recipe './tmp_directory'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
response = Net::HTTP.get_response(URI(url))
|
8
|
-
|
9
|
-
break unless response.is_a?(Net::HTTPRedirection)
|
10
|
-
url = response['location']
|
11
|
-
end
|
12
|
-
version = response.uri.to_s[/[^v]*$/]
|
13
|
-
download_url = base_url + "/download/v#{version}/geckodriver-v#{version}-linux64.tar.gz"
|
14
|
-
|
15
|
-
execute "download geckodriver-#{version}" do
|
16
|
-
cwd '/tmp/itamae-plugin-recipe-selenium'
|
17
|
-
command <<-EOF
|
18
|
-
rm -Rf geckodriver-v#{version}-linux64*
|
19
|
-
curl -L -o geckodriver-v#{version}-linux64.tar.gz #{download_url}
|
20
|
-
EOF
|
21
|
-
not_if "test -e geckodriver-v#{version}-linux64.tar.gz"
|
22
|
-
end
|
23
|
-
|
24
|
-
execute "install geckodriver-#{version}" do
|
25
|
-
cwd '/tmp/itamae-plugin-recipe-selenium'
|
26
|
-
command <<-EOF
|
27
|
-
tar zxf geckodriver-v#{version}-linux64.tar.gz
|
28
|
-
sudo mv -f geckodriver /usr/local/bin/
|
29
|
-
EOF
|
30
|
-
not_if "/usr/local/bin/geckodriver -V | grep 'geckodriver #{version}'"
|
3
|
+
setup_selenium_driver "setup geckodriver" do
|
4
|
+
type :gecko
|
5
|
+
tmp_dir '/tmp/itamae-plugin-recipe-selenium'
|
6
|
+
install_dir '/usr/local/bin'
|
31
7
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Itamae
|
4
|
+
module Plugin
|
5
|
+
module Resource
|
6
|
+
class SetupSeleniumDriver < Itamae::Resource::Base
|
7
|
+
define_attribute :action, default: :run
|
8
|
+
define_attribute :type, type: [String, Symbol], default: :chrome
|
9
|
+
define_attribute :tmp_dir, type: String, default: '/tmp'
|
10
|
+
define_attribute :install_dir, type: String, default: '/usr/local/bin/'
|
11
|
+
|
12
|
+
def pre_action
|
13
|
+
attributes.cwd = attributes.tmp_dir
|
14
|
+
attributes.install_dir = File.join(attributes.install_dir, '/')
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_current_attributes
|
18
|
+
current.executed = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def action_run(options)
|
22
|
+
case attributes.type.to_sym
|
23
|
+
when :chrome
|
24
|
+
run_setup_chromedriver
|
25
|
+
when :gecko
|
26
|
+
run_setup_geckodriver
|
27
|
+
end
|
28
|
+
|
29
|
+
updated!
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def run_setup_chromedriver
|
35
|
+
host = 'chromedriver.storage.googleapis.com'
|
36
|
+
base_url = 'https://' + host
|
37
|
+
browser_version = run_command('sudo yum list | grep google-chrome-stable').stdout.split[1]
|
38
|
+
browser_version = Gem::Version.new(browser_version.to_s).segments[0..2].join('.')
|
39
|
+
driver_version_url = base_url + "/LATEST_RELEASE_#{browser_version}"
|
40
|
+
driver_version = Net::HTTP.get_response(URI(driver_version_url)).body
|
41
|
+
download_url = base_url + "/#{driver_version}/chromedriver_linux64.zip"
|
42
|
+
header = Net::HTTP.start(host) { |http| http.head("/#{driver_version}/chromedriver_linux64.zip") }
|
43
|
+
etag = header['etag'][1...-1]
|
44
|
+
|
45
|
+
Itamae.logger.debug "browser version: #{browser_version}"
|
46
|
+
Itamae.logger.debug "driver version: #{driver_version}"
|
47
|
+
Itamae.logger.debug "download url: #{download_url}"
|
48
|
+
Itamae.logger.debug "etag: #{etag}"
|
49
|
+
|
50
|
+
run_command_if_not(
|
51
|
+
'download chromedriver',
|
52
|
+
"echo '#{etag} chromedriver_linux64-#{driver_version}.zip' | md5sum -c -",
|
53
|
+
<<-COMMANDS
|
54
|
+
rm -Rf chromedriver_linux64-#{driver_version}*
|
55
|
+
curl -o chromedriver_linux64-#{driver_version}.zip #{download_url}
|
56
|
+
COMMANDS
|
57
|
+
)
|
58
|
+
|
59
|
+
run_command_if_not(
|
60
|
+
'install chromedriver',
|
61
|
+
"#{attributes.install_dir}chromedriver -v | grep 'ChromeDriver #{driver_version}'",
|
62
|
+
<<-COMMANDS
|
63
|
+
unzip chromedriver_linux64-#{driver_version}.zip
|
64
|
+
sudo mv -f chromedriver #{attributes.install_dir}
|
65
|
+
COMMANDS
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def run_setup_geckodriver
|
70
|
+
base_url = "https://github.com/mozilla/geckodriver/releases"
|
71
|
+
url = base_url + '/latest'
|
72
|
+
response = nil
|
73
|
+
5.times do
|
74
|
+
response = Net::HTTP.get_response(URI(url))
|
75
|
+
|
76
|
+
break unless response.is_a?(Net::HTTPRedirection)
|
77
|
+
url = response['location']
|
78
|
+
end
|
79
|
+
driver_version = response.uri.to_s[/[^v]*$/]
|
80
|
+
download_url = base_url + "/download/v#{driver_version}/geckodriver-v#{driver_version}-linux64.tar.gz"
|
81
|
+
|
82
|
+
Itamae.logger.debug "driver version: #{driver_version}"
|
83
|
+
Itamae.logger.debug "download url: #{download_url}"
|
84
|
+
|
85
|
+
run_command_if_not(
|
86
|
+
'download geckodriver',
|
87
|
+
"test -e geckodriver-v#{driver_version}-linux64.tar.gz",
|
88
|
+
<<-COMMANDS
|
89
|
+
rm -Rf geckodriver-v#{driver_version}-linux64*
|
90
|
+
curl -L -o geckodriver-v#{driver_version}-linux64.tar.gz #{download_url}
|
91
|
+
COMMANDS
|
92
|
+
)
|
93
|
+
|
94
|
+
run_command_if_not(
|
95
|
+
'install geckodriver',
|
96
|
+
"#{attributes.install_dir}geckodriver -V | grep 'geckodriver #{driver_version}'",
|
97
|
+
<<-COMMANDS
|
98
|
+
tar zxf geckodriver-v#{driver_version}-linux64.tar.gz
|
99
|
+
sudo mv -f geckodriver #{attributes.install_dir}
|
100
|
+
COMMANDS
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def run_command_if_not(name, if_not_command, command)
|
105
|
+
if do_not_run_command_because_of_not_if?(if_not_command)
|
106
|
+
Itamae.logger.debug "#{resource_type}[#{name}] Execution skipped because already done"
|
107
|
+
else
|
108
|
+
run_command command
|
109
|
+
show_differences_message(name, 'executed', false, true)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def do_not_run_command_because_of_not_if?(command)
|
114
|
+
run_command(command, error: false).exit_status == 0
|
115
|
+
end
|
116
|
+
|
117
|
+
def show_differences_message(name, key, current_value, value)
|
118
|
+
Itamae.logger.color :green do
|
119
|
+
Itamae.logger.info "#{resource_type}[#{name}] #{key} will change from '#{current_value}' to '#{value}'"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itamae-plugin-recipe-selenium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- y-matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: itamae
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/itamae/plugin/recipe/selenium/templates/etc/yum.repos.d/google-chrome.repo.erb
|
96
96
|
- lib/itamae/plugin/recipe/selenium/tmp_directory.rb
|
97
97
|
- lib/itamae/plugin/recipe/selenium/version.rb
|
98
|
+
- lib/itamae/plugin/resource/setup_selenium_driver.rb
|
98
99
|
homepage: https://github.com/maedadev/itamae-plugin-recipe-selenium
|
99
100
|
licenses:
|
100
101
|
- MIT
|