Class: FaaStRuby::Command::Function::DeployTo

Inherits:
FunctionBaseCommand show all
Defined in:
lib/faastruby/cli/commands/function/deploy_to.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FunctionBaseCommand

#load_yaml

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ DeployTo

Returns a new instance of DeployTo.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 7

def initialize(args)
  @args = args
  help
  @missing_args = []
  FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
  @workspace_name = @args.shift
  parse_options
  load_yaml
  @yaml_config['before_build'] ||= []
  @function_name = @yaml_config['name']
  unless @yaml_config['serve_static']
    @options['root_to'] = @function_name if @options['is_root']
    @options['catch_all'] = @function_name if @options['is_catch_all']
    # @abort_when_tests_fail = true #@yaml_config['abort_deploy_when_tests_fail']
  end
  load_credentials
  @package_file = Tempfile.new('package')
end

Class Method Details

.helpObject



85
86
87
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 85

def self.help
  "deploy-to WORKSPACE_NAME [ARGS]"
end

Instance Method Details

#crystal_runtime?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 30

def crystal_runtime?
  return false if @yaml_config['runtime'].nil?
  @yaml_config['runtime'].match(/^crystal/)
end

#ruby_runtime?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 26

def ruby_runtime?
  @yaml_config['runtime'].nil? || @yaml_config['runtime'].match(/^ruby/)
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 41

def run
  create_or_use_workspace
  if @yaml_config['serve_static']
    if @options['quiet']
      puts "[#{@function_name}] Deploying static files '#{@function_name}' to workspace '#{@workspace_name}'..."
      spinner = spin("")
    else
      spinner = say("[#{@function_name}] Deploying static files '#{@function_name}' to workspace '#{@workspace_name}'...")
    end
    package_file_name = build_package
    workspace = FaaStRuby::Workspace.new(name: @workspace_name).deploy(package_file_name)
  else
    if @options['quiet']
      puts "[#{@function_name}] Deploying #{runtime_name} function '#{@function_name}' to workspace '#{@workspace_name}'..."
      spinner = spin("")
    else
      spinner = spin("[#{@function_name}] Deploying #{runtime_name} function '#{@function_name}' to workspace '#{@workspace_name}'...")
    end
    if ruby_runtime?
      FaaStRuby::CLI.error('Please fix the problems above and try again') unless bundle_install
    end
    if crystal_runtime?
      FaaStRuby::CLI.error('Please fix the problems above and try again') unless shards_install
    end
    FaaStRuby::CLI.error("[#{@function_name}] Deploy aborted because 'test_command' exited non-zero.") unless run_tests
    package_file_name = build_package
    workspace = FaaStRuby::Workspace.new(name: @workspace_name).deploy(package_file_name, root_to: @options['root_to'], catch_all: @options['catch_all'], context: @options['context'])
  end
  if workspace.errors.any?
    puts ' Failed :(' unless spinner&.error
    @package_file.unlink
    FaaStRuby::CLI.error(workspace.errors)
  end
  spinner.success unless @options['quiet']
  @package_file.unlink
  puts "* [#{@function_name}] Deploy OK".green
  unless @yaml_config['serve_static']
    puts "* [#{@function_name}] Workspace: #{@workspace_name}".green
    puts "* [#{@function_name}] Endpoint: #{FaaStRuby.workspace_host_for(@workspace_name)}/#{@function_name unless @options['root_to']}".green
  end
  puts '---'
  exit 0
end

#runtime_nameObject



35
36
37
38
39
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 35

def runtime_name
  return 'Ruby' if ruby_runtime?
  return 'Crystal' if crystal_runtime?
  return 'Ruby'
end

#usageObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/faastruby/cli/commands/function/deploy_to.rb', line 89

def usage
  puts "\nUsage: faastruby #{self.class.help}"
  puts %(
-f,--function PATH/TO/FUNCTION     # Specify the directory where the function is.
--context 'JSON_STRING'            # The data to be stored as execution context
                           #  in the cloud, accessible via 'event.context'
                           #  from within your function.
                           #  The context data must be a JSON String, and
                           #  have maximum size of 4KB.
--context-from-stdin               # Read context data from STDIN.
--set-root                         # Set the function as the root route for the workspace.
--set-catch-all                    # Set the function as the catch-all route for the workspace.
--dont-create-workspace            # Don't try to create the workspace if it doesn't exist.
--skip-dependencies                # Don't try to install Gems or Shards before creating
                           #  the deployment package
  )
end