From 04b1d5e49ea9bc32cbf0971ceb73eefd1c9b05d7 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 22 Mar 2023 21:07:04 -0700 Subject: [PATCH] Accessories may be pulled from authenticated registries --- README.md | 8 +++++++- lib/mrsk/cli/accessory.rb | 1 + test/cli/accessory_test.rb | 3 +++ test/commands/accessory_test.rb | 10 +++++----- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 56d26116e..eaa17aea8 100644 --- a/README.md +++ b/README.md @@ -445,7 +445,7 @@ FROM ruby:$RUBY_VERSION-slim as base ### Using accessories for database, cache, search services -You can manage your accessory services via MRSK as well. The services will build off public images, and will not be automatically updated when you deploy: +You can manage your accessory services via MRSK as well. Accessories are long-lived services that your app depends on. They are not updated when you deploy. ```yaml accessories: @@ -466,10 +466,16 @@ accessories: port: "36379:6379" volumes: - /var/lib/redis:/data + internal-example: + image: registry.digitalocean.com/user/otherservice:latest + host: 1.1.1.5 + port: 44444 ``` Now run `mrsk accessory start mysql` to start the MySQL server on 1.1.1.3. See `mrsk accessory` for all the commands possible. +Accessory images must be public or tagged in your private registry. + ### Using Cron You can use a specific container to run your Cron jobs: diff --git a/lib/mrsk/cli/accessory.rb b/lib/mrsk/cli/accessory.rb index 834c7dec1..36f5cd3c2 100644 --- a/lib/mrsk/cli/accessory.rb +++ b/lib/mrsk/cli/accessory.rb @@ -9,6 +9,7 @@ def boot(name) upload(name) on(accessory.host) do + execute *MRSK.registry.login execute *MRSK.auditor.record("Booted #{name} accessory"), verbosity: :debug execute *accessory.run end diff --git a/test/cli/accessory_test.rb b/test/cli/accessory_test.rb index fc6c25fbf..8d2fe4357 100644 --- a/test/cli/accessory_test.rb +++ b/test/cli/accessory_test.rb @@ -6,6 +6,7 @@ class CliAccessoryTest < CliTestCase Mrsk::Cli::Accessory.any_instance.expects(:upload).with("mysql") run_command("boot", "mysql").tap do |output| + assert_match /docker login.*on 1.1.1.3/, output assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e [REDACTED] -e MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output end end @@ -17,6 +18,8 @@ class CliAccessoryTest < CliTestCase Mrsk::Cli::Accessory.any_instance.expects(:upload).with("redis") run_command("boot", "all").tap do |output| + assert_match /docker login.*on 1.1.1.3/, output + assert_match /docker login.*on 1.1.1.4/, output assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e [REDACTED] -e MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=10m --publish 6379:6379 --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.4", output end diff --git a/test/commands/accessory_test.rb b/test/commands/accessory_test.rb index c98e1590d..156d57940 100644 --- a/test/commands/accessory_test.rb +++ b/test/commands/accessory_test.rb @@ -3,11 +3,11 @@ class CommandsAccessoryTest < ActiveSupport::TestCase setup do @config = { - service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, + service: "app", image: "dhh/app", registry: { "server" => "private.registry", "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ], accessories: { "mysql" => { - "image" => "mysql:8.0", + "image" => "private.registry/mysql:8.0", "host" => "1.1.1.5", "port" => "3306", "env" => { @@ -49,7 +49,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase test "run" do assert_equal \ - "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" --label service=\"app-mysql\" mysql:8.0", + "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=10m --publish 3306:3306 -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" --label service=\"app-mysql\" private.registry/mysql:8.0", @mysql.run.join(" ") assert_equal \ @@ -78,7 +78,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase test "execute in new container" do assert_equal \ - "docker run --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" mysql:8.0 mysql -u root", + "docker run --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" private.registry/mysql:8.0 mysql -u root", @mysql.execute_in_new_container("mysql", "-u", "root").join(" ") end @@ -90,7 +90,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase test "execute in new container over ssh" do @mysql.stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do - assert_match %r|docker run -it --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" mysql:8.0 mysql -u root|, + assert_match %r|docker run -it --rm -e MYSQL_ROOT_PASSWORD=\"secret123\" -e MYSQL_ROOT_HOST=\"%\" private.registry/mysql:8.0 mysql -u root|, @mysql.execute_in_new_container_over_ssh("mysql", "-u", "root") end end