Defined Type: docker::dockerize

Defined in:
manifests/dockerize.pp

Overview

This define dockerizes an application. It can:

- Create a dockerfile based on tinydata (default: false)
- Build the relevant image (default:false)
- Push the image to Docker Hub (default:false)
- Run the image from the Docker Hub (default:true)

Parameters:

  • ensure (String[1]) (defaults to: 'present')
  • template (Variant[Undef,String]) (defaults to: 'tp/dockerize/Dockerfile.erb')
  • init_template (Variant[Undef,String]) (defaults to: 'tp/dockerize/init.erb')
  • workdir (String[1]) (defaults to: '/var/tmp')
  • username (String[1]) (defaults to: 'example42')
  • os (String[1]) (defaults to: downcase($::operatingsystem))
  • osversion (String[1]) (defaults to: $::operatingsystemmajrelease)
  • maintainer (Variant[Undef,String]) (defaults to: undef)
  • from (Variant[Undef,String]) (defaults to: undef)
  • repository (Variant[Undef,String]) (defaults to: undef)
  • repository_tag (Variant[Undef,String]) (defaults to: undef)
  • run (Boolean) (defaults to: true)
  • build (Boolean) (defaults to: false)
  • push (Boolean) (defaults to: false)
  • exec_environment (Variant[Undef,Array]) (defaults to: undef)
  • build_options (String) (defaults to: '')
  • command_mode (Pattern[/command|supervisor/]) (defaults to: 'supervisor')
  • run_mode (Pattern[/service|command/]) (defaults to: 'command')
  • mount_data_dir (Boolean) (defaults to: true)
  • mount_log_dir (Boolean) (defaults to: true)
  • settings_hash (Hash) (defaults to: {})
  • data_module (String[1]) (defaults to: 'tinydata')


10
11
12
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
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
# File 'manifests/dockerize.pp', line 10

define docker::dockerize (

  String[1]               $ensure              = 'present',

  Variant[Undef,String]   $template            = 'tp/dockerize/Dockerfile.erb',
  Variant[Undef,String]   $init_template       = 'tp/dockerize/init.erb',
  String[1]               $workdir             = '/var/tmp',

  String[1]               $username            = 'example42',

  String[1]               $os                  = downcase($::operatingsystem),
  String[1]               $osversion           = $::operatingsystemmajrelease,

  Variant[Undef,String]   $maintainer          = undef,
  Variant[Undef,String]   $from                = undef,

  Variant[Undef,String]   $repository          = undef,
  Variant[Undef,String]   $repository_tag      = undef,

  Boolean                 $run                 = true,
  Boolean                 $build               = false,
  Boolean                 $push                = false,

  Variant[Undef,Array]    $exec_environment    = undef,

  String                  $build_options       = '',
  Pattern[/command|supervisor/] $command_mode  = 'supervisor',
  Pattern[/service|command/]    $run_mode      = 'command',

  Boolean                 $mount_data_dir      = true,
  Boolean                 $mount_log_dir       = true,

  Hash                    $settings_hash       = {},

  String[1]               $data_module         = 'tinydata',

  ) {

  # Settings evaluation
  $app = $title
  $tp_settings = tp_lookup($app,'settings',$data_module,'merge')
  $settings_supervisor = tp_lookup('supervisor','settings',$data_module,'merge')
  $settings = $tp_settings + $settings_hash

  $real_repository = $repository ? {
    undef   => $app,
    default => $repository,
  }
  $real_repository_tag = $repository_tag ? {
    undef   => "${os}-${osversion}",
    default => $repository_tag,
  }
  $real_from = $from ? {
    undef   => "${os}:${osversion}",
    default => $from,
  }

  Exec {
    path    => '/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin',
    timeout => 3000,
  }

  # Dockerfile creation
  if $build {
    docker::tp_build { $app:
      ensure           => $ensure,
      build_options    => $build_options,
      username         => $username,
      repository       => $real_repository,
      repository_tag   => $real_repository_tag,
      exec_environment => $exec_environment,
      workdir          => $workdir,
    }
  }

  # Image upload to Docker Hub
  if $push {
    docker::push { $app:
      ensure           => $ensure,
      username         => $username,
      repository       => $real_repository,
      repository_tag   => $real_repository_tag,
      exec_environment => $exec_environment,
    }
  }

  # Image run
  if $run {
    docker::run { $app:
      ensure           => $ensure,
      username         => $username,
      repository       => $real_repository,
      repository_tag   => $real_repository_tag,
      exec_environment => $exec_environment,
      run_mode         => $run_mode,
    }
  }

}