Defined Type: dockerapp::run

Defined in:
manifests/run.pp

Overview

Type: dockerapp::run

Runs an instance of the docker app with the defined parameters

Parameters

service_name

Used to determine the name of the app and the service installed. Usually it uses the title of the resource.

image

The docker image to be used.

ports

The ports to be exposed

hostname

Hostname of to be passed to the container. Defaults to the fqdn of the local machine

extra_parameters

Extra parameters to be passed to the container

environments

Environments variables

restart_service

If the service must be restarted in the case of a failure

volumes

Volumes to be mounted

dir_owner

The uid of the dir owner of the app dir

dir_group

The uid of the dir group of the app dir

command

Command to be executed on the docker-run

links

Docker links

links

Custom network to use

Parameters:

  • service_name (Any) (defaults to: $title)
  • image (Any) (defaults to: undef)
  • ports (Any) (defaults to: undef)
  • hostname (Any) (defaults to: $::fqdn)
  • extra_parameters (Any) (defaults to: [])
  • environments (Any) (defaults to: [])
  • restart_service (Any) (defaults to: true)
  • volumes (Any) (defaults to: [])
  • dir_owner (Any) (defaults to: 1)
  • dir_group (Any) (defaults to: 1)
  • command (Any) (defaults to: undef)
  • links (Any) (defaults to: undef)
  • net (Any) (defaults to: undef)
  • require (Any) (defaults to: undef)


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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'manifests/run.pp', line 46

define dockerapp::run (
  $service_name = $title,
  $image = undef,
  $ports = undef,
  $hostname = $::fqdn,
  $extra_parameters = [],
  $environments = [],
  $restart_service = true,
  $volumes = [],
  $dir_owner = 1,
  $dir_group = 1,
  $command = undef,
  $links = undef,
  $net = undef,
  $require = undef,
)
{
  if !defined(Class['::dockerapp']){
    class{'::dockerapp':}
  }

  $data_dir = $::dockerapp::params::data_dir
  $config_dir = $::dockerapp::params::config_dir
  $scripts_dir = $::dockerapp::params::scripts_dir
  $lib_dir = $::dockerapp::params::lib_dir
  $log_dir = $::dockerapp::params::log_dir

  $conf_datadir = "${data_dir}/${service_name}"
  $conf_configdir = "${config_dir}/${service_name}"
  $conf_scriptsdir = "${scripts_dir}/${service_name}"
  $conf_libdir = "${lib_dir}/${service_name}"
  $conf_logdir = "${log_dir}/${service_name}"

  if !defined(File[$conf_datadir]){
    file{ $conf_datadir:
      ensure  => directory,
      require => File[$data_dir],
      owner   => $dir_owner,
      group   => $dir_group,
    }
  }

  if !defined(File[$conf_configdir]){
    file{ $conf_configdir:
      ensure  => directory,
      require => File[$config_dir],
      owner   => $dir_owner,
      group   => $dir_group,
    }
  }

  if !defined(File[$conf_scriptsdir]){
    file{ $conf_scriptsdir:
      ensure  => directory,
      require => File[$scripts_dir],
      owner   => $dir_owner,
      group   => $dir_group,
    }
  }
  if !defined(File[$conf_logdir]){
    file{ $conf_logdir:
      ensure  => directory,
      require => File[$lib_dir],
      owner   => $dir_owner,
      group   => $dir_group,
    }
  }
  if !defined(File[$conf_libdir]){
    file{ $conf_libdir:
      ensure  => directory,
      require => File[$log_dir],
      owner   => $dir_owner,
      group   => $dir_group,
    }
  }

  if($links != undef){
    if( $net != undef ){
      if( !defined( Docker_Network[$net] )) {
        docker_network { $net:
          ensure => present,
        }
      }
    }

    ::docker::run { $service_name:
      image            => $image,
      ports            => $ports,
      hostname         => $hostname,
      extra_parameters => $extra_parameters,
      restart_service  => $restart_service,
      volumes          => $volumes,
      env              => $environments,
      command          => $command,
      net              => [$net],
      links            => $links,
      require          => $require,
    }
  }else {

    ::docker::run { $service_name:
      image            => $image,
      ports            => $ports,
      hostname         => $hostname,
      extra_parameters => $extra_parameters,
      restart_service  => $restart_service,
      volumes          => $volumes,
      env              => $environments,
      command          => $command,
      net              => [$net],
      require          => $require,
    }
  }


}