|
75 | 75 |
|
76 | 76 | # Does a version check and self-update if required |
77 | 77 | if options['self_update'] |
78 | | - this_version = '2.4.0' |
| 78 | + this_version = '3.0.0' |
79 | 79 | puts colorize_lightblue("This is a universal dev env (version #{this_version})") |
80 | 80 | # Skip version check if not on master (prevents infinite loops if you're in a branch that isn't up to date with the |
81 | 81 | # latest release code yet) |
|
124 | 124 | File.open(DEV_ENV_CONTEXT_FILE, 'w+') { |file| file.write(config_repo) } |
125 | 125 | end |
126 | 126 |
|
| 127 | + config_repo = File.read(DEV_ENV_CONTEXT_FILE).strip |
127 | 128 | # Check if dev-env-config exists, and if so pull the dev-env configuration. Otherwise clone it. |
128 | | - puts colorize_lightblue('Retrieving custom configuration repo files:') |
129 | 129 | if Dir.exist?(DEV_ENV_CONFIG_DIR) |
130 | 130 | new_project = false |
131 | | - command_successful = run_command("git -C #{root_loc}/dev-env-config pull") |
| 131 | + command_successful = if config_repo == 'local' |
| 132 | + 0 |
| 133 | + else |
| 134 | + run_command("git -C #{root_loc}/dev-env-config pull") |
| 135 | + end |
132 | 136 | else |
133 | 137 | new_project = true |
134 | | - config_repo = File.read(DEV_ENV_CONTEXT_FILE) |
135 | 138 | parsed_repo, delimiter, ref = config_repo.rpartition('#') |
136 | 139 | # If they didn't specify a #ref, rpartition returns "", "", wholestring |
137 | 140 | parsed_repo = ref if delimiter.empty? |
138 | | - command_successful = run_command("git clone #{parsed_repo} #{root_loc}/dev-env-config") |
139 | | - if command_successful.zero? && !delimiter.empty? |
140 | | - puts colorize_lightblue("Checking out configuration repo ref: #{ref}") |
141 | | - command_successful = run_command("git -C #{root_loc}/dev-env-config checkout #{ref}") |
| 141 | + if config_repo == 'local' |
| 142 | + puts colorize_lightblue('Initializing local config repository.') |
| 143 | + run_command("mkdir #{DEV_ENV_CONFIG_DIR}") |
| 144 | + # Create a configuration.yml with an empty services array |
| 145 | + File.open("#{DEV_ENV_CONFIG_DIR}/configuration.yml", 'w') do |file| |
| 146 | + file.write("---\nservices: {}\n") |
| 147 | + end |
| 148 | + puts colorize_green("You can start adding apps to #{DEV_ENV_CONFIG_DIR}/configuration.yml") |
| 149 | + exit 1 |
| 150 | + else |
| 151 | + command_successful = run_command("git clone #{parsed_repo} #{DEV_ENV_CONFIG_DIR}") |
| 152 | + if command_successful.zero? && !delimiter.empty? |
| 153 | + command_successful = run_command("git -C #{DEV_ENV_CONFIG_DIR} checkout #{ref}") |
| 154 | + end |
142 | 155 | end |
143 | 156 | end |
144 | 157 |
|
|
177 | 190 | # TODO bash autocompletion of container names |
178 | 191 | if options['prepare_compose'] |
179 | 192 | # Create a file called .commodities.yml with the list of commodities in it |
180 | | - puts colorize_lightblue('Creating list of commodities') |
181 | 193 | create_commodities_list(root_loc) |
182 | 194 |
|
183 | 195 | # Call the ruby function to create the docker compose file containing the apps and their commodities |
184 | | - puts colorize_lightblue('Creating docker-compose file list') |
185 | 196 | prepare_compose(root_loc, DOCKER_COMPOSE_FILE_LIST) |
186 | 197 | end |
187 | 198 |
|
|
191 | 202 | exit |
192 | 203 | end |
193 | 204 |
|
194 | | - puts colorize_lightblue('Building images...') |
195 | | - if run_command("#{ENV['DC_CMD']} build " + (options['nopull'] ? '' : '--pull')) != 0 |
196 | | - puts colorize_red('Something went wrong when building your app images. Check the output above.') |
| 205 | + puts colorize_lightblue('Building images (might take a while)... (logging to logfiles/imagebuild.log)') |
| 206 | + if run_command("#{ENV['DC_CMD']} build #{options['nopull'] ? '' : '--pull'} > logfiles/imagebuild.log 2>&1") != 0 |
| 207 | + puts colorize_red('Something went wrong when building the images, check the log file. Here are the last 10 lines:') |
| 208 | + lines = File.readlines("#{root_loc}/logfiles/imagebuild.log") |
| 209 | + last_ten = lines.last(10) |
| 210 | + last_ten.each { |line| puts line } |
197 | 211 | exit |
198 | 212 | end |
199 | | - |
200 | 213 | end |
201 | 214 |
|
202 | 215 | if options['provision_commodities'] |
203 | 216 | # Before creating any containers, let's see what already exists (in case we need to override provision status) |
204 | 217 | existing_containers = [] |
205 | | - # v2 --services seems to work differently. it already excludes deleted containers |
206 | 218 | run_command("#{ENV['DC_CMD']} ps --services", existing_containers) |
207 | 219 |
|
208 | 220 | # Let's force a recreation of the containers here so we know they're using up-to-date images |
209 | | - puts colorize_lightblue('Creating containers...') |
210 | | - if run_command("#{ENV['DC_CMD']} up --remove-orphans --force-recreate --no-start") != 0 |
211 | | - puts colorize_red('Something went wrong when creating your app containers. Check the output above.') |
| 221 | + puts colorize_lightblue('Recreating containers... (logging to logfiles/containercreate.log)') |
| 222 | + if run_command("#{ENV['DC_CMD']} up --remove-orphans --force-recreate --no-start > logfiles/containercreate.log 2>&1") != 0 |
| 223 | + puts colorize_red('Something went wrong when creating the containers, check the log file. Here are the last 10 lines:') |
| 224 | + lines = File.readlines("#{root_loc}/logfiles/containercreate.log") |
| 225 | + last_ten = lines.last(10) |
| 226 | + last_ten.each { |line| puts line } |
212 | 227 | exit |
213 | 228 | end |
214 | 229 |
|
|
239 | 254 | # The list of expensive services currently starting |
240 | 255 | expensive_inprogress = [] |
241 | 256 |
|
| 257 | + puts colorize_lightblue('Checking application configurations...') |
242 | 258 | config['applications'].each do |appname, appconfig| |
243 | 259 | # First, special options check (in the dev-env-config) |
244 | 260 | # for any settings that should override what the app wants to do |
|
274 | 290 | end |
275 | 291 | end |
276 | 292 |
|
277 | | - puts colorize_lightblue('Starting log receiver service...') |
278 | | - up = run_command("#{ENV['DC_CMD']} up --no-deps --remove-orphans -d logstash") |
| 293 | + up = run_command("#{ENV['DC_CMD']} up --no-deps --remove-orphans -d logstash", []) |
279 | 294 | sleep(3) |
280 | 295 | if up != 0 |
281 | | - puts colorize_red('Something went wrong when initialising logging. Check the output above.') |
| 296 | + puts colorize_red('Something went wrong when initialising live container logging. Check the output above.') |
282 | 297 | exit |
283 | 298 | end |
284 | 299 |
|
285 | 300 | # Now we can start inexpensive apps, which should be quick and easy |
286 | 301 | if services_to_start.any? |
287 | | - puts colorize_lightblue('Starting inexpensive services...') |
288 | | - up = run_command("#{ENV['DC_CMD']} up --no-deps --remove-orphans -d " + services_to_start.join(' ')) |
| 302 | + puts colorize_lightblue('Starting inexpensive services... (logging to logfiles/containerstart.log)') |
| 303 | + up = run_command("#{ENV['DC_CMD']} up --no-deps --remove-orphans -d #{services_to_start.join(' ')}") |
289 | 304 | if up != 0 |
290 | | - puts colorize_red('Something went wrong when creating your app images or containers. Check the output above.') |
| 305 | + puts colorize_red('Something went wrong when starting the containers, check the log file. Here are the last 10 lines:') |
| 306 | + lines = File.readlines("#{root_loc}/logfiles/containerstart.log") |
| 307 | + last_ten = lines.last(10) |
| 308 | + last_ten.each { |line| puts line } |
291 | 309 | exit |
292 | 310 | end |
293 | 311 | end |
294 | 312 |
|
295 | 313 | # Until we have no more left to start AND we have no more in progress... |
296 | | - puts colorize_lightblue('Starting expensive services...') if expensive_todo.length.positive? |
| 314 | + if expensive_todo.length.positive? |
| 315 | + puts colorize_lightblue('Starting expensive services... (logging to logfiles/containerstart.log)') |
| 316 | + end |
297 | 317 | expensive_failed = [] |
298 | 318 | while expensive_todo.length.positive? || expensive_inprogress.length.positive? |
299 | 319 | # Wait for a bit before the next round of checks |
|
405 | 425 | puts colorize_yellow(" #{service['compose_service']}") |
406 | 426 | end |
407 | 427 | else |
408 | | - puts colorize_green('All done, environment is ready for use') |
| 428 | + puts colorize_green('Environment is ready for use') |
409 | 429 | end |
410 | 430 |
|
411 | 431 | post_up_message = config.fetch('post-up-message', nil) |
|
0 commit comments