From 55c5875321e9209ed2192c7e2e70f7b350e7dc11 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 7 Jan 2023 21:29:33 +0100 Subject: [PATCH] Use Base class for default config assignment --- lib/mrsk/commands.rb | 7 +++++++ lib/mrsk/commands/app.rb | 8 +------- lib/mrsk/commands/registry.rb | 2 +- lib/mrsk/commands/traefik.rb | 2 +- lib/tasks/mrsk/traefik.rake | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/mrsk/commands.rb b/lib/mrsk/commands.rb index 408490c5..2c2754bf 100644 --- a/lib/mrsk/commands.rb +++ b/lib/mrsk/commands.rb @@ -1,4 +1,11 @@ module Mrsk::Commands + class Base + attr_accessor :config + + def initialize(config) + @config = config + end + end end require "mrsk/commands/app" diff --git a/lib/mrsk/commands/app.rb b/lib/mrsk/commands/app.rb index c7f6458e..c8303013 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -1,10 +1,4 @@ -class Mrsk::Commands::App - attr_accessor :config - - def initialize(config) - @config = config - end - +class Mrsk::Commands::App < Mrsk::Commands::Base def push # TODO: Run 'docker buildx create --use' when needed "docker buildx build --push --platform=linux/amd64,linux/arm64 -t #{config.image_with_version} ." diff --git a/lib/mrsk/commands/registry.rb b/lib/mrsk/commands/registry.rb index a2763192..d7175dc9 100644 --- a/lib/mrsk/commands/registry.rb +++ b/lib/mrsk/commands/registry.rb @@ -1,4 +1,4 @@ -class Mrsk::Commands::Registry +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 diff --git a/lib/mrsk/commands/traefik.rb b/lib/mrsk/commands/traefik.rb index d411215e..b500b99c 100644 --- a/lib/mrsk/commands/traefik.rb +++ b/lib/mrsk/commands/traefik.rb @@ -1,4 +1,4 @@ -class Mrsk::Commands::Traefik +class Mrsk::Commands::Traefik < Mrsk::Commands::Base def start "docker run --name traefik " + "--rm -d " + diff --git a/lib/tasks/mrsk/traefik.rake b/lib/tasks/mrsk/traefik.rake index 5d1491fa..918ddf91 100644 --- a/lib/tasks/mrsk/traefik.rake +++ b/lib/tasks/mrsk/traefik.rake @@ -1,6 +1,6 @@ require_relative "setup" -traefik = Mrsk::Commands::Traefik.new +traefik = Mrsk::Commands::Traefik.new(MRSK_CONFIG) namespace :mrsk do namespace :traefik do