summaryrefslogtreecommitdiff
path: root/manifests/instance.pp
blob: 8f9f1d1efa9cb209eb921aeb51939250991d0ee5 (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
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
define blog::instance (
  String $author,
  String $blog_title = $name,
  Boolean $has_comments = false,
  String $engine_version = '8.0',
  String $subtitle = '',
  Optional[Struct[{ url => String, ref => String}]] $vcs_repo = undef,
) {

  $root = "${blog::blog_root}/${title}"
  $safe_title = base64('encode', $blog_title)

  # Download source
  vcsrepo { $root:
    ensure   => latest,
    provider => git,
    source   => 'https://github.com/HugoNikanor/website-blog-2.git',
    revision => $engine_version,
    group    => 'www-data',
    # keep_local_changes => true,
  }

  # Manage entries directory
  if $vcs_repo {
    vcsrepo { "${root}/entries":
      ensure   => latest,
      provider => git,
      source   => $vcs_repo['url'],
      revision => $vcs_repo['ref'],
      group    => 'www-data',
    }
  } else {
    file { "${root}/entries":
      ensure => directory,
    }
  }

  file { "${root}/settings.php":
    ensure  => file,
    content => epp('blog/settings.php.epp', {
      author       => $author,
      title        => $blog_title,
      subtitle     => $subtitle,
      has_comments => $has_comments,
      }),
  }

  file { "${root}/footnote":
    ensure => directory,
    recurse => true,
  }

  $foot_files = [
    ['about.md',   'About'],
    ['contact.md', 'Contact'],
    ['legal.md',   'Legal'],
    ['qna.md',     '"Q&A"'],
  ]

  $foot_files.each |$item| {
    file { "${root}/footnote/${item[0]}":
      source => "puppet:///modules/blog/footers/${item[0]}",
    }
  }

  file { "${root}/special-files.ini":
    ensure       => file,
    content      => epp(
      'blog/special-files.ini.epp',
      { foot_files => $foot_files, }),
  }

  nginx::resource::location { "${safe_title} - /":
    location          => '/',
    try_files         => ['$uri', '$uri/', '=404'],
    index_files       => [],
    ssl               => true,
    ssl_only          => true,
    autoindex         => on,
    server            => $blog::blog_server_name,
    add_header        => {
      'Cache-Control' => "no-cache",
    },
  }

  nginx::resource::location { "${safe_title} - css":
    location  => '~ \.css$',
    try_files => [ '$uri', '=404' ],
    ssl       => true,
    ssl_only  => true,
    expires   => '1h',
    add_header        => {
      'Cache-Control' => "no-cache",
    },
  }

  nginx::resource::location { "${safe_title} - php":
    location       => '~ \.php$',
    fastcgi_params => 'snippets/fastcgi-php.conf',
    fastcgi        => 'unix:/run/php/php-fpm.sock',
    ssl            => true,
    ssl_only       => true,
    server         => $blog::blog_server_name,
  }

  nginx::resource::location { "${safe_title} - ht":
    location            => '~ /\.ht',
    location_cfg_append => { deny => 'all' },
    index_files         => [],
    ssl                 => true,
    server              => $blog::blog_server_name,
  }
}