Merge branch 'main' into dockerfile-context-build-options

This commit is contained in:
Samuel Sieg
2023-03-09 08:54:23 +01:00
17 changed files with 250 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
desc "deploy", "Deploy app to servers"
def deploy
runtime = print_runtime do
say "Ensure Docker is installed...", :magenta
say "Ensure curl and Docker are installed...", :magenta
invoke "mrsk:cli:server:bootstrap"
say "Log into image registry...", :magenta
@@ -173,7 +173,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
desc "registry", "Login and -out of the image registry"
subcommand "registry", Mrsk::Cli::Registry
desc "server", "Bootstrap servers with Docker"
desc "server", "Bootstrap servers with curl and Docker"
subcommand "server", Mrsk::Cli::Server
desc "traefik", "Manage Traefik load balancer"

View File

@@ -1,6 +1,15 @@
class Mrsk::Cli::Server < Mrsk::Cli::Base
desc "bootstrap", "Ensure Docker is installed on servers"
desc "bootstrap", "Ensure curl and Docker are installed on servers"
def bootstrap
on(MRSK.hosts + MRSK.accessory_hosts) { execute "which docker || (apt-get update -y && apt-get install docker.io -y)" }
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
if dependencies_to_install.any?
execute "apt-get update -y && apt-get install #{dependencies_to_install.join(" ")} -y)"
end
end
end
end

View File

@@ -25,7 +25,7 @@ class Mrsk::Commander
end
def primary_host
specific_hosts&.sole || config.primary_web_host
specific_hosts&.first || config.primary_web_host
end
def hosts

View File

@@ -2,7 +2,7 @@ class Mrsk::Commands::Registry < Mrsk::Commands::Base
delegate :registry, to: :config
def login
docker :login, registry["server"], "-u", redact(registry["username"]), "-p", redact(lookup_password)
docker :login, registry["server"], "-u", redact(lookup("username")), "-p", redact(lookup("password"))
end
def logout
@@ -10,11 +10,11 @@ class Mrsk::Commands::Registry < Mrsk::Commands::Base
end
private
def lookup_password
if registry["password"].is_a?(Array)
ENV.fetch(registry["password"].first).dup
def lookup(key)
if registry[key].is_a?(Array)
ENV.fetch(registry[key].first).dup
else
registry["password"]
registry[key]
end
end
end

View File

@@ -4,7 +4,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
"--detach",
"--restart", "unless-stopped",
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
"--publish", "80:80",
"--publish", port,
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
"traefik",
"--providers.docker",
@@ -45,6 +45,10 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
end
def port
"#{config.raw_config.traefik.fetch("host_port", "80")}:80"
end
private
def cmd_args
(config.raw_config.dig(:traefik, "args") || { }).collect { |(key, value)| [ "--#{key}", value ] }.flatten