Module: Dapp::Deployment::Dapp::Command::Apply

Included in:
Dapp
Defined in:
lib/dapp/deployment/dapp/command/apply.rb

Instance Method Summary collapse

Instance Method Details

#deployment_applyObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
64
65
66
# File 'lib/dapp/deployment/dapp/command/apply.rb', line 6

def deployment_apply
  repo = option_repo
  image_version = options[:image_version]

  validate_repo_name!(repo)
  validate_tag_name!(image_version)

  log_process("Applying deployment #{deployment.name}") do
    deployment.kube.delete_unknown_resources!

    deployment.to_kube_bootstrap_pods(repo, image_version).each do |name, spec|
      next if deployment.kube.pod_succeeded?(name)
      deployment.kube.delete_pod!(name) if deployment.kube.pod_exist?(name)
      log_process(:bootstrap) do
        deployment.kube.run_job!(spec, name)
      end
    end

    deployment.to_kube_before_apply_job_pods(repo, image_version).each do |name, spec|
      log_process(:before_apply_job) do
        deployment.kube.delete_pod!(name) if deployment.kube.pod_exist?(name)
        deployment.kube.run_job!(spec, name)
      end
    end

    deployment.apps.each do |app|
      log_process("Applying app #{app.name}") do
        (app.kube.existing_deployments_names - app.to_kube_deployments(repo, image_version).keys).each do |deployment_name|
          app.kube.delete_deployment!(deployment_name)
        end

        (app.kube.existing_services_names - app.to_kube_services.keys).each do |service_name|
          app.kube.delete_service!(service_name)
        end

        app.to_kube_bootstrap_pods(repo, image_version).each do |name, spec|
          next if app.kube.pod_succeeded?(name)
          app.kube.delete_pod!(name) if app.kube.pod_exist?(name)
          log_process(:bootstrap) do
            app.kube.run_job!(spec, name)
          end
        end

        app.to_kube_before_apply_job_pods(repo, image_version).each do |name, spec|
          log_process(:before_apply_job) do
            app.kube.delete_pod!(name) if app.kube.pod_exist?(name)
            app.kube.run_job!(spec, name)
          end
        end

        app.to_kube_deployments(repo, image_version).each do |name, spec|
          app.kube.apply_deployment!(name, spec)
        end

        app.to_kube_services.each do |name, spec|
          app.kube.apply_service!(name, spec)
        end
      end
    end
  end
end