charmkit 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2694aa3234aab42395939a61724fc04942537a1d
4
- data.tar.gz: fe4b8c831f4cd517ebcea769bcfba5b91cab76a5
3
+ metadata.gz: 4c61b8a5df2d9fa456312355f5c1a6fbb5eac127
4
+ data.tar.gz: b8922c3548a51783da295fb921a45ba285237a34
5
5
  SHA512:
6
- metadata.gz: d02d16fe85ba47ae73281830c965eaec5e843bb0046fc03d58a616dc26311b5fc10cf0e73d480ccac2631f83d413ba8ac8262964cbd18aa26d2d73d1bd8e8efd
7
- data.tar.gz: 49d61068e00a397c3bf436419ca7880289fa499aa124794ba49eddc1531cabef2a15951e73f320147a4ae692eb13fe91543b69fc6e8363d53ae45204cd2e7585
6
+ metadata.gz: 025622d786353958686dad9735b8841b927f0dd26b6c636d5ce5148a378e0a1100095414c96f28f3174129ae52cdd865024833bf5b46fa4fa65a0e2adf139a16
7
+ data.tar.gz: 64a98f72f23f8274df138242e3060da5e9d40704fc0f0ddb3b574b4292a0d1f9ee239e6f7ef375092287f371e058ac46c9e5903dbeaacba608d8169be6b118b0
@@ -0,0 +1,59 @@
1
+ require 'charmkit'
2
+
3
+ template('examples/my-demo-charm/templates/vhost.conf',
4
+ '/tmp/nginx-data.conf',
5
+ public_address: 'localhost',
6
+ app_path: '/srv/app')
7
+
8
+ inline_template('vhost.conf',
9
+ '/tmp/output.txt',
10
+ public_address: "localhost",
11
+ app_path: "/srv/app")
12
+ __END__
13
+
14
+ @@ nginx.conf
15
+
16
+ server_connections { 50m; }
17
+
18
+ @@ vhost.conf
19
+
20
+ server {
21
+ ## Your website name goes here.
22
+ server_name <%= public_address %>;
23
+ ## Your only path reference.
24
+ root <%= app_path %>;
25
+ location / {
26
+ index doku.php;
27
+ # This is cool because no php is touched for static content.
28
+ # include the "?$args" part so non-default permalinks doesn't break when using query string
29
+ try_files $uri $uri/ @dokuwiki;
30
+ }
31
+
32
+ location ~ ^/lib.*\.(gif|png|ico|jpg)$ {
33
+ expires 30d;
34
+ }
35
+
36
+ location ^~ /conf/ { return 403; }
37
+ location ^~ /data/ { return 403; }
38
+
39
+ location @dokuwiki {
40
+ rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
41
+ rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
42
+ rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
43
+ rewrite ^/(.*) /doku.php?id=$1 last;
44
+ }
45
+
46
+ location ~ \.php$ {
47
+ include fastcgi_params;
48
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
49
+ fastcgi_pass unix:/run/php/php7.0-fpm.sock;
50
+ }
51
+ # Block access to data folders
52
+ location ~ /(data|conf|bin|inc)/ {
53
+ deny all;
54
+ }
55
+ # Block access to .htaccess files
56
+ location ~ /\.ht {
57
+ deny all;
58
+ }
59
+ }
@@ -2,9 +2,7 @@ require 'erb'
2
2
 
3
3
  module Charmkit
4
4
  module Helpers
5
- # Processes templates
6
- #
7
- # template 'my-template.erb' '/etc/config/me.conf', service_name: "nginx"
5
+ # Helper for rendering file and inline templates
8
6
  class TemplateRenderer
9
7
  def self.empty_binding
10
8
  binding
@@ -17,9 +15,66 @@ module Charmkit
17
15
  end
18
16
  end
19
17
 
18
+ # Reads from a erb file and renders the content with context
19
+ #
20
+ # @param src String - file path of template
21
+ # @param dst String - file path location to save
22
+ # @param context Hash - parametized variables to pass to template
23
+ # @return Boolean
24
+ #
25
+ # @example
26
+ # template('examples/my-demo-charm/templates/vhost.conf',
27
+ # '/tmp/nginx-data.conf',
28
+ # public_address: 'localhost',
29
+ # app_path: '/srv/app')
20
30
  def template(src, dst, **context)
21
31
  rendered = TemplateRenderer.render(File.read(src), context)
22
32
  File.write(dst, rendered)
23
33
  end
34
+
35
+ # Reads from a embedded template in the rake task itself.
36
+ #
37
+ # @param src String - The data found after __END__
38
+ # @param dst String - Save location
39
+ # @param context Hash - variables to pass into template
40
+ # @return Boolean
41
+ #
42
+ # @example
43
+ # inline_template('vhost.conf',
44
+ # '/etc/nginx/sites-enabled/default')
45
+ # server_name: "example.com")
46
+ #
47
+ # __END__
48
+ # @@ vhost.conf
49
+ # server { name <%= server_name %> }
50
+ def inline_template(name, dst, **context)
51
+ templates = {}
52
+ begin
53
+ app, data = File.read(caller.first.split(":").first).split("__END__", 2)
54
+ rescue Errno::ENOENT
55
+ app, data = nil
56
+ end
57
+
58
+ data.strip!
59
+ if data
60
+ template = nil
61
+ data.each_line do |line|
62
+ if line =~ /^@@\s*(.*\S)\s*$/
63
+ template = String.new
64
+ templates[$1.to_s] = template
65
+ elsif
66
+ template << line
67
+ end
68
+ end
69
+
70
+ begin
71
+ rendered = TemplateRenderer.render(templates[name], context)
72
+ rescue
73
+ puts "Unable to load inline template #{name}"
74
+ exit 1
75
+ end
76
+ File.write(dst, rendered)
77
+ end
78
+ end
24
79
  end
25
80
  end
@@ -1,8 +1,8 @@
1
1
  namespace :nginx do
2
2
  desc "Install NGINX"
3
3
  task :install do
4
- `apt-get update`
5
- `juju-log "Installing NGINX and its dependencies."`
6
- `apt-get install -qyf nginx-full`
4
+ cmd.run "apt-get", "update"
5
+ cmd.run "juju-log", "Installing NGINX and its dependencies."
6
+ cmd.run "apt-get", "install", "-qyf", "nginx-full"
7
7
  end
8
8
  end
@@ -12,8 +12,8 @@ namespace :php do
12
12
  'php-mbstring',
13
13
  'php-xml'
14
14
  ]
15
- `apt-get update`
16
- `juju-log "Installing PHP7 and its dependencies."`
17
- `apt-get install -qyf #{pkgs.join(' ')}`
15
+ cmd.run "apt-get", "update"
16
+ cmd.run "juju-log", "Installing PHP7 and its dependencies."
17
+ cmd.run "apt-get", "install", "-qyf", pkgs.join(' ')
18
18
  end
19
19
  end
@@ -6,7 +6,7 @@ module Charmkit
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 4
9
- PATCH = 4
9
+ PATCH = 5
10
10
  PRE = nil
11
11
 
12
12
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charmkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stokes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-command
@@ -130,6 +130,7 @@ files:
130
130
  - examples/my-demo-charm/templates/plugins.local.php
131
131
  - examples/my-demo-charm/templates/users.auth.php
132
132
  - examples/my-demo-charm/templates/vhost.conf
133
+ - examples/render_inline.rb
133
134
  - lib/charmkit.rb
134
135
  - lib/charmkit/extend/string_tools.rb
135
136
  - lib/charmkit/helpers/runner.rb