Class: Envirobly::Cli::Main

Inherits:
Base
  • Object
show all
Includes:
Envirobly::Colorize
Defined in:
lib/envirobly/cli/main.rb

Constant Summary

Constants included from Envirobly::Colorize

Envirobly::Colorize::BLUE, Envirobly::Colorize::BOLD, Envirobly::Colorize::FAINT, Envirobly::Colorize::GREEN, Envirobly::Colorize::RED, Envirobly::Colorize::RESET, Envirobly::Colorize::YELLOW

Instance Method Summary collapse

Methods included from Envirobly::Colorize

#bold, #cross, #display_config_errors, #downwards_arrow_to_right, #faint, #green, #green_check, #red, #yellow

Methods inherited from Base

exit_on_failure?

Instance Method Details

#deploy(environ_name = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/envirobly/cli/main.rb', line 89

def deploy(environ_name = nil)
  commit = Envirobly::Git::Commit.new options.commit

  unless commit.exists?
    say_error "Commit '#{commit.ref}' doesn't exist in this repository"
    exit 1
  end

  Envirobly::AccessToken.new(shell:).require!

  deployment = Envirobly::Deployment.new(
    account_id: options.,
    region: options.region,
    project_id: options.project_id,
    project_name: options.project_name,
    environ_name: environ_name.presence,
    commit:,
    shell:
  )
  deployment.perform(dry_run: options.dry_run)
end

#exec(service_name, *command) ⇒ Object



130
131
132
# File 'lib/envirobly/cli/main.rb', line 130

def exec(service_name, *command)
  Envirobly::ContainerShell.new(service_name, options, shell:).exec(command)
end

#instance_types(region = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/envirobly/cli/main.rb', line 59

def instance_types(region = nil)
  default_region = Envirobly::Defaults::Region.new(shell:)
  region = region.presence || default_region.require_if_none

  api = Envirobly::Api.new
  table_data = api.list_instance_types(region).object.map do |item|
    [
      item["code"],
      item["vcpu"],
      Envirobly::Numeric.new(item["memory"], short: true),
      Envirobly::Numeric.new(item["monthly_price"]),
      item["group"]
    ]
  end

  print_table [ [ "Name", "vCPU", "Memory (GB)", "Monthly price ($)", "Group" ] ] +
    table_data, borders: true
end

#pull(region, bucket, ref, path) ⇒ Object



112
113
114
115
116
# File 'lib/envirobly/cli/main.rb', line 112

def pull(region, bucket, ref, path)
  Envirobly::Duration.measure("Build context download took %s") do
    Envirobly::Aws::S3.new(region:, bucket:).pull ref, path
  end
end

#rsync(source, destination) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/envirobly/cli/main.rb', line 142

def rsync(source, destination)
  service_name = nil

  [ source, destination ].each do |path|
    if path =~ /\A([a-z0-9\-_]+):/i
      service_name = $1
      break
    end
  end

  Envirobly::ContainerShell.new(service_name, options, shell:).rsync(source, destination)
end

#set_default_accountObject



31
32
33
# File 'lib/envirobly/cli/main.rb', line 31

def 
  Envirobly::Defaults::Account.new(shell:).require_value
end

#set_default_regionObject



36
37
38
# File 'lib/envirobly/cli/main.rb', line 36

def set_default_region
  Envirobly::Defaults::Region.new(shell:).require_value
end

#signinObject



17
18
19
20
# File 'lib/envirobly/cli/main.rb', line 17

def 
  access_token = Envirobly::AccessToken.new(shell:)
  access_token.set
end

#signoutObject



23
24
25
26
27
28
# File 'lib/envirobly/cli/main.rb', line 23

def signout
  Envirobly::AccessToken.destroy
  say "You've signed out."
  say "This didn't delete the access token itself."
  say "You can sign in again with `envirobly signin`."
end

#validateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/envirobly/cli/main.rb', line 41

def validate
  Envirobly::AccessToken.new(shell:).require!

  configs = Envirobly::Config.new
  api = Envirobly::Api.new

  params = { validation: configs.to_params }
  response = api.validate_shape params

  if response.object.fetch("valid")
    puts "Config is valid #{green_check}"
  else
    display_config_errors response.object.fetch("errors")
    exit 1
  end
end

#versionObject



8
9
10
11
12
13
14
# File 'lib/envirobly/cli/main.rb', line 8

def version
  if options.pure
    puts Envirobly::VERSION
  else
    puts "envirobly CLI v#{Envirobly::VERSION}"
  end
end