Class: Dash::Cli::Build
- Inherits:
-
Base
- Object
- Thor
- Base
- Dash::Cli::Build
show all
- Defined in:
- lib/dash/cli/build.rb
Defined Under Namespace
Classes: BuildError, Clone, PortForwarding
Constant Summary
Constants inherited
from Base
Dash::Cli::Base::AUTOMATIC_DEPLOY_LOCK_MESSAGE, Dash::Cli::Base::HOOK_MUTEX, Dash::Cli::Base::VERBOSITY
Instance Method Summary
collapse
Methods inherited from Base
dynamic_command_class, exit_on_failure?, #initialize
Instance Method Details
#create ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/dash/cli/build.rb', line 91
def create
if (remote_host = DASH.config.builder.remote)
connect_to_remote_host(remote_host)
end
run_locally do
begin
debug "Using builder: #{DASH.builder.name}"
execute *DASH.builder.create
rescue SSHKit::Command::Failed => e
if e.message =~ /stderr=(.*)/
error "Couldn't create remote builder: #{$1}"
false
else
raise
end
end
end
end
|
#deliver ⇒ Object
5
6
7
8
|
# File 'lib/dash/cli/build.rb', line 5
def deliver
invoke :push
invoke :pull
end
|
#details ⇒ Object
120
121
122
123
124
125
|
# File 'lib/dash/cli/build.rb', line 120
def details
run_locally do
puts "Builder: #{DASH.builder.name}"
puts capture(*DASH.builder.info)
end
end
|
#dev ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/dash/cli/build.rb', line 130
def dev
cli = self
ensure_docker_installed
docker_included_files = Set.new(Dash::Docker.included_files)
git_uncommitted_files = Set.new(Dash::Git.uncommitted_files)
git_untracked_files = Set.new(Dash::Git.untracked_files)
docker_uncommitted_files = docker_included_files & git_uncommitted_files
if docker_uncommitted_files.any?
say "WARNING: Files with uncommitted changes will be present in the dev container:", :yellow
docker_uncommitted_files.sort.each { |f| say " #{f}", :yellow }
say
end
docker_untracked_files = docker_included_files & git_untracked_files
if docker_untracked_files.any?
say "WARNING: Untracked files will be present in the dev container:", :yellow
docker_untracked_files.sort.each { |f| say " #{f}", :yellow }
say
end
parser = build_progress_parser
handler = handler_for(parser)
with_env(DASH.config.builder.secrets) do
run_locally do
build = DASH.builder.push(cli.options[:output], tag_as_dirty: true, no_cache: cli.options[:no_cache])
DASH.with_verbosity(:debug) do
execute(*build, **handler)
end
end
end
ensure
record_build_report parser, build_directory: "."
end
|
#pull ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/dash/cli/build.rb', line 76
def pull
forward_local_registry_port(DASH.hosts, **DASH.config.ssh.options) do
if (first_hosts = login_and_mirror_hosts).any?
say "Pulling image on #{first_hosts.join(", ")} to seed the #{"mirror".pluralize(first_hosts.count)}...", :magenta
pull_on_hosts(first_hosts)
say "Pulling image on remaining hosts...", :magenta
pull_on_hosts(DASH.app_hosts - first_hosts)
else
pull_on_hosts(DASH.app_hosts)
end
end
end
|
#push ⇒ Object
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
67
68
69
70
71
72
73
|
# File 'lib/dash/cli/build.rb', line 13
def push
cli = self
pre_connect_if_required
ensure_docker_installed
setup_local_registry if DASH.registry.local?
login_to_registry_locally unless DASH.registry.local?
run_hook "pre-build"
uncommitted_changes = Dash::Git.uncommitted_changes
if DASH.config.builder.git_clone?
if uncommitted_changes.present?
say "Building from a local git clone, so ignoring these uncommitted changes:\n #{uncommitted_changes}", :yellow
end
run_locally do
Clone.new(self).prepare
end
elsif uncommitted_changes.present?
say "Building with uncommitted changes:\n #{uncommitted_changes}", :yellow
end
parser = build_progress_parser
handler = handler_for(parser)
forward_local_registry_port_for_remote_builder do
with_env(DASH.config.builder.secrets) do
run_locally do
begin
execute *DASH.builder.inspect_builder
rescue SSHKit::Command::Failed => e
if e.message =~ /(context not found|no builder|no compatible builder|does not exist)/
warn "Missing compatible builder, so creating a new one first"
begin
cli.remove
rescue SSHKit::Command::Failed
raise unless e.message =~ /(context not found|no builder|does not exist)/
end
cli.create
else
raise
end
end
push = DASH.builder.push(cli.options[:output], no_cache: cli.options[:no_cache])
DASH.with_verbosity(:debug) do
Dir.chdir(DASH.config.builder.build_directory) { execute *push, env: DASH.builder.push_env, **handler }
end
end
end
end
ensure
record_build_report parser
end
|
#remove ⇒ Object
112
113
114
115
116
117
|
# File 'lib/dash/cli/build.rb', line 112
def remove
run_locally do
debug "Using builder: #{DASH.builder.name}"
execute *DASH.builder.remove
end
end
|