Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) add a little bit of verbosity to deploy_signed_repos_to_s3 #1273

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## [Unreleased]
### Changed
- (maint) Make deploy_signed_repos_to_s3 just a bit more verbose

## [0.122.2] - 2024-10-07
### Changed
Expand Down
17 changes: 10 additions & 7 deletions lib/packaging/util/net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def rsync_exec(source, opts = {})
target_host: nil,
extra_flags: nil,
dryrun: ENV['DRYRUN']
}.merge(opts.merge(opts.delete_if { |_, value| value.nil? })) # rubocop:disable Style/CollectionCompact
}.merge(opts.merge(opts.delete_if { |_, value| value.nil? }))

stdout, = Pkg::Util::Execution.capture3(rsync_cmd(source, options), true)
stdout
Expand Down Expand Up @@ -216,15 +216,18 @@ def rsync_from(source, origin_host, dest, opts = {})
)
end

def s3sync_to(source, target_bucket, target_directory = "", flags = [])
def s3sync_to(source, target_bucket, target_directory = '', flags = [])
s3cmd = Pkg::Util::Tool.check_tool('s3cmd')
s3cfg_path = File.join(ENV['HOME'], '.s3cfg')

if Pkg::Util::File.file_exists?(File.join(ENV['HOME'], '.s3cfg'))
stdout, = Pkg::Util::Execution.capture3("#{s3cmd} sync #{flags.join(' ')} '#{source}' s3://#{target_bucket}/#{target_directory}/")
stdout
else
fail "#{File.join(ENV['HOME'], '.s3cfg')} does not exist. It is required to ship files using s3cmd."
unless File.exist?(s3cfg_path)
fail "#{s3cfg_path} does not exist. It is required to ship files using s3cmd."
end

sync_command = "#{s3cmd} sync #{flags.join(' ')} '#{source}' " \
"s3://#{target_bucket}/#{target_directory}/"

Pkg::Util::Execution.capture3(sync_command, true)
end

# This is fairly absurd. We're implementing curl by shelling out. What do I
Expand Down
18 changes: 10 additions & 8 deletions spec/lib/packaging/util/net_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@

it 'should fail if ~/.s3cfg is not present' do
expect(Pkg::Util::Tool).to receive(:check_tool).with("s3cmd").and_return(s3cmd)
expect(Pkg::Util::File)
.to receive(:file_exists?)
expect(File)
.to receive(:exist?)
.with(File.join(ENV['HOME'], '.s3cfg'))
.and_return(false)
expect { Pkg::Util::Net.s3sync_to('foo', 'bar', 'boo') }
Expand All @@ -192,25 +192,27 @@

it "should s3 sync 'thing' to 's3://foo@bar/home/foo/' with no flags" do
expect(Pkg::Util::Tool).to receive(:check_tool).with("s3cmd").and_return(s3cmd)
expect(Pkg::Util::File)
.to receive(:file_exists?)
expect(File)
.to receive(:exist?)
.with(File.join(ENV['HOME'], '.s3cfg'))
.and_return(true)
expect(Pkg::Util::Execution)
.to receive(:capture3)
.with("#{s3cmd} sync 'thing' s3://foo@bar/home/foo/")
.with("#{s3cmd} sync 'thing' s3://foo@bar/home/foo/", anything)
Pkg::Util::Net.s3sync_to("thing", "foo@bar", "home/foo")
end

it "should s3sync 'thing' to 's3://foo@bar/home/foo/' with --delete-removed and --acl-public" do
expect(Pkg::Util::Tool).to receive(:check_tool).with("s3cmd").and_return(s3cmd)
expect(Pkg::Util::File)
.to receive(:file_exists?)
expect(File)
.to receive(:exist?)
.with(File.join(ENV['HOME'], '.s3cfg'))
.and_return(true)
expect(Pkg::Util::Execution)
.to receive(:capture3)
.with("#{s3cmd} sync --delete-removed --acl-public 'thing' s3://foo@bar/home/foo/")
.with(
"#{s3cmd} sync --delete-removed --acl-public 'thing' s3://foo@bar/home/foo/", anything
)
Pkg::Util::Net.s3sync_to("thing", "foo@bar", "home/foo", ["--delete-removed", "--acl-public"])
end
end
Expand Down
27 changes: 20 additions & 7 deletions tasks/nightly_repos.rake
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,28 @@ namespace :pl do
end

task :deploy_signed_repos_to_s3, [:target_bucket] => "pl:fetch" do |t, args|
target_bucket = args.target_bucket or fail ":target_bucket is a required argument to #{t}"
fail ":target_bucket is a required argument to #{t}" unless args.target_bucket
target_bucket = args.target_bucket

# Ship it to the target for consumption
# First we ship the latest and clean up any repo-configs that are no longer valid with --delete-removed and --acl-public
Pkg::Util::Net.s3sync_to("pkg/#{Pkg::Config.project}-latest/", target_bucket, "#{Pkg::Config.project}-latest", ["--acl-public", "--delete-removed", "--follow-symlinks"])
# Then we ship the sha version with just --acl-public
Pkg::Util::Net.s3sync_to("pkg/#{Pkg::Config.project}/", target_bucket, Pkg::Config.project, ["--acl-public", "--follow-symlinks"])
# Ship it to the target for consumption.

puts "'#{Pkg::Config.ref}' of '#{Pkg::Config.project}' has been shipped via s3 to '#{target_bucket}'"
# First we ship the latest and clean up any repo-configs that
# are no longer valid with --delete-removed and --acl-public
source = "pkg/#{Pkg::Config.project}-latest/"
target_directory = "#{Pkg::Config.project}-latest"
puts("S3 sync from '#{Dir.pwd}/#{source}' to 's3://#{target_bucket}/#{target_directory}'")
Pkg::Util::Net.s3sync_to(source, target_bucket, target_directory,
['--acl-public', '--delete-removed', '--follow-symlinks'])

# Then we ship the sha version with just --acl-public
source = "pkg/#{Pkg::Config.project}/"
target_directory = Pkg::Config.project
puts("S3 sync from '#{Dir.pwd}/#{source}' to 's3://#{target_bucket}/#{target_directory}'")
Pkg::Util::Net.s3sync_to(source, target_bucket, target_directory,
['--acl-public', '--follow-symlinks'])

puts "'#{Pkg::Config.ref}' of '#{Pkg::Config.project}' has been uploaded to" \
"'s3://#{target_bucket}'"
end

task :generate_signed_repo_configs, [:target_prefix] => "pl:fetch" do |t, args|
Expand Down