Encourage registry password from ENV

This commit is contained in:
David Heinemeier Hansson
2023-02-19 17:42:30 +01:00
parent 2ed3ccc53e
commit 28be8dc0f0
4 changed files with 25 additions and 3 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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

View File

@@ -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",