Class: PicsolveDockerBuilder::Scala
- Inherits:
-
Frame
- Object
- Frame
- PicsolveDockerBuilder::Scala
show all
- Defined in:
- lib/picsolve_docker_builder/scala.rb
Overview
Instance Method Summary
collapse
Methods inherited from Frame
#asset_image, #asset_image_build, #asset_image_dockerfile, #build, #build_dir, #build_mode, #build_user, #build_user_home, #build_user_uid, #container, #create_container, #create_logger, #dest_image_name, #docker_build_build, #dockerfile, #dockerfile_exists?, #dockerfile_hooks_asset_build_early, #dockerfile_hooks_asset_build_late, #dockerfile_hooks_docker_build_early, #dockerfile_hooks_docker_build_late, #dockerfile_path, #dockerfile_template, #dockerignore_template, #environment, #execute, #execute_attach, #fetch_asset_image, #image_name, #initialize, #jenkins_build_number, #log, #push, #runtime_image_name, #ssh_auth_forwarding?, #ssh_auth_forwarding_dockerfile, #ssh_auth_forwarding_path, #ssh_known_hosts, #start, #stop, #tag, #tags, #validate_config, #validate_config_docker, #volume_ssh_auth_forwarding, #volume_workspace, #volumes
Methods included from Base
#base_dir, #config, #config_file, #config_path, #config_paths, #create_logger, #log, #read_config, #validate_config
Instance Method Details
#asset_build ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/picsolve_docker_builder/scala.rb', line 160
def asset_build
log.info "start asset building with image #{image_name}"
start
prepare_volumes
build_cmd = [
'gosu', build_user, 'bash', '-c', sbt_command
]
execute_attach build_cmd
log.info "finished asset building with image #{image_name}"
stop
end
|
#bin_path ⇒ Object
90
91
92
|
# File 'lib/picsolve_docker_builder/scala.rb', line 90
def bin_path
@bin_path ||= detect_bin_path
end
|
#default_config ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/picsolve_docker_builder/scala.rb', line 9
def default_config
c = super
c['scala'] = {
'sbt' => {
'build_task' => [
'clean test universal:packageZipTarball'
]
}
}
c
end
|
#detect_bin_path ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/picsolve_docker_builder/scala.rb', line 94
def detect_bin_path
path = universal_bin_path
unless path.nil?
log.debug "run script detected in '#{path}'"
return path
end
path = run_script
unless path.nil?
path = run_script[:destination]
log.debug "run script detected in '#{path}'"
return path
end
fail 'No run script detected'
end
|
#detect_run_script ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/picsolve_docker_builder/scala.rb', line 113
def detect_run_script
path = run_script_path
return nil unless File.exist? path
basename = ::File.basename(path)
{
basename: basename,
source: path,
destination: "/#{basename}"
}
end
|
#dirs_sbt ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/picsolve_docker_builder/scala.rb', line 82
def dirs_sbt
[
'.sbt',
'.ivy2',
'.m2'
]
end
|
#docker_build ⇒ Object
78
79
80
|
# File 'lib/picsolve_docker_builder/scala.rb', line 78
def docker_build
@docker_build = docker_builder.build
end
|
#docker_build_files ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/picsolve_docker_builder/scala.rb', line 38
def docker_build_files
f = []
f << Builder::File.new(
'app.tar.gz',
source: universal_tar_gz,
destination: '/opt'
)
unless run_script.nil?
f << Builder::File.new(
run_script[:destination],
run_script
)
end
f
end
|
#docker_builder ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/picsolve_docker_builder/scala.rb', line 54
def docker_builder
Builder::Builder.new(
base_image: image_name,
maintainer: 'Picsolve Onlineops <[email protected]>',
ports: [9000],
hooks: {
before_adds: [
'# add play users',
'RUN groupadd -r play && \\',
' useradd -r -g play play',
'# create pid dir',
'RUN mkdir -p /var/run/play && \\',
' chown play:play /var/run/play'
],
after_adds: [
'# chown app directories',
'RUN chown -R play:play /opt'
]
},
command: ['gosu', 'play', bin_path],
files: docker_build_files
)
end
|
#prepare_volumes ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/picsolve_docker_builder/scala.rb', line 21
def prepare_volumes
volumes = volumes_sbt.map do |v|
v[1]
end
cmd = [
'chown',
'-c',
build_user,
build_user_home
]
cmd += volumes
execute cmd
end
|
#run_script ⇒ Object
109
110
111
|
# File 'lib/picsolve_docker_builder/scala.rb', line 109
def run_script
@run_script ||= detect_run_script
end
|
#run_script_path ⇒ Object
124
125
126
|
# File 'lib/picsolve_docker_builder/scala.rb', line 124
def run_script_path
File.join(base_dir, 'run.sh')
end
|
#sbt_command ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/picsolve_docker_builder/scala.rb', line 141
def sbt_command
return @sbt_command unless @sbt_command.nil?
runs = config['scala']['sbt']['build_task'].map do |tasks|
"sbt #{tasks}"
end
runs.join ' && '
end
|
#sbt_lib_release ⇒ Object
155
156
157
158
|
# File 'lib/picsolve_docker_builder/scala.rb', line 155
def sbt_lib_release
@sbt_command = "sbt clean test \"release cross with-defaults\""
build
end
|
#sbt_lib_snapshot ⇒ Object
150
151
152
153
|
# File 'lib/picsolve_docker_builder/scala.rb', line 150
def sbt_lib_snapshot
@sbt_command = 'sbt clean update test publish'
build
end
|
#universal_bin_path ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/picsolve_docker_builder/scala.rb', line 178
def universal_bin_path
Zlib::GzipReader.open(universal_tar_gz) do |gunzip|
gunzip_io = StringIO.new(gunzip.read)
Gem::Package::TarReader.new gunzip_io do |tar|
tar.each do |entry|
next unless entry.file?
next unless entry.full_name.match(%r{/bin})
next if entry.full_name.match(/\.bat$/)
return File.join('/opt', entry.full_name)
end
end
end
nil
end
|
#universal_tar_gz ⇒ Object
193
194
195
196
197
198
199
200
201
|
# File 'lib/picsolve_docker_builder/scala.rb', line 193
def universal_tar_gz
build_asset_glob = File.join(base_dir, 'target/**/*.tgz')
tgz_files = Dir.glob(build_asset_glob)
fail "no universal_tar_gz found: #{build_asset_glob}" \
if tgz_files.length < 1
fail "more than one universal_tar_gz found: #{build_asset_glob}" \
if tgz_files.length > 1
tgz_files[0]
end
|
#volumes_array ⇒ Object
137
138
139
|
# File 'lib/picsolve_docker_builder/scala.rb', line 137
def volumes_array
super + volumes_sbt
end
|
#volumes_sbt ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/picsolve_docker_builder/scala.rb', line 128
def volumes_sbt
dirs_sbt.map do |dir|
[
File.join(base_dir, dir),
File.join(build_user_home, dir)
]
end
end
|