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:
Jberczel
2023-05-01 15:26:50 -04:00
parent 4fa6a6c06d
commit bfb70b2118
5 changed files with 83 additions and 4 deletions

View File

@@ -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

View File

@@ -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