Puppet Plan: complyadm::install::upload_images

Defined in:
plans/install/upload_images.pp

Overview

Ensures that this version of Comply’s application images are on all infra targets. Archived versions of the images are curled down from a public GCS bucket and then uploaded to the infra targets. The images are then loaded into the local docker or podman image cache.

Will locally cache the images to boltproject/downloads/ to speed up plan re-runs

Parameters:

  • config (Complyadm::Config)

    Complyadm::Config config object from hiera

Returns:

  • This plan does not return anything



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
# File 'plans/install/upload_images.pp', line 13

plan complyadm::install::upload_images(
  Complyadm::Config $config,
) {
  $runtime = $config['runtime']
  $images_cache_dir = file::join(complyadm::download_dir(), 'images')
  without_default_logging() || {
    run_command("mkdir -p ${images_cache_dir}", 'localhost')
  }

  $config['roles'].each |$role, $role_info| {
    $targets_by_role = $role_info['targets']
    $role_info['services'].each |$name, $service| {
      $image_name = $service['container']['image']

      $filename = "${regsubst($image_name, '[\/:]', '_', 'G')}.tar.gz"
      $local_cached_image_tar_path = file::join($images_cache_dir, $filename)

      $remote_image_inspect_results = complyadm::images::inspect($image_name, $targets_by_role, undef, $runtime)

      $remote_image_inspect_results.each |$target_run_result| {
        if !$target_run_result.ok {
          if !file::exists($local_cached_image_tar_path) {
            without_default_logging() || {
              $download_url = "https://storage.googleapis.com/comply-images/${filename}"
              complyadm::download_image($download_url, $local_cached_image_tar_path)
            }
          } else {
            out::message("Archive '${filename}' for role '${role}' exists in local cache, not updating.")
          }

          without_default_logging() || {
            out::message("Archive '${filename}' for '${role}' role does not exist on '${target_run_result.target.name}', uploading.")
            upload_file($local_cached_image_tar_path, '/tmp', $targets_by_role, '_run_as' => 'root')
            run_command("${runtime} load -i /tmp/${$filename}", $targets_by_role, '_run_as' => 'root')
          }
        }
      }
    }
  }
}