module Cluster class Runner KEY_CADDYFILE_PATH = "CADDYFILE_PATH" @@dc = system("docker compose version", out: "/dev/null", err: "/dev/null") ? "docker compose" : "docker-compose" def run command, options = {} begin if !system command, options raise command.red end rescue Interrupt # user pressed Ctrl+C, do nothing end end def dc command, options = {} run "#{@@dc} -f ~/development/spend-cloud/docker-compose.yml #{command}", options end def start args, options ENV.delete(KEY_CADDYFILE_PATH) if (options.nuxt) ENV[KEY_CADDYFILE_PATH] = './docker/caddy/Caddyfile-nuxt' end if options.pull dc "pull" end if options.build dc "build #{options.pull ? "--pull" : ""}" end run "docker container prune -f" dc "up --detach --remove-orphans --force-recreate --always-recreate-deps" if options.pull or options.build system "docker image prune -f" end UI.success("\nāœ”ļø You can visit your environment at šŸ‘‰ https://spend-cloud.dev.spend.cloud šŸ‘Œ") end def stop dc "down --remove-orphans" end def delete dc "down --remove-orphans -v" end def reset args, options delete start args, options end def status dc "ps" end def logs args, options command = "logs" command << " --follow" if options.f or options.follow command << " --timestamps" if options.t or options.timestamps command << " --tail #{options.tail}" if options.tail dc "#{command} #{args.join " "}" end end end