Sha256: bcab9b8693dfb59098c4c07b613df2e734dfd93f68e2f8a8e0b09418476456da

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

require 'yaml'

module Sct
  class ShellCommand

    def error message
      UI.error message
      exit 1
    end

    def execute args, options
      command = args.empty? ? "sh" : args.join(" ")

      file = "docker-compose.dev.yml"

      if !File.exist? file
        error "Could not find file '#{file}'."
      end

      manifest = YAML.load File.read file

      services = manifest["services"].to_a

      service, service_spec = services.first

      container = service_spec["container_name"]

      project = `docker container inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' #{container}`.chomp

      if project == "spend-cloud"
        print "This container was not started with 'sct dev'. Are you sure you want to continue? [y/N] ".red

        answer = $stdin.readline.chomp.downcase

        if answer != "y"
          exit
        end
      end

      user = options.root ? "root:root" : "$(id -u):$(id -g)"

      puts "Attaching to shell in container #{container.bold}".green

      system "docker exec -it --user #{user} #{container} #{command}"
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sct-1.10.0 sct/lib/sct/commands/shell.rb
sct-1.9.0 sct/lib/sct/commands/shell.rb
sct-1.8.2 sct/lib/sct/commands/shell.rb
sct-1.8.1 sct/lib/sct/commands/shell.rb
sct-1.8.0 sct/lib/sct/commands/shell.rb
sct-1.7.0 sct/lib/sct/commands/shell.rb
sct-1.6.3 sct/lib/sct/commands/shell.rb
sct-1.5.1 sct/lib/sct/commands/shell.rb
sct-1.5.0 sct/lib/sct/commands/shell.rb
sct-1.4.0 sct/lib/sct/commands/shell.rb
sct-1.3.0 sct/lib/sct/commands/shell.rb
sct-1.2.0 sct/lib/sct/commands/shell.rb