charmkit 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +63 -42
- data/Rakefile +3 -0
- data/charmkit.gemspec +1 -2
- data/examples/{CKfile → Charmkitfile} +0 -71
- data/examples/demo/lib/install.rb +30 -0
- data/examples/demo/readme +1 -0
- data/examples/plugin_loader.rb +1 -9
- data/examples/template.rb +1 -3
- data/lib/charmkit/helpers/template.rb +25 -0
- data/lib/charmkit/plugins/nginx.rb +23 -0
- data/lib/charmkit/version.rb +2 -2
- data/lib/charmkit.rb +3 -66
- metadata +22 -22
- data/exe/charmkit +0 -21
- data/lib/charmkit/plugins/core.rb +0 -84
- data/lib/charmkit/plugins/hookenv.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24756041722bd6f0869ceaa2bf01c29b7d580af1
|
4
|
+
data.tar.gz: 07dc358b6837a4686090776d750c95595a8e15ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c4dc17926306904a09e18d34efb3ed1ee913544e6b6b0a77e00519e227e31d2b93c30197ddbd0f3e8313e1055443ec9cd15cc300a22de8e0509a51dcfe20b3a
|
7
|
+
data.tar.gz: 1b376bb8a1fae54c63847b054a819ddbf2e3754b98998d61493ffa6b8b2b3923059a88d90a219839c883bd170eefa11a789981d6adb78822dcbe4f531f418d5c
|
data/README.md
CHANGED
@@ -19,19 +19,22 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
Define all install, configure, upgrade tasks within a normal **Rakefile**. The
|
23
|
+
hooks will then need to just call those tasks:
|
24
|
+
|
22
25
|
In **hooks/install**:
|
23
26
|
|
24
27
|
```
|
25
28
|
#!/bin/sh
|
26
29
|
|
27
30
|
apt-get update
|
28
|
-
apt-get install -qyf ruby
|
31
|
+
apt-get install -qyf ruby --no-install-recommends
|
29
32
|
gem install bundler
|
30
33
|
|
31
34
|
bundle install --local --quiet
|
32
35
|
|
33
36
|
# Runs the lib/install.rb hook
|
34
|
-
bundle exec
|
37
|
+
bundle exec rake dokuwiki:install
|
35
38
|
```
|
36
39
|
|
37
40
|
In other hooks call *charmkit* with the execing hook (eg. **hooks/config-changed**)
|
@@ -39,7 +42,7 @@ In other hooks call *charmkit* with the execing hook (eg. **hooks/config-changed
|
|
39
42
|
```
|
40
43
|
#!/bin/sh
|
41
44
|
|
42
|
-
bundle exec
|
45
|
+
bundle exec rake dokuwiki:config_changed
|
43
46
|
```
|
44
47
|
|
45
48
|
Same for **hooks/upgrade-charm**
|
@@ -47,67 +50,85 @@ Same for **hooks/upgrade-charm**
|
|
47
50
|
```
|
48
51
|
#!/bin/sh
|
49
52
|
|
50
|
-
bundle exec
|
53
|
+
bundle exec rake dokuwiki:install
|
54
|
+
bundle exec rake dokuwiki:config_changed
|
55
|
+
|
51
56
|
```
|
52
57
|
|
53
58
|
## Writing Charmkit style hooks
|
54
59
|
|
55
|
-
All Charmkit hooks
|
56
|
-
files must match the name of the hook you want to assicate to and must end with
|
57
|
-
a **.rb** extension.
|
58
|
-
|
59
|
-
For example, if my hook runs `bundle exec charmkit config-changed` then in my
|
60
|
-
**lib/** directory should exist a file named **lib/config-changed.rb**.
|
61
|
-
|
62
|
-
To start, you'll want to inherit from the **Charmkit** class. The class name should also
|
63
|
-
reflect the name of the hook being executed and should be in a standard Ruby camelcase style.
|
64
|
-
|
65
|
-
See the syntax below for a the **config-changed** hook being run:
|
60
|
+
All Charmkit hooks will reside in a normal **Rakefile**.
|
66
61
|
|
67
62
|
### Syntax
|
68
63
|
|
69
64
|
```ruby
|
70
65
|
require 'charmkit'
|
71
66
|
|
72
|
-
|
73
|
-
plugin :core
|
74
|
-
plugin :hookenv
|
67
|
+
namespace :dokuwiki do
|
75
68
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
desc "Install required apt packages"
|
70
|
+
task :install_deps do
|
71
|
+
pkgs = [
|
72
|
+
'nginx-full', 'php-fpm', 'php-cgi', 'php-curl', 'php-gd', 'php-json',
|
73
|
+
'php-mcrypt', 'php-readline', 'php-mbstring', 'php-xml'
|
74
|
+
]
|
75
|
+
`apt-get update`
|
76
|
+
`apt-get install -qyf #{pkgs.join(' ')}`
|
77
|
+
end
|
81
78
|
|
79
|
+
desc "Install Dokuwiki"
|
80
|
+
task :install => [:install_deps] do
|
81
|
+
app_path = `config-get app_path`
|
82
|
+
resource_path = `resource-get stable-release`
|
82
83
|
hook_path = ENV['JUJU_CHARM_DIR']
|
83
|
-
app_path = config 'app_path'
|
84
84
|
|
85
|
-
|
85
|
+
mkdir_p app_path unless Dir.exists? app_path
|
86
86
|
|
87
|
-
|
87
|
+
`tar xf #{resource_path} -C #{app_path} --strip-components=1`
|
88
|
+
rm "#{app_path}/conf/install.php" if File.exists? "#{app_path}/conf/install.php"
|
89
|
+
cp "#{hook_path}/templates/acl.auth.php", "#{app_path}/conf/acl.auth.php"
|
90
|
+
cp "#{hook_path}/templates/local.php", "#{app_path}/conf/local.php"
|
91
|
+
cp "#{hook_path}/templates/plugins.local.php", "#{app_path}/conf/plugin.local.php"
|
88
92
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
resource_path = resource 'development-release'
|
94
|
-
else
|
95
|
-
status :blocked, "Unknown release given #{release}"
|
96
|
-
exit 1
|
97
|
-
end
|
93
|
+
version = File.read "#{app_path}/VERSION"
|
94
|
+
`application-version-set '#{version}'`
|
95
|
+
`status-set active Dokuwiki Install finished.`
|
96
|
+
end
|
98
97
|
|
99
|
-
|
98
|
+
desc "Configure Dokuwiki"
|
99
|
+
task :config_changed do
|
100
|
+
app_path = `config-get app_path`
|
101
|
+
hook_path = ENV['JUJU_CHARM_DIR']
|
100
102
|
|
101
|
-
|
103
|
+
admin_user = `config-get #{admin_user}`
|
104
|
+
admin_password = `config-get admin_password`
|
105
|
+
admin_name = `config-get admin_name`
|
106
|
+
admin_email = `config-get admin_email`
|
107
|
+
template "#{hook_path}/templates/users.auth.php",
|
108
|
+
"#{app_path}/conf/users.auth.php",
|
109
|
+
admin_user: admin_user,
|
110
|
+
admin_password: admin_password,
|
111
|
+
admin_name: admin_name,
|
112
|
+
admin_email: admin_email
|
113
|
+
|
114
|
+
template "#{hook_path}/templates/vhost.conf",
|
115
|
+
"/etc/nginx/sites-enabled/default",
|
116
|
+
public_address: unit('public-address'),
|
117
|
+
app_path: app_path
|
118
|
+
|
119
|
+
chown_R 'www-data', 'www-data', app_path
|
120
|
+
|
121
|
+
# TODO: service :restart, "nginx"
|
122
|
+
# TODO: service :restart, "php7.0-fpm"
|
123
|
+
`systemctl restart php7.0-fpm`
|
124
|
+
`systemctl restart nginx`
|
125
|
+
`status-set active Ready`
|
102
126
|
end
|
103
127
|
end
|
104
128
|
```
|
105
129
|
|
106
|
-
The core of Charmkit
|
107
|
-
|
108
|
-
|
109
|
-
* core - Gives you access to things like *package*, *mkdir_p*, *chown_R*, etc.
|
110
|
-
* hookenv - Provides access to Juju hook items such as *resource*, *unit*, *juju-log*, etc.
|
130
|
+
The core of Charmkit contains a few helpers such as template rendering but
|
131
|
+
otherwise kept relatively small.
|
111
132
|
|
112
133
|
## Packaging the Charm
|
113
134
|
|
data/Rakefile
CHANGED
data/charmkit.gemspec
CHANGED
@@ -21,10 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "tty-command", "~> 0.2.0"
|
25
|
-
|
26
24
|
spec.add_development_dependency "bundler", "~> 1.13"
|
27
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
27
|
spec.add_development_dependency "pry", "~> 0.10.4"
|
28
|
+
spec.add_development_dependency "yard"
|
30
29
|
end
|
@@ -1,76 +1,5 @@
|
|
1
1
|
# -*- mode:ruby -*-
|
2
2
|
|
3
|
-
name "dokuwiki"
|
4
|
-
summary "Dokuwiki is a simple to use wiki"
|
5
|
-
desc <<~EOF
|
6
|
-
DokuWiki is a simple to use and highly versatile Open Source wiki software
|
7
|
-
that doesn't require a database. It is loved by users for its clean and
|
8
|
-
readable syntax.
|
9
|
-
EOF
|
10
|
-
maintainer 'Adam Stokes <adam.stokes@ubuntu.com>'
|
11
|
-
license 'MIT'
|
12
|
-
copyright_holder 'Canonical Ltd.'
|
13
|
-
copyright_year '2016'
|
14
|
-
url "https://github.com/battlemidget/juju-charm-dokuwiki.rb"
|
15
|
-
bugs "https://github.com/battlemidget/juju-charm-dokuwiki.rb/issues"
|
16
|
-
|
17
|
-
series "xenial"
|
18
|
-
series "trusty"
|
19
|
-
|
20
|
-
# CONFIG ######################################################################
|
21
|
-
# These items will be exposed to the charm via `config-get`
|
22
|
-
config "app_path" do
|
23
|
-
type :string
|
24
|
-
default "/srv/app"
|
25
|
-
desc "Where to store dokuwiki source"
|
26
|
-
end
|
27
|
-
|
28
|
-
config "release" do
|
29
|
-
type :string
|
30
|
-
default "/srv/app"
|
31
|
-
desc "Dokuwiki release"
|
32
|
-
end
|
33
|
-
|
34
|
-
config "admin_user" do
|
35
|
-
type :string
|
36
|
-
default "admin"
|
37
|
-
desc "Admin username (default: admin)"
|
38
|
-
end
|
39
|
-
|
40
|
-
config "admin_password" do
|
41
|
-
type :string
|
42
|
-
default "5f4dcc3b5aa765d61d8327deb882cf99"
|
43
|
-
desc "Admin password md5 hash format (default password: password)"
|
44
|
-
end
|
45
|
-
|
46
|
-
config "admin_name" do
|
47
|
-
type :string
|
48
|
-
default "The Admin"
|
49
|
-
desc "Name of admin"
|
50
|
-
end
|
51
|
-
|
52
|
-
config "admin_email" do
|
53
|
-
type :string
|
54
|
-
default "adam@root.me"
|
55
|
-
desc "Admin email"
|
56
|
-
end
|
57
|
-
# END #########################################################################
|
58
|
-
|
59
|
-
# RESOURCES ###################################################################
|
60
|
-
# These items will be exposed to the charm via `resource-get`
|
61
|
-
resource "stable-release" do
|
62
|
-
type :file
|
63
|
-
filename "stable.tgz"
|
64
|
-
desc "Dokuwiki stable"
|
65
|
-
end
|
66
|
-
|
67
|
-
resource "development-release" do
|
68
|
-
type :file
|
69
|
-
filename "deveopment.tgz"
|
70
|
-
desc "Dokuwiki development"
|
71
|
-
end
|
72
|
-
# END #########################################################################
|
73
|
-
|
74
3
|
depends_on "nginx-full"
|
75
4
|
depends_on "php-fpm"
|
76
5
|
depends_on "php-cgi"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'charmkit'
|
2
|
+
|
3
|
+
class Install < Charmkit
|
4
|
+
plugin :core
|
5
|
+
plugin :nginx
|
6
|
+
plugin :php
|
7
|
+
|
8
|
+
incant :nginx_install do |nginx|
|
9
|
+
ngnix.install
|
10
|
+
nginx.set_vhost server_name: config('server_name'),
|
11
|
+
application_path: config('app_path')
|
12
|
+
end
|
13
|
+
incant :php_install do |php|
|
14
|
+
php.install version: 7,
|
15
|
+
plugins: ['fpm',
|
16
|
+
'cgi',
|
17
|
+
'curl',
|
18
|
+
'gd',
|
19
|
+
'json',
|
20
|
+
'mcrypt',
|
21
|
+
'readline',
|
22
|
+
'mbstring',
|
23
|
+
'xml']
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def summon
|
28
|
+
log "Running example charm code"
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
example charm demo using charmkit
|
data/examples/plugin_loader.rb
CHANGED
data/examples/template.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Charmkit
|
4
|
+
module Helpers
|
5
|
+
# Processes templates
|
6
|
+
#
|
7
|
+
# template 'my-template.erb' '/etc/config/me.conf', service_name: "nginx"
|
8
|
+
class TemplateRenderer
|
9
|
+
def self.empty_binding
|
10
|
+
binding
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.render(template_content, locals = {})
|
14
|
+
b = empty_binding
|
15
|
+
locals.each { |k, v| b.local_variable_set(k, v) }
|
16
|
+
ERB.new(template_content).result(b)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def template(src, dst, **context)
|
21
|
+
rendered = TemplateRenderer.render(File.read(src), context)
|
22
|
+
File.write(dst, rendered)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Charmkit
|
2
|
+
module Plugins
|
3
|
+
module NGINXPlugin
|
4
|
+
module InstanceMethods
|
5
|
+
class NGINX
|
6
|
+
include Charmkit::Helpers::FS
|
7
|
+
def initialize
|
8
|
+
if !is_installed? 'nginx-full'
|
9
|
+
status :maintenance, 'Installing NGINX'
|
10
|
+
package ['nginx-full']
|
11
|
+
status :active, "NGINX installed."
|
12
|
+
end
|
13
|
+
yield(self)
|
14
|
+
end
|
15
|
+
def install_vhost
|
16
|
+
puts "installing vhost"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
register_plugin(:nginx, NGINXPlugin)
|
22
|
+
end
|
23
|
+
end
|
data/lib/charmkit/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
module Charmkit
|
2
2
|
def self.version
|
3
3
|
Gem::Version.new VERSION::STRING
|
4
4
|
end
|
@@ -6,7 +6,7 @@ class Charmkit
|
|
6
6
|
module VERSION
|
7
7
|
MAJOR = 0
|
8
8
|
MINOR = 3
|
9
|
-
PATCH =
|
9
|
+
PATCH = 8
|
10
10
|
PRE = nil
|
11
11
|
|
12
12
|
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
data/lib/charmkit.rb
CHANGED
@@ -1,71 +1,8 @@
|
|
1
1
|
require "charmkit/version"
|
2
|
+
require "charmkit/helpers/template"
|
2
3
|
|
3
|
-
|
4
|
+
module Charmkit
|
4
5
|
# A generic exception by Charmkit
|
5
6
|
class Error < StandardError; end
|
6
|
-
|
7
|
-
@opts = {}
|
8
|
-
|
9
|
-
module Plugins
|
10
|
-
@plugins = {}
|
11
|
-
|
12
|
-
def self.load_plugin(name)
|
13
|
-
unless plugin = @plugins[name]
|
14
|
-
require "charmkit/plugins/#{name}"
|
15
|
-
raise Error, "plugin #{name} did not register itself correctly in Charmkit::Plugins" unless plugin = @plugins[name]
|
16
|
-
end
|
17
|
-
plugin
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.register_plugin(name, mod)
|
21
|
-
@plugins[name] = mod
|
22
|
-
end
|
23
|
-
|
24
|
-
module Base
|
25
|
-
module ClassMethods
|
26
|
-
# Generic options for this class, plugins store their options here.
|
27
|
-
attr_reader :opts
|
28
|
-
|
29
|
-
def inherited(subclass)
|
30
|
-
subclass.instance_variable_set(:@opts, opts.dup)
|
31
|
-
subclass.opts.each do |key, value|
|
32
|
-
if value.is_a?(Enumerable) && !value.frozen?
|
33
|
-
subclass.opts[key] = value.dup
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
def plugin(plugin, *args, &block)
|
38
|
-
plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
|
39
|
-
plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)
|
40
|
-
self.include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
|
41
|
-
self.extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
|
42
|
-
plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
module InstanceMethods
|
48
|
-
# The class-level options hash. This should probably not be modified at
|
49
|
-
# the instance level.
|
50
|
-
def opts
|
51
|
-
self.class.opts
|
52
|
-
end
|
53
|
-
|
54
|
-
# This performs the actual work of installing, configuring, restarting
|
55
|
-
# of services.
|
56
|
-
#
|
57
|
-
# class Install < Charmkit
|
58
|
-
# def summon
|
59
|
-
# cp "#{ENV['JUJU_CHARM_DIR']}/templates/nginx.conf.tpl",
|
60
|
-
# "/etc/nginx/nginx.conf"
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
def summon
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
extend Plugins::Base::ClassMethods
|
70
|
-
plugin Plugins::Base
|
71
7
|
end
|
8
|
+
extend Charmkit::Helpers
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charmkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
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-
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: tty-command
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,11 +66,24 @@ dependencies:
|
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: 0.10.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
83
|
description: ''
|
84
84
|
email:
|
85
85
|
- battlemidget@users.noreply.github.com
|
86
|
-
executables:
|
87
|
-
- charmkit
|
86
|
+
executables: []
|
88
87
|
extensions: []
|
89
88
|
extra_rdoc_files: []
|
90
89
|
files:
|
@@ -99,16 +98,17 @@ files:
|
|
99
98
|
- bin/console
|
100
99
|
- bin/setup
|
101
100
|
- charmkit.gemspec
|
102
|
-
- examples/
|
101
|
+
- examples/Charmkitfile
|
103
102
|
- examples/basic.rb
|
103
|
+
- examples/demo/lib/install.rb
|
104
|
+
- examples/demo/readme
|
104
105
|
- examples/plugin_loader.rb
|
105
106
|
- examples/template.rb
|
106
107
|
- examples/templates/user_auth.txt
|
107
|
-
- exe/charmkit
|
108
108
|
- lib/charmkit.rb
|
109
109
|
- lib/charmkit/extend/string_tools.rb
|
110
|
-
- lib/charmkit/
|
111
|
-
- lib/charmkit/plugins/
|
110
|
+
- lib/charmkit/helpers/template.rb
|
111
|
+
- lib/charmkit/plugins/nginx.rb
|
112
112
|
- lib/charmkit/version.rb
|
113
113
|
homepage: http://charmkit.org
|
114
114
|
licenses:
|
data/exe/charmkit
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "charmkit/extend/string_tools"
|
4
|
-
|
5
|
-
if ARGV.length > 1
|
6
|
-
puts "To many arguments, should be one of 'install, config-changed, start, stop, upgrade-charm'"
|
7
|
-
exit 1
|
8
|
-
end
|
9
|
-
|
10
|
-
hook_name = ARGV.pop
|
11
|
-
|
12
|
-
if File.exists?("./lib/#{hook_name}.rb")
|
13
|
-
require "./lib/#{hook_name}"
|
14
|
-
else
|
15
|
-
puts "Could not find hook in ./lib/#{hook_name}.rb"
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
|
19
|
-
puts "Loading #{hook_name}"
|
20
|
-
m = Object.const_get(hook_name.classify).new
|
21
|
-
m.summon
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'tty-command'
|
3
|
-
require 'erb'
|
4
|
-
|
5
|
-
class Charmkit
|
6
|
-
module Plugins
|
7
|
-
module Core
|
8
|
-
module InstanceMethods
|
9
|
-
FileUtils.singleton_methods.each do |m|
|
10
|
-
define_method m, FileUtils.method(m).to_proc
|
11
|
-
end
|
12
|
-
|
13
|
-
def file(dst, content:)
|
14
|
-
File.write(dst, content)
|
15
|
-
end
|
16
|
-
|
17
|
-
def is_file?(path)
|
18
|
-
return File.exists? path
|
19
|
-
end
|
20
|
-
|
21
|
-
def is_dir?(path)
|
22
|
-
return Dir.exists? path
|
23
|
-
end
|
24
|
-
|
25
|
-
def cat(src)
|
26
|
-
return File.read(src)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Run commands optionally getting it's output, error
|
30
|
-
#
|
31
|
-
# run 'ls -l /tmp'
|
32
|
-
def run(data)
|
33
|
-
if ENV['DRYRUN']
|
34
|
-
puts "DRYRUN: #{data}"
|
35
|
-
else
|
36
|
-
cmd = TTY::Command.new(printer: :null)
|
37
|
-
return cmd.run(data)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
# Processes templates
|
43
|
-
#
|
44
|
-
# template 'my-template.erb' '/etc/config/me.conf', service_name: "nginx"
|
45
|
-
class TemplateRenderer
|
46
|
-
def self.empty_binding
|
47
|
-
binding
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.render(template_content, locals = {})
|
51
|
-
b = empty_binding
|
52
|
-
locals.each { |k, v| b.local_variable_set(k, v) }
|
53
|
-
ERB.new(template_content).result(b)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def template(src, dst, **context)
|
58
|
-
rendered = TemplateRenderer.render(File.read(src), context)
|
59
|
-
File.write(dst, rendered)
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# Installs packages
|
64
|
-
#
|
65
|
-
# package ['nginx-full'], :update_cache
|
66
|
-
def package(packages, *opts)
|
67
|
-
if opts.include?(:update_cache)
|
68
|
-
run "apt-get update"
|
69
|
-
end
|
70
|
-
run "apt-get install -qyf #{packages.join(' ')}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def is_installed?(package)
|
74
|
-
begin
|
75
|
-
run "dpkg -s #{package}" and return true
|
76
|
-
rescue
|
77
|
-
return false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
register_plugin(:core, Core)
|
83
|
-
end
|
84
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class Charmkit
|
2
|
-
module Plugins
|
3
|
-
module HookEnv
|
4
|
-
module InstanceMethods
|
5
|
-
# calls status-set in juju environment
|
6
|
-
def status(level=:maintenance, msg="")
|
7
|
-
levels = [:maintenance, :active, :blocked, :waiting]
|
8
|
-
raise unless levels.include?(level)
|
9
|
-
run "status-set #{level.to_s} '#{msg}'"
|
10
|
-
end
|
11
|
-
|
12
|
-
def config(item)
|
13
|
-
out, err = run "config-get '#{item}'"
|
14
|
-
return out.chomp
|
15
|
-
end
|
16
|
-
|
17
|
-
def resource(item)
|
18
|
-
out, err = run "resource-get '#{item}'"
|
19
|
-
return out.chomp
|
20
|
-
end
|
21
|
-
|
22
|
-
def unit(item)
|
23
|
-
out, err = run "unit-get '#{item}'"
|
24
|
-
return out.chomp
|
25
|
-
end
|
26
|
-
|
27
|
-
def action(item)
|
28
|
-
out, err = run "action-get '#{item}'"
|
29
|
-
return out.chomp
|
30
|
-
end
|
31
|
-
|
32
|
-
def action=(item)
|
33
|
-
out, err = run "action-set '#{item}'"
|
34
|
-
return out.chomp
|
35
|
-
end
|
36
|
-
|
37
|
-
def log(msg)
|
38
|
-
run "juju-log #{msg}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
register_plugin(:hookenv, HookEnv)
|
43
|
-
end
|
44
|
-
end
|