lib/vidar/cli.rb in vidar-0.3.4 vs lib/vidar/cli.rb in vidar-0.4.0

- old
+ new

@@ -57,33 +57,42 @@ Run.docker "push #{Config.get!(:image)}:release" Run.docker "push #{Config.get!(:image)}:latest" end desc "deploy", "Performs k8s deployment with deploy hook" - method_option :revision, default: nil + method_option :revision, required: false def deploy revision = options[:revision] || Config.get!(:revision) Log.info "Current cluster_name: #{Config.get!(:cluster_name)} ###" - Log.info "Set kubectl image..." - Run.kubectl "set image deployments,cronjobs *=#{Config.get!(:image)}:#{revision} --all" - 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? if template_name.to_s.empty? Log.info "No deploy hook found" else Log.info "Executing deploy hook #{template_name.strip!}..." Run.kubectl "delete job deploy-hook --ignore-not-found=true" + Run.kubectl "set image cronjobs deploy-hook-template=#{Config.get!(:image)}:#{revision} --all" Run.kubectl "create job deploy-hook --from=#{template_name}" + + deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace), filter: "deploy-hook") + deploy_status.wait_until_completed + + unless deploy_status.success? + Log.error "Error running deploy hook template" + exit(1) + end end else Log.info "Error getting deploy hook template: #{error}" exit(1) end + + Log.info "Set kubectl image..." + Run.kubectl "set image deployments,cronjobs *=#{Config.get!(:image)}:#{revision} --all" end desc "release", "Builds and publishes docker images" def release Log.info "Release #{options[:image]}:#{options[:revision]}" @@ -95,30 +104,32 @@ desc "monitor_deploy_status", "Checks is deployment has finished and sends post-deploy notification" method_option :success_color, required: false method_option :error_color, required: false def monitor_deploy_status - Log.info "Current cluster_name: #{Config.get!(:cluster_name)} ###" + Log.info "Current cluster_name: #{Config.get!(:cluster_name)}" Log.info "Checking is all containers on #{Config.get!(:cluster_name)} in #{Config.get!(:namespace)} are ready..." slack_notification = SlackNotification.new( - webhook_url: Config.get!(:slack_webhook_url), + webhook_url: Config.get(:slack_webhook_url), github: Config.get!(:github), revision: Config.get!(:revision), revision_name: Config.get!(:revision_name), cluster_label: Config.get!(:cluster_label), cluster_url: Config.get!(:cluster_url), success_color: options[:success_color], error_color: options[:error_color], ) - ok = Vidar::DeployStatus.new(Config.get!(:namespace)).ok? + deploy_status = Vidar::DeployStatus.new(namespace: Config.get!(:namespace)) - if ok - Log.info "OK: All containers are ready." + deploy_status.wait_until_completed + + if deploy_status.success? + Log.info "OK: All containers are ready" slack_notification.success if slack_notification.configured? else - Log.error "ERROR: Some of containers are not ready." + Log.error "ERROR: Some of containers are errored or not ready" slack_notification.error if slack_notification.configured? exit(1) end end end