Registry login from config credentials

This commit is contained in:
David Heinemeier Hansson
2023-01-07 21:31:13 +01:00
parent 8fa53a0f95
commit 705cd1033e
2 changed files with 13 additions and 14 deletions

View File

@@ -1,10 +1,13 @@
class Mrsk::Commands::Registry < Mrsk::Commands::Base
def login
if (user = ENV["DOCKER_USER"]).present? && (password = ENV["DOCKER_PASSWORD"]).present?
# FIXME: Find a way to hide PW so it's not shown on terminal
"docker login -u #{user} -p #{password}"
else
raise ArgumentError, "Missing DOCKER_USER or DOCKER_PASSWORD in ENV"
end
ensure_credentials_present
"docker login #{config.registry["server"]} -u #{config.registry["username"]} -p #{config.registry["password"]}"
end
private
def ensure_credentials_present
unless config.registry && config.registry["username"].present? && config.registry["password"].present?
raise ArgumentError, "You must configure registry/username and registry/password"
end
end
end

View File

@@ -1,17 +1,13 @@
require_relative "setup"
registry = Mrsk::Commands::Registry.new
registry = Mrsk::Commands::Registry.new(MRSK_CONFIG)
namespace :mrsk do
namespace :registry do
desc "Login to the registry using ENV['DOCKER_USER'] and ENV['DOCKER_PASSWORD']"
desc "Login to the registry locally and remotely"
task :login do
if ENV["DOCKER_USER"].present? && ENV["DOCKER_PASSWORD"].present?
run_locally { execute registry.login }
on(MRSK_CONFIG.servers) { execute registry.login }
else
puts "Skipping login due to missing ENV['DOCKER_USER'] and ENV['DOCKER_PASSWORD']"
end
run_locally { execute registry.login }
on(MRSK_CONFIG.servers) { execute registry.login }
end
end
end