Class: Nvoi::Cli::Deploy::Steps::DeployService

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/cli/deploy/steps/deploy_service.rb

Overview

DeployService handles K8s deployment of all services

Constant Summary collapse

DEFAULT_RESOURCES =
{
  request_memory: "128Mi",
  request_cpu: "100m",
  limit_memory: "512Mi",
  limit_cpu: "500m"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config, ssh, tunnels, log) ⇒ DeployService

Returns a new instance of DeployService.



16
17
18
19
20
21
22
23
# File 'lib/nvoi/cli/deploy/steps/deploy_service.rb', line 16

def initialize(config, ssh, tunnels, log)
  @config = config
  @ssh = ssh
  @tunnels = tunnels
  @log = log
  @namer = config.namer
  @kubectl = External::Kubectl.new(ssh)
end

Instance Method Details

#run(registry_tag, timestamp) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nvoi/cli/deploy/steps/deploy_service.rb', line 25

def run(registry_tag, timestamp)
  # Image is already in registry (pushed via SSH tunnel in BuildImage step)
  @log.info "Using image from registry: %s", registry_tag

  # Gather env vars
  first_service = @config.deploy.application.app.keys.first
  all_env = @config.env_for_service(first_service)

  # Deploy app secret
  deploy_app_secret(all_env)

  # Deploy database if configured
  db_config = @config.deploy.application.database
  if db_config
    db_spec = db_config.to_service_spec(@namer)
    deploy_database(db_spec) if db_spec
  end

  # Deploy additional services
  @config.deploy.application.services.each do |service_name, service_config|
    service_spec = service_config.to_service_spec(@config.deploy.application.name, service_name)
    deploy_service(service_name, service_spec)
  end

  # Deploy app services
  @config.deploy.application.app.each do |service_name, service_config|
    service_env = @config.env_for_service(service_name)
    deploy_app_service(service_name, service_config, registry_tag, service_env)

    # Deploy cloudflared for services with tunnels
    tunnel = @tunnels.find { |t| t.service_name == service_name }
    if tunnel
      deploy_cloudflared(service_name, tunnel.tunnel_token)
      verify_traffic_switchover(service_config)
    end
  end

  @log.success "All services deployed"
end