Class: Luban::Deployment::Application::Dockerizer
- Inherits:
-
Worker
show all
- Defined in:
- lib/luban/deployment/cli/application/docker/dockerizer.rb
Constant Summary
collapse
- DefaultRevisionSize =
12
Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge
Parameters::General::DefaultLubanRootPath
Helpers::Utils::LogLevels
Instance Attribute Summary collapse
Attributes inherited from Worker::Base
#task
#backend
#config
Instance Method Summary
collapse
Methods inherited from Worker
#bundle_command, #bundle_executable, #docker_path, #gemfile, #has_gemfile?, #profile_name, #release_path, #release_tag, #releases_path, #ruby_bin_path, #shell_setup
#package_bin_path, #package_install_path, #packages_path
#control_file_dir, #control_file_name, #control_file_path, #control_path, #log_file_name, #log_file_path, #log_path, #output_redirection, #pid_file_name, #pid_file_path, #pids_path, #profile_name, #profile_path, #service_entry, #shell_command, #shell_delimiter, #shell_output, #shell_prefix, #shell_setup
#app_archives_path, #app_bin_path, #app_path, #app_tmp_path, #archived_logs_path, #archives_path, #current_app_path, #deployment_projects_path, #docker_root_path, #downloads_path, #env_path, #envrc_file, #packages_root_path, #project_path, #releases_root_path, #shared_path, #tmp_path, #unset_envrc_file
#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version
#dockerize, #dockerized?, #env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#validate_for_docker_cert_path
#monitor_defined?, #process_monitor_via
#current_uid, #current_user, included
#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home, #with_clean_env
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Attribute Details
#build ⇒ Object
Returns the value of attribute build.
5
6
7
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 5
def build
@build
end
|
Instance Method Details
#build_application ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 87
def build_application
if built?
update_result "Skipped! ALREADY built #{build[:image_tag]}.", status: :skipped
return
end
output = compose_application!
if built?
update_result "Successfully built #{build[:image_tag]}."
else
update_result "FAILED to build #{build[:image_tag]}: #{output}.",
status: :failed, level: :error
end
end
|
#built? ⇒ Boolean
83
84
85
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 83
def built?
!(build[:image_id] = get_image_id).empty?
end
|
#default_docker_tcp_port ⇒ Object
17
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 17
def default_docker_tcp_port; docker_tls_verify? ? "2376" : "2375"; end
|
#default_docker_templates_path ⇒ Object
13
14
15
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 13
def default_docker_templates_path
task.opts.default_docker_templates_path
end
|
#distribute_application ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 106
def distribute_application
if distributed?
update_result "Skipped! ALREADY distributed #{build[:image_tag]}.", status: :skipped
return
end
output = distribute_application!
if distributed?
update_result "Successfully distributed #{build[:image_tag]}."
else
update_result "FAILED to distribute #{build[:image_tag]}: #{output}",
status: :failed, level: :error
end
end
|
#distributed? ⇒ Boolean
102
103
104
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 102
def distributed?
build[:image_id] == get_image_id(docker_options)
end
|
#docker_ca_cert_path ⇒ Object
23
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 23
def docker_ca_cert_path; docker_cert_path.join("ca.pem"); end
|
#docker_client_cert_path ⇒ Object
24
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 24
def docker_client_cert_path; docker_cert_path.join("cert.pem"); end
|
#docker_host ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 32
def docker_host
unix_socket = host[:docker_unix_socket] || docker_unix_socket
if unix_socket.nil?
tcp_port = host[:docker_tcp_port] || docker_tcp_port || default_docker_tcp_port
"tcp://#{hostname}:#{tcp_port}"
else
"unix://#{unix_socket}"
end
end
|
#docker_options ⇒ Object
42
43
44
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 42
def docker_options
@docker_options ||= ["-H #{docker_host}"].concat(docker_tls_verify? ? tls_options : [])
end
|
#docker_templates_path ⇒ Object
9
10
11
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 9
def docker_templates_path
task.opts.docker_templates_path
end
|
#docker_tls_verify? ⇒ Boolean
19
20
21
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 19
def docker_tls_verify?;
host[:docker_tls_verify].nil? ? docker_tls_verify : host[:docker_tls_verify]
end
|
#dockerize_application ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 65
def dockerize_application
rmdir(build[:path]) if force?
dockerize_application!
case build[:status]
when :succeeded
update_result "Successfully dockerized #{build[:image_tag]}."
when :skipped
update_result "Skipped! ALREADY dockerized #{build[:image_tag]}.", status: :skipped
else
update_result "FAILED to dockerize #{build[:image_tag]}.", status: :failed, level: :error
end
update_result build: build
end
|
#get_image_id(docker_options = []) ⇒ Object
79
80
81
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 79
def get_image_id(docker_options = [])
capture(:docker, docker_options.join(' '), :images, "-q", build[:image_tag])
end
|
#init_docker ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 50
def init_docker
puts " Initializing #{application_name} docker profile"
docker_templates.each do |path|
print " - #{path}"
src_path = default_docker_templates_path.join(path)
dst_path = docker_templates_path.join(path)
if file?(dst_path)
puts " [skipped]"
else
upload!(src_path, dst_path)
puts " [created]"
end
end
end
|
#revision_size ⇒ Object
46
47
48
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 46
def revision_size
task.opts.revision_size || DefaultRevisionSize
end
|
#tls_key_path ⇒ Object
25
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 25
def tls_key_path; docker_cert_path.join("key.pem"); end
|
#tls_options ⇒ Object
27
28
29
30
|
# File 'lib/luban/deployment/cli/application/docker/dockerizer.rb', line 27
def tls_options
["--tlsverify", "--tlscacert #{docker_ca_cert_path}",
"--tlscert #{docker_client_cert_path}", "--tlskey #{tls_key_path}"]
end
|