Add local dependencies check
Add checks for: * Docker installed locally * Docker buildx plugin installed locally * Dockerfile exists If checks fail, it will halt deployment and provide more specific error messages. Also adds a cli subcommand: `mrsk build dependencies` Fixes: #109 and #237
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
|
||||
class BuildError < StandardError; end
|
||||
|
||||
desc "deliver", "Build app and push app image to registry then pull image on servers"
|
||||
def deliver
|
||||
with_lock do
|
||||
@@ -10,16 +13,18 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
desc "push", "Build and push app image to registry"
|
||||
def push
|
||||
with_lock do
|
||||
cli = self
|
||||
cli_build = self
|
||||
|
||||
run_locally do
|
||||
begin
|
||||
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
|
||||
if cli_build.dependencies
|
||||
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
|
||||
end
|
||||
rescue SSHKit::Command::Failed => e
|
||||
if e.message =~ /(no builder)|(no such file or directory)/
|
||||
error "Missing compatible builder, so creating a new one first"
|
||||
|
||||
if cli.create
|
||||
if cli_build.create
|
||||
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
|
||||
end
|
||||
else
|
||||
@@ -77,4 +82,19 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
puts capture(*MRSK.builder.info)
|
||||
end
|
||||
end
|
||||
|
||||
desc "dependencies", "Check local dependencies"
|
||||
def dependencies
|
||||
run_locally do
|
||||
begin
|
||||
execute *MRSK.builder.dependencies
|
||||
rescue SSHKit::Command::Failed => e
|
||||
build_error = e.message =~ /command not found/ ?
|
||||
"Docker is not installed locally" :
|
||||
"Docker buildx plugin is not installed locally"
|
||||
raise BuildError, build_error
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,4 +33,28 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
|
||||
def multiarch_remote
|
||||
@multiarch_remote ||= Mrsk::Commands::Builder::Multiarch::Remote.new(config)
|
||||
end
|
||||
|
||||
def native_and_local?
|
||||
name == 'native'
|
||||
end
|
||||
|
||||
def dependencies
|
||||
if native_and_local?
|
||||
docker_version
|
||||
else
|
||||
combine \
|
||||
docker_version,
|
||||
docker_buildx_version
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def docker_version
|
||||
docker "--version"
|
||||
end
|
||||
|
||||
def docker_buildx_version
|
||||
docker :buildx, "version"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base
|
||||
delegate :argumentize, to: Mrsk::Utils
|
||||
|
||||
class BuilderError < StandardError; end
|
||||
|
||||
def clean
|
||||
docker :image, :rm, "--force", config.absolute_image
|
||||
end
|
||||
@@ -17,6 +20,7 @@ class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base
|
||||
context
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def build_tags
|
||||
[ "-t", config.absolute_image, "-t", config.latest_image ]
|
||||
@@ -35,7 +39,11 @@ class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base
|
||||
end
|
||||
|
||||
def build_dockerfile
|
||||
argumentize "--file", dockerfile
|
||||
if Pathname.new(File.expand_path(dockerfile)).exist?
|
||||
argumentize "--file", dockerfile
|
||||
else
|
||||
raise BuilderError, "Missing Dockerfile"
|
||||
end
|
||||
end
|
||||
|
||||
def args
|
||||
|
||||
Reference in New Issue
Block a user