Add ERB eval so we can use credentials
This commit is contained in:
14
README.md
14
README.md
@@ -13,13 +13,21 @@ servers:
|
|||||||
- xxx.xxx.xxx.xxx
|
- xxx.xxx.xxx.xxx
|
||||||
- xxx.xxx.xxx.xxx
|
- xxx.xxx.xxx.xxx
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: mysql2://username@localhost/database_name/
|
DATABASE_URL: mysql2://localhost/my-app_production/
|
||||||
REDIS_URL: redis://host:6379/1
|
REDIS_URL: redis://host:6379/1
|
||||||
registry:
|
registry:
|
||||||
# No server definition needed if using Docker Hub
|
# No server definition needed if using Docker Hub
|
||||||
server: registry.digitalocean.com
|
server: registry.digitalocean.com
|
||||||
username: your-token
|
username: <%= Rails.application.credentials.registry["username"] %>
|
||||||
password: your-token
|
password: <%= Rails.application.credentials.registry["password"] %>
|
||||||
|
```
|
||||||
|
|
||||||
|
Then ensure your encrypted credentials have the registry username + password by editing them with `rails credentials:edit`:
|
||||||
|
|
||||||
|
```
|
||||||
|
registry:
|
||||||
|
username: real-user-name
|
||||||
|
password: real-password
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you're ready to deploy a multi-arch image (FIXME: currently you need to manually run `docker buildx create --use` once first):
|
Now you're ready to deploy a multi-arch image (FIXME: currently you need to manually run `docker buildx create --use` once first):
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
require "active_support/ordered_options"
|
require "active_support/ordered_options"
|
||||||
|
require "erb"
|
||||||
|
|
||||||
class Mrsk::Configuration
|
class Mrsk::Configuration
|
||||||
delegate :service, :image, :env, :registry, :ssh_user, to: :config, allow_nil: true
|
delegate :service, :image, :env, :registry, :ssh_user, to: :config, allow_nil: true
|
||||||
|
|
||||||
def self.load_file(file)
|
def self.load_file(file)
|
||||||
if file.exist?
|
if file.exist?
|
||||||
new YAML.load_file(file).symbolize_keys
|
new YAML.load(ERB.new(IO.read(file)).result).symbolize_keys
|
||||||
else
|
else
|
||||||
raise "Configuration file not found in #{file}"
|
raise "Configuration file not found in #{file}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,4 +26,9 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
configuration = Mrsk::Configuration.new(@config.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) })
|
configuration = Mrsk::Configuration.new(@config.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) })
|
||||||
assert_equal "ghcr.io/dhh/app:123", configuration.absolute_image
|
assert_equal "ghcr.io/dhh/app:123", configuration.absolute_image
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "erb evaluation of yml config" do
|
||||||
|
configuration = Mrsk::Configuration.load_file Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__))
|
||||||
|
assert_equal "my-user", configuration.registry["username"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
11
test/fixtures/deploy.erb.yml
vendored
Normal file
11
test/fixtures/deploy.erb.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
service: app
|
||||||
|
image: dhh/app
|
||||||
|
servers:
|
||||||
|
- 1.1.1.1
|
||||||
|
- 1.1.1.2
|
||||||
|
env:
|
||||||
|
REDIS_URL: redis://x/y
|
||||||
|
registry:
|
||||||
|
server: registry.digitalocean.com
|
||||||
|
username: <%= "my-user" %>
|
||||||
|
password: <%= "my-password" %>
|
||||||
Reference in New Issue
Block a user