Encourage registry password from ENV
This commit is contained in:
@@ -14,7 +14,8 @@ servers:
|
|||||||
- 192.168.0.2
|
- 192.168.0.2
|
||||||
registry:
|
registry:
|
||||||
username: registry-user-name
|
username: registry-user-name
|
||||||
password: <%= ENV.fetch("MRSK_REGISTRY_PASSWORD") %>
|
password:
|
||||||
|
- MRSK_REGISTRY_PASSWORD
|
||||||
env:
|
env:
|
||||||
secret:
|
secret:
|
||||||
- RAILS_MASTER_KEY
|
- RAILS_MASTER_KEY
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ registry:
|
|||||||
# Specify the registry server, if you're not using Docker Hub
|
# Specify the registry server, if you're not using Docker Hub
|
||||||
# server: registry.digitalocean.com / ghcr.io / ...
|
# server: registry.digitalocean.com / ghcr.io / ...
|
||||||
username: my-user
|
username: my-user
|
||||||
password: my-password-should-go-somewhere-safe
|
password:
|
||||||
|
- MRSK_REGISTRY_PASSWORD
|
||||||
|
|
||||||
# Inject ENV variables into containers (secrets come from .env).
|
# Inject ENV variables into containers (secrets come from .env).
|
||||||
# env:
|
# env:
|
||||||
|
|||||||
@@ -2,10 +2,19 @@ class Mrsk::Commands::Registry < Mrsk::Commands::Base
|
|||||||
delegate :registry, to: :config
|
delegate :registry, to: :config
|
||||||
|
|
||||||
def login
|
def login
|
||||||
docker :login, registry["server"], "-u", redact(registry["username"]), "-p", redact(registry["password"])
|
docker :login, registry["server"], "-u", redact(registry["username"]), "-p", redact(lookup_password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def logout
|
def logout
|
||||||
docker :logout, registry["server"]
|
docker :logout, registry["server"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def lookup_password
|
||||||
|
if registry["password"].is_a?(Array)
|
||||||
|
ENV.fetch(registry["password"].first).dup
|
||||||
|
else
|
||||||
|
registry["password"]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,17 @@ class CommandsRegistryTest < ActiveSupport::TestCase
|
|||||||
@registry.login.join(" ")
|
@registry.login.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "registry login with ENV password" do
|
||||||
|
ENV["MRSK_REGISTRY_PASSWORD"] = "more-secret"
|
||||||
|
@config[:registry]["password"] = [ "MRSK_REGISTRY_PASSWORD" ]
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker login hub.docker.com -u dhh -p more-secret",
|
||||||
|
@registry.login.join(" ")
|
||||||
|
ensure
|
||||||
|
ENV.delete("MRSK_REGISTRY_PASSWORD")
|
||||||
|
end
|
||||||
|
|
||||||
test "registry logout" do
|
test "registry logout" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker logout hub.docker.com",
|
"docker logout hub.docker.com",
|
||||||
|
|||||||
Reference in New Issue
Block a user