summaryrefslogtreecommitdiff
path: root/puppet/modules/site_static/manifests/location.pp
blob: ab2b74945ec9e372a0ca98ef8aa0f6fac68e5739 (plain)
1
2
3
4
5
6
7
8
9
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
# configure static service for location
define site_static::location($path, $format, $source) {

  $file_path = "/srv/static/${name}"
  $allowed_formats = ['amber','rack']

  if $format == undef {
    fail("static_site location `${path}` is missing `format` field.")
  }

  if ! member($allowed_formats, $format) {
    $formats_str = join($allowed_formats, ', ')
    fail("Unsupported static_site location format `${format}`. Supported formats include ${formats_str}.")
  }

  if ($format == 'amber') {
    exec {"amber_build_${name}":
      cwd       => $file_path,
      command   => 'amber rebuild',
      user      => 'www-data',
      timeout   => 600,
      subscribe => Vcsrepo[$file_path]
    }
  }

  if ($format == 'rack') {
    # Run bundler if there is a Gemfile
    exec { 'bundler_update':
      cwd     => $file_path,
      command => '/bin/bash -c "/usr/bin/bundle check --path vendor/bundle || /usr/bin/bundle install --path vendor/bundle --without test development debug"',
      unless  => '/usr/bin/bundle check --path vendor/bundle',
      onlyif  => 'test -f Gemfile',
      user    => 'www-data',
      timeout => 600,
      require => [Class['bundler::install'], Class['site_config::ruby::dev']];
    }
  }

  vcsrepo { $file_path:
    ensure   => present,
    force    => true,
    revision => $source['revision'],
    provider => $source['type'],
    source   => $source['repo'],
    owner    => 'www-data',
    group    => 'www-data'
  }

}