lib/vidar/cli.rb in vidar-0.6.0 vs lib/vidar/cli.rb in vidar-0.7.0
- old
+ new
@@ -4,67 +4,61 @@
def self.exit_on_failure?
true
end
- desc "run_runner", "Runs any given command in runner image"
+ desc "exec", "Run any command in given docker-compose target, default target is `runner`"
option :command
- def run_runner
+ option :target, default: "runner"
+ def exec
Run.docker_compose("run runner #{options[:command]}") || exit(1)
end
- desc "pull", "Pulls existing docker images to leverage docker caching"
+ desc "pull", "Pull existing docker images to leverage docker caching"
def pull
Log.info "Pulling #{Config.get!(:image)} tags"
- Run.docker "pull #{Config.get!(:image)}:builder-#{Config.get!(:current_branch)} 2> /dev/null || true"
- Run.docker "pull #{Config.get!(:image)}:builder 2> /dev/null || true"
+ Run.docker "pull #{Config.get!(:image)}:runner-#{Config.get!(:current_branch)} 2> /dev/null || true"
+ Run.docker "pull #{Config.get!(:image)}:runner-#{Config.get!(:default_branch)} 2> /dev/null || true"
Run.docker "pull #{Config.get!(:image)}:release 2> /dev/null || true"
Log.info "Docker images:"
- Log.info Run.docker("images")
+ Run.docker("images")
end
- desc "build", "Builds docker stages"
+ desc "build", "Build docker stages"
def build
- Log.info "Building #{Config.get!(:image)}:builder-#{Config.get!(:current_branch)}"
- Run.docker_compose "build builder"
-
- Log.info "Building #{Config.get!(:image)}:runner-#{Config.get!(:current_branch)}"
+ Log.info "Building runner image"
Run.docker_compose "build runner"
- Log.info "Building #{Config.get!(:image)}:release"
+ Log.info "Building release image"
Run.docker_compose "build release"
end
desc "cache", "Caches intermediate docker stages"
def cache
- Log.info "Publish #{Config.get!(:image)}:builder-#{Config.get!(:current_branch)}"
- Run.docker "push #{Config.get!(:image)}:builder-#{Config.get!(:current_branch)}"
+ Log.info "Publishing runner image"
+ Run.docker "push #{Config.get!(:image)}:runner-#{Config.get!(:current_branch)}"
end
- desc "publish", "Publishes docker images on docker registry"
+ desc "publish", "Publish docker images on docker registry"
def publish
- Log.info "Publish #{Config.get!(:image)}:#{Config.get!(:revision)}"
+ Log.info "Publishing #{Config.get!(:image)}:#{Config.get!(:revision)}"
Run.docker "tag #{Config.get!(:image)}:release #{Config.get!(:image)}:#{Config.get!(:revision)}"
Run.docker "push #{Config.get!(:image)}:#{Config.get!(:revision)}"
return unless Config.get!(:current_branch) == Config.get!(:default_branch)
- Log.info "Publish #{Config.get!(:image)}:builder"
- Run.docker "tag #{Config.get!(:image)}:builder-#{Config.get!(:current_branch)} #{Config.get!(:image)}:builder"
- Run.docker "push #{Config.get!(:image)}:builder"
-
- Log.info "Publish #{Config.get!(:image)}:latest"
+ Log.info "Publishing #{Config.get!(:image)}:release"
Run.docker "tag #{Config.get!(:image)}:release #{Config.get!(:image)}:latest"
Run.docker "push #{Config.get!(:image)}:release"
Run.docker "push #{Config.get!(:image)}:latest"
end
- desc "deploy", "Performs k8s deployment with deploy hook"
+ desc "deploy", "Perform k8s deployment with deploy hook"
method_option :revision, required: false
def deploy
revision = options[:revision] || Config.get!(:revision)
- Log.info "Current kubectl context: #{Config.get!(:kubectl_context)} ###"
+ Log.info "Current kubectl context: #{Config.get!(:kubectl_context)}"
Log.info "Looking for deploy hook..."
template_name, error, status = Open3.capture3 "kubectl get cronjob deploy-hook-template -n #{Config.get!(:namespace)} -o name --ignore-not-found=true"
if status.success?
@@ -92,21 +86,21 @@
Log.info "Set kubectl image..."
Run.kubectl "set image deployments,cronjobs *=#{Config.get!(:image)}:#{revision} --all"
end
- desc "release", "Builds and publishes docker images"
+ desc "release", "Build and publish docker images"
def release
- Log.info "Release #{options[:image]}:#{options[:revision]}"
+ Log.info "Build and release #{Config.get!(:image)}:#{Config.get!(:revision)}"
pull
build
cache
publish
end
- desc "monitor_deploy_status", "Checks is deployment has finished and sends post-deploy notification"
+ desc "monitor_deploy_status", "Check is deployment has finished and sends post-deploy notification"
def monitor_deploy_status
- Log.info "Current kubectl context: #{Config.get!(:kubectl_context)} ###"
+ Log.info "Current kubectl context: #{Config.get!(:kubectl_context)}"
Log.info "Checking if all containers in #{Config.get!(:namespace)} namespace(s) are ready..."
deploy_config = Config.deploy_config
Log.error "ERROR: could not find deployment config for #{Config.get!(:kubectl_context)} context" unless deploy_config