Defined Type: skopeo::sync

Defined in:
manifests/sync.pp

Summary

Manage configuration for scopeo sync

Overview

Sync copies Docker/OCI images from source to destination registry

Examples:

skopeo::sync { 'registry':
  src  => 'index.docker.io',
  dest => 'my.registry',
}

Parameters:

  • src (String)

    Source registry

  • src_type (Skopeo::SrcType) (defaults to: 'yaml')

    Source transport: ‘docker`,`dir` or `yaml`. Default is `yaml`

  • dest (String)

    Destination registry

  • dest_prefix (Optional[String]) (defaults to: undef)

    Set prefix for destination registry

  • dest_type (Skopeo::DestType) (defaults to: 'docker')

    Destination transport, either ‘docker` or `dir`. Default: `docker`

  • args (Skopeo::Args) (defaults to: $skopeo::args)

    Optional key-value arguments passed to the sync command

  • matrix (Optional[Skopeo::Matrix]) (defaults to: undef)

    A hash with ‘images` and `versions` array that will be cross joined

  • by_tag (Skopeo::ByTag) (defaults to: {})

    Hash containing image name and version (regexp)

  • tls_verify (Boolean) (defaults to: true)

    HTTPS TLS verification

  • redirect_logs (Boolean) (defaults to: true)

    Whether logs should be redirected to a file stored in the ‘log_dir`

  • on_change (Boolean) (defaults to: true)

    Whether synchronization should be performed upon config change

  • user (String) (defaults to: $skopeo::user)
  • group (String) (defaults to: $skopeo::group)
  • base_dir (Stdlib::Unixpath) (defaults to: $skopeo::base_dir)
  • log_dir (Stdlib::Unixpath) (defaults to: $skopeo::log_dir)


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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'manifests/sync.pp', line 36

define skopeo::sync (
  String                   $src,
  String                   $dest,
  Skopeo::SrcType          $src_type = 'yaml',
  Skopeo::DestType         $dest_type = 'docker',
  Skopeo::Args             $args = $skopeo::args,
  Optional[Skopeo::Matrix] $matrix = undef,
  Skopeo::ByTag            $by_tag = {},
  Boolean                  $tls_verify = true,
  Boolean                  $redirect_logs = true,
  Boolean                  $on_change = true,
  String                   $user = $skopeo::user,
  String                   $group = $skopeo::group,
  Stdlib::Unixpath         $base_dir = $skopeo::base_dir,
  Stdlib::Unixpath         $log_dir = $skopeo::log_dir,
  Optional[String]         $dest_prefix = undef,
) {
  $imgs = !empty($matrix) ? {
    # cross product (versions x images)
    true => $matrix['images'].reduce({}) |$res, $img| {
      merge($res, { $img => $matrix['versions'].map |$val| { $val } })
    },
    false => {},
  }

  # soon to be YAML
  $registry = {
    'tls-verify' => $tls_verify,
    'images' => $imgs,
    'images-by-tag-regex' => $by_tag,
  }

  $non_empty = $registry.filter |$keys, $values| { type($values) =~ Type[Boolean] or !empty($values) }

  # final filtered hash
  $config = {
    $src => $non_empty,
  }

  file { "${base_dir}/${title}.yaml":
    ensure  => file,
    owner   => $user,
    group   => $group,
    mode    => '0640',
    content => inline_epp('<%= stdlib::to_yaml($config) %>', {
        config => $config,
    }),
  }

  $_dest = $dest_prefix ? {
    undef   => $dest,
    default => "${dest}/${dest_prefix}",
  }

  $_redirect = $redirect_logs ? {
    true => " >> ${log_dir}/skopeo.log 2>&1",
    false => '',
  }

  # optional args
  $_args = join($args.map |$key, $value| {
      if $key.length > 1 {
        if empty($value) {
          " --${key}"
        } else {
          " --${key} ${value}"
        }
      } else {
        " -${key} ${value}" # short args, e.g. -f oci
      }
  },'')

  if $on_change {
    exec { "skopeo_sync-${title}":
      command     => "skopeo sync${_args} --src ${src_type} --dest ${dest_type} ${base_dir}/${title}.yaml ${_dest}${_redirect}",
      environment => "XDG_RUNTIME_DIR=/run/user/${skopeo::uid}",
      path        => $facts['path'],
      user        => $user,
      cwd         => $base_dir,
      provider    => 'shell',
      refreshonly => true,
      require     => [File[$log_dir]],
      subscribe   => File["${base_dir}/${title}.yaml"],
    }
  }

  # cron { 'sync-k8s':
  #   ensure  => present,
  #   command => "skopeo sync --src yaml --dest docker k8s.yml ${dest}/k8s.io",
  #   user    => $user,
  #   hour    => '*/4', # in 4 hours intervals
  #   minute  => '5',
  #   require => Package['skopeo'],
  # }
}