Is a global option better?

This commit is contained in:
Samuel Sieg
2023-03-12 10:53:29 +01:00
parent ff0170076e
commit 47af6d9483
4 changed files with 15 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ module Mrsk::Cli
class_option :quiet, type: :boolean, aliases: "-q", desc: "Minimal logging" class_option :quiet, type: :boolean, aliases: "-q", desc: "Minimal logging"
class_option :version, desc: "Run commands against a specific app version" class_option :version, desc: "Run commands against a specific app version"
class_option :use_prebuilt_image, type: :boolean, default: false, desc: "Use prebuilt image, skip building"
class_option :primary, type: :boolean, aliases: "-p", desc: "Run commands only on primary host instead of all" class_option :primary, type: :boolean, aliases: "-p", desc: "Run commands only on primary host instead of all"
class_option :hosts, aliases: "-h", desc: "Run commands on these hosts instead of all (separate by comma)" class_option :hosts, aliases: "-h", desc: "Run commands on these hosts instead of all (separate by comma)"
@@ -42,6 +43,7 @@ module Mrsk::Cli
commander.config_file = Pathname.new(File.expand_path(options[:config_file])) commander.config_file = Pathname.new(File.expand_path(options[:config_file]))
commander.destination = options[:destination] commander.destination = options[:destination]
commander.version = options[:version] commander.version = options[:version]
commander.use_prebuilt_image = options[:use_prebuilt_image]
commander.specific_hosts = options[:hosts]&.split(",") commander.specific_hosts = options[:hosts]&.split(",")
commander.specific_roles = options[:roles]&.split(",") commander.specific_roles = options[:roles]&.split(",")

View File

@@ -1,8 +1,7 @@
class Mrsk::Cli::Build < Mrsk::Cli::Base class Mrsk::Cli::Build < Mrsk::Cli::Base
desc "deliver", "Build app and push app image to registry then pull image on servers" desc "deliver", "Build app and push app image to registry then pull image on servers"
option :use_prebuilt_image, aliases: "-P", type: :boolean, default: false, desc: "Use prebuilt image, skip build"
def deliver def deliver
push unless options[:use_prebuilt_image] push unless MRSK.use_prebuilt_image
pull pull
end end

View File

@@ -9,44 +9,37 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
end end
desc "deploy", "Deploy app to servers" desc "deploy", "Deploy app to servers"
option :use_prebuilt_image, aliases: "-P", type: :boolean, default: false, desc: "Use prebuilt image, skip build"
def deploy def deploy
runtime = print_runtime do runtime = print_runtime do
say "Ensure curl and Docker are installed...", :magenta say "Ensure curl and Docker are installed...", :magenta
invoke "mrsk:cli:server:bootstrap", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:server:bootstrap"
say "Log into image registry...", :magenta say "Log into image registry...", :magenta
invoke "mrsk:cli:registry:login", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:registry:login"
say "Build and push app image...", :magenta say "Build and push app image...", :magenta
invoke "mrsk:cli:build:deliver" invoke "mrsk:cli:build:deliver"
say "Ensure Traefik is running...", :magenta say "Ensure Traefik is running...", :magenta
invoke "mrsk:cli:traefik:boot", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:traefik:boot"
say "Ensure app can pass healthcheck...", :magenta say "Ensure app can pass healthcheck...", :magenta
invoke "mrsk:cli:healthcheck:perform", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:healthcheck:perform"
invoke "mrsk:cli:app:boot", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:app:boot"
say "Prune old containers and images...", :magenta say "Prune old containers and images...", :magenta
invoke "mrsk:cli:prune:all", [], options.without(:use_prebuilt_image) invoke "mrsk:cli:prune:all"
end end
audit_broadcast "Deployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast] audit_broadcast "Deployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
end end
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login" desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
option :use_prebuilt_image, aliases: "-P", type: :boolean, default: false, desc: "Use prebuilt image, skip build"
def redeploy def redeploy
runtime = print_runtime do runtime = print_runtime do
unless options[:use_prebuilt_image]
say "Build and push app image...", :magenta say "Build and push app image...", :magenta
invoke "mrsk:cli:build:push" invoke "mrsk:cli:build:deliver"
end
say "Pull image onto servers...", :magenta
invoke "mrsk:cli:build:pull"
say "Ensure app can pass healthcheck...", :magenta say "Ensure app can pass healthcheck...", :magenta
invoke "mrsk:cli:healthcheck:perform" invoke "mrsk:cli:healthcheck:perform"

View File

@@ -1,7 +1,7 @@
require "active_support/core_ext/enumerable" require "active_support/core_ext/enumerable"
class Mrsk::Commander class Mrsk::Commander
attr_accessor :config_file, :destination, :verbosity, :version attr_accessor :config_file, :destination, :verbosity, :version, :use_prebuilt_image
def initialize(config_file: nil, destination: nil, verbosity: :info) def initialize(config_file: nil, destination: nil, verbosity: :info)
@config_file, @destination, @verbosity = config_file, destination, verbosity @config_file, @destination, @verbosity = config_file, destination, verbosity