class Pipedawg::Job::Skopeo::Copy
Public Class Methods
new(name, opts = {})
click to toggle source
Calls superclass method
Pipedawg::Job::Skopeo::new
# File lib/pipedawg/job/skopeo/copy.rb, line 8 def initialize(name, opts = {}) opts = { config: {}, copy_image: name, destinations: [{ copy_image: nil, flags: [], options: {} }], flags: [], logins: {}, options: {}, stage: '${CI_PROJECT_DIR}/stage', trusted_ca_cert_source_files: [], trusted_ca_cert_target_file: '/etc/docker/certs.d/ca.crt' }.merge(opts) super name, opts update end
Public Instance Methods
update()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 18 def update # rubocop:disable Metrics/AbcSize require 'json' opts[:script] = debug + config + cert_copies + login + mkstage + pull + ( opts[:destinations].map { |d| push(d) } ).flatten(1) end
Private Instance Methods
cert_copies()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 31 def cert_copies ["mkdir -p $(dirname \"#{opts[:trusted_ca_cert_target_file]}\")"] + Array(opts[:trusted_ca_cert_source_files]).map do |cert| "cat \"#{cert}\" >> \"#{opts[:trusted_ca_cert_target_file]}\"" end end
config()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 27 def config ['export CONFIG=$(mktemp -d)', "echo #{opts[:config].to_json.inspect} > \"${CONFIG}/config.json\""] end
copy(copy_opts, source, destination)
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 56 def copy(copy_opts, source, destination) Array(["#{opts[:command]} copy --authfile \"${CONFIG}/config.json\"", flags(copy_opts), options(copy_opts), source, destination].reject(&:empty?).join(' ')) end
flags(opts)
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 61 def flags(opts) opts.fetch(:flags, []).uniq.map { |f| "--#{f}" }.join(' ') end
login()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 38 def login opts.fetch(:logins, {}).map do |k, v| "echo \"#{v['password']}\" | #{opts[:command]} login --authfile \"${CONFIG}/config.json\" --username \"#{v['username']}\" --password-stdin \"#{k}\"" # rubocop:disable Layout/LineLength end end
mkstage()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 44 def mkstage ["mkdir -p \"#{opts[:stage]}\""] end
options(opts)
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 65 def options(opts) opts.fetch(:options, {}).map { |k, v| "--#{k} \"#{v}\"" }.join(' ') end
pull()
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 48 def pull copy(opts, "docker://#{opts[:copy_image]}", "\"dir://#{opts[:stage]}\"") end
push(destination_opts)
click to toggle source
# File lib/pipedawg/job/skopeo/copy.rb, line 52 def push(destination_opts) copy(destination_opts, "\"dir://#{opts[:stage]}\"", "docker://#{destination_opts[:copy_image]}") end