Sha256: 07a5da67dda524abcd01cc67b283761f0d4bd308cce8f6ef0dc81808314bd138

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sct-1.10.2 cluster/lib/cluster/runner.rb
sct-1.10.1 cluster/lib/cluster/runner.rb
sct-1.10.0 cluster/lib/cluster/runner.rb
sct-1.9.0 cluster/lib/cluster/runner.rb