Merge branch 'main' into pr/223
* main: Don't run actions twice on PRs Further distinguish dependency verification Naming Reveal configured dockerfile path Style Distinguish from server dependencies Distinguish from local dependency verification Improve clarity and intent Style Style Style Add local dependencies check Bootstrap: use multi-platform installer
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
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
|
||||
@@ -14,7 +16,9 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
|
||||
run_locally do
|
||||
begin
|
||||
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
|
||||
if cli.verify_local_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"
|
||||
@@ -77,4 +81,22 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
|
||||
puts capture(*MRSK.builder.info)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
desc "", "" # Really a private method, but needed to be invoked from #push
|
||||
def verify_local_dependencies
|
||||
run_locally do
|
||||
begin
|
||||
execute *MRSK.builder.ensure_local_dependencies_installed
|
||||
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
|
||||
|
||||
@@ -17,9 +17,6 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
invoke_options = deploy_options
|
||||
|
||||
runtime = print_runtime do
|
||||
say "Ensure curl and Docker are installed...", :magenta
|
||||
invoke "mrsk:cli:server:bootstrap", [], invoke_options
|
||||
|
||||
say "Log into image registry...", :magenta
|
||||
invoke "mrsk:cli:registry:login", [], invoke_options
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
class Mrsk::Cli::Server < Mrsk::Cli::Base
|
||||
desc "bootstrap", "Ensure curl and Docker are installed on servers"
|
||||
desc "bootstrap", "Set up Docker to run MRSK apps"
|
||||
def bootstrap
|
||||
with_lock do
|
||||
on(MRSK.hosts + MRSK.accessory_hosts) do
|
||||
dependencies_to_install = Array.new.tap do |dependencies|
|
||||
dependencies << "curl" unless execute "which curl", raise_on_non_zero_exit: false
|
||||
dependencies << "docker.io" unless execute "which docker", raise_on_non_zero_exit: false
|
||||
end
|
||||
missing = []
|
||||
|
||||
if dependencies_to_install.any?
|
||||
execute "apt-get update -y && apt-get install #{dependencies_to_install.join(" ")} -y"
|
||||
on(MRSK.hosts | MRSK.accessory_hosts) do |host|
|
||||
unless execute(*MRSK.docker.installed?, raise_on_non_zero_exit: false)
|
||||
if execute(*MRSK.docker.superuser?, raise_on_non_zero_exit: false)
|
||||
info "Missing Docker on #{host}. Installing…"
|
||||
execute *MRSK.docker.install
|
||||
else
|
||||
missing << host
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if missing.any?
|
||||
raise "Docker is not installed on #{missing.join(", ")} and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,6 +92,10 @@ class Mrsk::Commander
|
||||
@builder ||= Mrsk::Commands::Builder.new(config)
|
||||
end
|
||||
|
||||
def docker
|
||||
@docker ||= Mrsk::Commands::Docker.new(config)
|
||||
end
|
||||
|
||||
def healthcheck
|
||||
@healthcheck ||= Mrsk::Commands::Healthcheck.new(config)
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
|
||||
delegate :create, :remove, :push, :clean, :pull, :info, to: :target
|
||||
|
||||
def name
|
||||
target.class.to_s.remove("Mrsk::Commands::Builder::").underscore
|
||||
target.class.to_s.remove("Mrsk::Commands::Builder::").underscore.inquiry
|
||||
end
|
||||
|
||||
def target
|
||||
@@ -33,4 +33,24 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
|
||||
def multiarch_remote
|
||||
@multiarch_remote ||= Mrsk::Commands::Builder::Multiarch::Remote.new(config)
|
||||
end
|
||||
|
||||
|
||||
def ensure_local_dependencies_installed
|
||||
if name.native?
|
||||
ensure_local_docker_installed
|
||||
else
|
||||
combine \
|
||||
ensure_local_docker_installed,
|
||||
ensure_local_buildx_installed
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def ensure_local_docker_installed
|
||||
docker "--version"
|
||||
end
|
||||
|
||||
def ensure_local_buildx_installed
|
||||
docker :buildx, "version"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
|
||||
class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base
|
||||
class BuilderError < StandardError; end
|
||||
|
||||
delegate :argumentize, to: Mrsk::Utils
|
||||
|
||||
def clean
|
||||
@@ -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
|
||||
|
||||
21
lib/mrsk/commands/docker.rb
Normal file
21
lib/mrsk/commands/docker.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Mrsk::Commands::Docker < Mrsk::Commands::Base
|
||||
# Install Docker using the https://github.com/docker/docker-install convenience script.
|
||||
def install
|
||||
pipe [ :curl, "-fsSL", "https://get.docker.com" ], :sh
|
||||
end
|
||||
|
||||
# Checks the Docker client version. Fails if Docker is not installed.
|
||||
def installed?
|
||||
docker "-v"
|
||||
end
|
||||
|
||||
# Checks the Docker server version. Fails if Docker is not running.
|
||||
def running?
|
||||
docker :version
|
||||
end
|
||||
|
||||
# Do we have superuser access to install Docker and start system services?
|
||||
def superuser?
|
||||
[ '[ "${EUID:-$(id -u)}" -eq 0 ]' ]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user