|
1 | 1 | """ |
2 | | -Things dealing with the 'update' action |
| 2 | +Deals with updating images used by components |
3 | 3 | """ |
4 | 4 | import logging |
5 | 5 | import sys |
6 | 6 |
|
7 | | -import devlab_bench |
8 | | -from devlab_bench.helpers.command import Command |
| 7 | +import devlab_bench.helpers.docker |
| 8 | +import devlab_bench.actions.build |
| 9 | +from devlab_bench.helpers.docker import get_needed_images |
9 | 10 |
|
10 | | -def action(uninstall=False, set_version=None, **kwargs): |
| 11 | +def action(components='*', skip_base_images=False, **kwargs): |
11 | 12 | """ |
12 | | - Attempt to update devlab. This will cause call sys.exit |
| 13 | + This is for updating images used by components |
13 | 14 |
|
14 | | - exit code is 0 upon success and 1 if not |
| 15 | + Args: |
| 16 | + components: list of components or image names to update, this can also be |
| 17 | + the string '*' |
| 18 | + include_base_images: Bool whether to inlcude the devlab base images when updating |
| 19 | + Returns: |
| 20 | + None |
15 | 21 | """ |
16 | | - if update_devlab(uninstall=uninstall, set_version=set_version, **kwargs): |
17 | | - sys.exit(0) |
18 | | - else: |
19 | | - sys.exit(1) |
| 22 | + ignored_args = kwargs |
| 23 | + log = logging.getLogger("UpdateImages") |
| 24 | + if components == '*': |
| 25 | + components = None |
| 26 | + update_component_images(components, skip_base_images=skip_base_images, logger=log) |
20 | 27 |
|
21 | | -def update_devlab(uninstall=False, set_version=None, **kwargs): |
| 28 | +def update_component_images(components=None, skip_base_images=True, logger=None): |
22 | 29 | """ |
23 | | - Use the installer to try and update devlab to the latest version in the repo |
| 30 | + Look through given components and try to build or pull new versions of the |
| 31 | + image layers etc... |
24 | 32 |
|
25 | 33 | Args: |
26 | | - uninstall: bool, indicating to uninstall instead of update |
27 | | - set_version: str, indicating a specific version of devlab to install |
| 34 | + components: list, of components to use for finding images to update |
| 35 | + include_base_images: Bool whether to include base images when updating |
| 36 | + logger: Logger object to use for log messages |
28 | 37 |
|
29 | 38 | Returns: |
30 | | - Bool, True if successful False if not |
| 39 | + None |
31 | 40 | """ |
32 | | - ignored_args = kwargs |
33 | | - log = logging.getLogger("UpdateDevlab") |
34 | | - log.debug("Running installer.py to check for updates etc...") |
35 | | - command = '{}/installer.py'.format(devlab_bench.DEVLAB_ROOT) |
36 | | - args = [] |
37 | | - if uninstall and set_version: |
38 | | - log.error("Cannot uninstall a specific version. Uninstall takes no argument") |
39 | | - return False |
40 | | - if uninstall: |
41 | | - args.append('uninstall') |
42 | | - if set_version: |
43 | | - args += ['install', '--set-version', set_version] |
44 | | - inst_out = Command(command, args, interactive=True).run() |
45 | | - if inst_out[0] != 0: |
46 | | - log.error("Installer did not exit successfully... Aborting!") |
47 | | - return False |
48 | | - return True |
| 41 | + if logger: |
| 42 | + log = logger |
| 43 | + else: |
| 44 | + log = logging.getLogger('update_images') |
| 45 | + log.debug('Looking up images being referenced in components') |
| 46 | + needed_images = get_needed_images(components, logger=log) |
| 47 | + ext_images = needed_images['external_images']['exists'] + needed_images['external_images']['missing'] |
| 48 | + int_images = [] |
| 49 | + base_images = needed_images['base_images']['exists'] + needed_images['base_images']['missing'] |
| 50 | + if not skip_base_images: |
| 51 | + int_images += base_images |
| 52 | + int_images += needed_images['runtime_images']['exists'] + needed_images['runtime_images']['missing'] |
| 53 | + log_output = True |
| 54 | + log.info("Building/Updating devlab and project's managed images: '%s'", ','.join(int_images)) |
| 55 | + devlab_bench.actions.build.action(int_images, skip_pull_images=base_images, clean=True, pull=True) |
| 56 | + for ext_image in ext_images: |
| 57 | + log.info("Pulling down any updates to image: '%s'", ext_image) |
| 58 | + pi_res = devlab_bench.helpers.docker.DOCKER.pull_image(ext_image, log_output=log_output, logger=log) |
| 59 | + if pi_res[0] != 0: |
| 60 | + log.error("Failed pulling updates for image: %s", ext_image) |
| 61 | + sys.exit(1) |
0 commit comments