Skip to content

Commit 5e43cc1

Browse files
davpratgmarciani
authored andcommitted
Addressing some comments
Signed-off-by: David Pratt <[email protected]>
1 parent 6a0fc0a commit 5e43cc1

File tree

5 files changed

+68
-47
lines changed

5 files changed

+68
-47
lines changed

attributes/default.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
# AWS domain
2727
default['cluster']['aws_domain'] = aws_domain
2828

29+
# URL for ParallelCluster Artifacts stored in public S3 buckets
30+
# ['cluster']['region'] will need to be defined by image_dna.json during AMI build.
31+
default['cluster']['artifacts_s3_url'] = "https://#{node['cluster']['region']}-aws-parallelcluster.s3.#{node['cluster']['region']}.#{node['cluster']['aws_domain']}/archives"
32+
2933
# Cluster config
3034
default['cluster']['cluster_s3_bucket'] = nil
3135
default['cluster']['cluster_config_s3_key'] = nil
@@ -243,7 +247,7 @@
243247
)
244248

245249
# MySQL Packages
246-
default['cluster']['mysql']['package']['root'] = "https://#{node['cluster']['region']}-aws-parallelcluster.s3.#{node['cluster']['region']}.#{node['cluster']['aws_domain']}/archives/mysql"
250+
default['cluster']['mysql']['package']['root'] = "#{node['cluster']['artifacts_s3_url']}/mysql"
247251
default['cluster']['mysql']['package']['version'] = "8.0.31-1"
248252
default['cluster']['mysql']['package']['source-version'] = "8.0.31"
249253
default['cluster']['mysql']['package']['platform'] = if arm_instance?
@@ -261,7 +265,7 @@
261265
end
262266
default['cluster']['mysql']['package']['file-name'] = "mysql-community-client-#{node['cluster']['mysql']['package']['version']}.tar.gz"
263267
default['cluster']['mysql']['package']['archive'] = "#{node['cluster']['mysql']['package']['root']}/#{node['cluster']['mysql']['package']['platform']}/#{node['cluster']['mysql']['package']['file-name']}"
264-
default['cluster']['mysql']['package']['source'] = "#{node['cluster']['mysql']['package']['root']}/source/mysql-#{node['cluster']['mysql']['package']['source-version']}.tar.gz"
268+
default['cluster']['mysql']['package']['source'] = "#{node['cluster']['artifacts_s3_url']}/source/mysql-#{node['cluster']['mysql']['package']['source-version']}.tar.gz"
265269

266270
# MySQL Validation
267271
if arm_instance?
@@ -631,7 +635,6 @@
631635
default['cluster']['slurm_node_reg_mem_percent'] = 75
632636
default['cluster']['slurmdbd_response_retries'] = 30
633637

634-
635638
# Official ami build
636639
default['cluster']['is_official_ami_build'] = false
637640

cookbooks/aws-parallelcluster-install/libraries/helpers.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,60 @@ def get_package_version(package_name)
3434
end
3535
version
3636
end
37+
38+
def validate_file_hash(file_path, expected_hash)
39+
hash_function = yield
40+
checksum = hash_function.file(file_path).hexdigest
41+
if checksum != expected_hash
42+
raise "Downloaded file #{file_path} checksum #{checksum} does not match expected checksum #{expected_hash}"
43+
end
44+
end
45+
46+
def validate_file_md5_hash(file_path, expected_hash)
47+
validate_file_hash(file_path, expected_hash) do
48+
require 'digest'
49+
Digest::MD5
50+
end
51+
end
52+
53+
def validate_file_sha256_hash(file_path, expected_hash)
54+
validate_file_hash(file_path, expected_hash) do
55+
require 'digest'
56+
Digest::SHA2.new(256)
57+
end
58+
end
59+
60+
def install_repository_definition(repository_name, definition_source, local_file, md5_hash = nil)
61+
remote_file local_file do
62+
source definition_source
63+
mode '0644'
64+
retries 3
65+
retry_delay 5
66+
not_if { ::File.exist?(local_file) }
67+
end
68+
69+
ruby_block "Validate Repository Definition Checksum" do
70+
block do
71+
validate_file_md5_hash(local_file, md5_hash = nil)
72+
end
73+
not_if { md5_hash.nil? }
74+
end
75+
76+
if platform?('ubuntu')
77+
# dpkg_package is used here because 'package' seems to default to using apt_package
78+
# which fails on the MySQL package.
79+
dpkg_package repository_name do
80+
source local_file
81+
end
82+
83+
apt_update 'update' do
84+
action :update
85+
retries 3
86+
retry_delay 5
87+
end
88+
else
89+
package repository_name do
90+
source local_file
91+
end
92+
end
93+
end

cookbooks/aws-parallelcluster-install/recipes/install_mysql_client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#
44
# Cookbook:: aws-parallelcluster
5-
# Recipe:: mysql
5+
# Recipe:: install_mysql_client
66
#
77
# Copyright:: 2013-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
88
#
@@ -24,7 +24,7 @@
2424

2525
package_installer = value_for_platform(
2626
'default' => "yum install -y",
27-
'ubuntu' => { 'default' => "apt install" }
27+
'ubuntu' => { 'default' => "apt install -y" }
2828
)
2929

3030
mysql_archive_url = node['cluster']['mysql']['package']['archive']
@@ -55,7 +55,7 @@
5555

5656
# Add MySQL source file
5757
template "#{node['cluster']['sources_dir']}/mysql_source_code.txt" do
58-
source 'mysql/mysql_source_code.erb'
58+
source 'mysql/mysql_source_code.txt.erb'
5959
owner 'root'
6060
group 'root'
6161
mode '0644'

cookbooks/aws-parallelcluster-install/recipes/install_mysql_repository.rb

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#
44
# Cookbook:: aws-parallelcluster
5-
# Recipe:: mysql
5+
# Recipe:: install_mysql_repository
66
#
77
# Copyright:: 2013-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
88
#
@@ -15,47 +15,8 @@
1515
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
def install_repository_configuration_package(repository_name, definition_source, local_file, md5_hash)
19-
remote_file local_file do
20-
source definition_source
21-
mode '0644'
22-
retries 3
23-
retry_delay 5
24-
not_if { ::File.exist?(local_file) }
25-
end
26-
27-
ruby_block "Validate Repository Definition Checksum" do
28-
block do
29-
require 'digest'
30-
checksum = Digest::MD5.file(local_file).hexdigest
31-
32-
if checksum != md5_hash
33-
raise "Downloaded file #{local_file} checksum #{checksum} does not match expected checksum #{md5_hash}"
34-
end
35-
end
36-
end
37-
38-
if platform?('ubuntu')
39-
# dpkg_package is used here because 'package' seems to default to using apt_package
40-
# which fails on the MySQL package.
41-
dpkg_package repository_name do
42-
source local_file
43-
end
44-
45-
apt_update 'update' do
46-
action :update
47-
retries 3
48-
retry_delay 5
49-
end
50-
else
51-
package repository_name do
52-
source local_file
53-
end
54-
end
55-
end
56-
5718
unless platform?('ubuntu') && arm_instance?
58-
install_repository_configuration_package(
19+
install_repository_definition(
5920
"MySQL Repository",
6021
node['cluster']['mysql']['repository']['definition']['url'],
6122
"/tmp/#{node['cluster']['mysql']['repository']['definition']['file-name']}",

0 commit comments

Comments
 (0)