sct/lib/sct/commands/dev.rb in sct-1.0.0 vs sct/lib/sct/commands/dev.rb in sct-1.0.1
- old
+ new
@@ -1,43 +1,61 @@
require 'yaml'
module Sct
class DevCommand
+ @@file = "docker-compose.dev.yml"
+
def error message
UI.error message
exit 1
end
- def execute args, options
- file = "docker-compose.dev.yml"
+ def dc command
+ system "docker-compose -f ~/development/spend-cloud/docker-compose.yml #{command}"
+ end
- if !File.exist? file
- error "Could not find file '#{file}'."
+ def local_dc command
+ system "docker-compose -f #{@@file} #{command}"
+ end
+
+ def manifest
+ if !File.exist? @@file
+ error "Could not find file '#{@@file}'."
end
- manifest = YAML.load File.read file
+ 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."
+ 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"] || ""
+ if options.pull
+ return unless local_dc "pull"
+ end
+
if options.build
- return unless system "docker-compose -f #{file} build #{options.pull ? "--pull" : ""}"
+ return unless local_dc "build --build-arg PUID=$(id -u) --build-arg PGID=$(id -g) #{options.pull ? "--pull" : ""}"
end
- return unless system "docker-compose -f ~/development/spend-cloud/docker-compose.yml rm --stop --force #{service}"
+ if options.pull or options.build
+ system "docker image prune -f"
+ end
- system "docker-compose -f #{file} run --rm --service-ports --name #{container} #{service} #{command}"
+ return unless dc "rm --stop --force #{service}"
- system "docker-compose -f ~/development/spend-cloud/docker-compose.yml up --detach #{service}"
+ local_dc "run --rm --service-ports --name #{container} #{service} #{command}"
+
+ dc "up --detach #{service}"
end
end
end