class Renuo::Cli::Commands::CheckDeploioStatus
:nocov:
Constants
- APP_NAME
- INTERVAL_IN_SECONDS
- PROJECT
- TIMEOUT_IN_SECONDS
Public Class Methods
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 19 def initialize(options) abort "missing env DEPLOIO_APP_NAME" if APP_NAME.nil? abort "missing env DEPLOIO_PROJECT" if PROJECT.nil? @revision = options.git_revision || `git rev-parse HEAD`.strip end
Public Instance Methods
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 25 def run puts "(1/2) Checking build status for revision #{@revision}..." poll "build" abort "build check timed out after #{TIMEOUT_IN_SECONDS} seconds" if build.nil? puts "(2/2) Checking release status for build #{build_name}..." poll "release" abort "release check timed out after #{TIMEOUT_IN_SECONDS} seconds" if release.nil? end
Private Instance Methods
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 57 def build @build ||= fetch("builds").find do |build| build.dig("spec", "forProvider", "sourceConfig", "git", "revision") == @revision end end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 63 def build_name @build_name ||= build.dig("metadata", "name") end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 67 def build_status build.dig("status", "atProvider", "buildStatus") end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 41 def fetch(type) command = "nctl get #{type} -a #{APP_NAME} -p #{PROJECT} -o yaml" stdout, stderr, status = Open3.capture3 command abort "error fetching #{type} information: #{stderr}" unless status.success? Psych.load_stream stdout end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 49 def fetch_build_logs command = "nctl logs build -a #{APP_NAME} -p #{PROJECT} -l 5000 --no-labels" stdout, stderr, status = Open3.capture3 command abort "error fetching build logs: #{stderr}" unless status.success? stdout end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 95 def poll(type) elapsed = 0 while elapsed < TIMEOUT_IN_SECONDS if send type break if succeeded?(send(:"#{type}_status"), type) else puts "no matching #{type} found, waiting..." end sleep INTERVAL_IN_SECONDS elapsed += INTERVAL_IN_SECONDS end end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 71 def release @release ||= fetch("releases").find do |release| release.dig("spec", "forProvider", "build", "name") == build_name end end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 77 def release_status release.dig("status", "atProvider", "releaseStatus") end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 81 def succeeded?(status, type) # rubocop:disable Metrics/MethodLength case status when "available", "success" puts "#{type} succeeded" true when "error", "failed", "failure" puts fetch_build_logs abort "#{type} failed" else puts "#{type} status is #{status}, waiting..." instance_variable_set :"@#{type}", nil end end
Source
# File lib/renuo/cli/commands/check_deploio_status.rb, line 37 def system!(cmd) abort unless system cmd end