Sha256: ab3991f31f7894849f92f91c769eb1f49ee0c10f9aa79e6e86dc3edc8e8621ed

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'yaml'

module Sct
  class DevCommand

    @@file = "docker-compose.dev.yml"

    def error message
      UI.error message
      exit 1
    end

    def dc command, env = {}
      system env, "docker-compose -f ~/development/spend-cloud/docker-compose.yml #{command}"
    end

    def dc_dev command, env = {}
      system env, "docker-compose -f #{@@file} #{command}"
    end

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

      YAML.load File.read @@file
    end

    def execute args, options
      services = manifest["services"].to_a

      if services.length != 1
        error "Currently sct only supports a single service declaration in '#{@@file}'. Contact the infra guild if you consider this a limitation."
      end

      service, service_spec = services.first

      container = service_spec["container_name"]
      command = service_spec["command"] || ""

      env = { "PUID" => `id -u`.chomp, "PGID" => `id -g`.chomp }

      if options.pull
        return unless dc_dev "pull"
      end

      if options.build
        return unless dc_dev "build #{options.pull ? "--pull" : ""}", env
      end

      if options.pull or options.build
        system "docker image prune -f"
      end

      return unless dc "rm --stop --force #{service}"

      dc_dev "run --rm --service-ports --name #{container} #{service} #{command}", env

      dc "up --detach #{service}"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sct-1.0.5 sct/lib/sct/commands/dev.rb
sct-1.0.4 sct/lib/sct/commands/dev.rb