charmkit 0.3.4 → 0.3.5
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/.gitignore +1 -0
- data/README.md +82 -24
- data/charmkit.gemspec +2 -1
- data/examples/CKfile +137 -0
- data/examples/basic.rb +5 -5
- data/examples/plugin_loader.rb +9 -0
- data/exe/charmkit +21 -0
- data/lib/charmkit/extend/string_tools.rb +14 -0
- data/lib/charmkit/plugins/core.rb +84 -0
- data/lib/charmkit/plugins/hookenv.rb +44 -0
- data/lib/charmkit/version.rb +13 -2
- data/lib/charmkit.rb +69 -7
- metadata +24 -8
- data/lib/charmkit/fs.rb +0 -21
- data/lib/charmkit/hook-tools.rb +0 -40
- data/lib/charmkit/package.rb +0 -19
- data/lib/charmkit/runner.rb +0 -14
- data/lib/charmkit/template.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f742ba89357ad616835697ea86d6f9a079f3faf
|
4
|
+
data.tar.gz: 2432ac3a5dce8a156d1ff2c4112c7a04a2d5279c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a7ddce6c4a359fb5da2c00755857013cc5d2a10ae30faf9918f563ced7b9f8d38c2e367d03f1440c5ecc43081aae0684cf712e3097207c77ecf4f00b49a86e6
|
7
|
+
data.tar.gz: 690573d393d1ed24982e2401d6eae53e69b26e27acf81b4292659a6efac64b921ff30793c1f44a871196c37778d0299805a1f81f4392ab0a200c03db8d482859
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,48 +22,107 @@ Or install it yourself as:
|
|
22
22
|
In **hooks/install**:
|
23
23
|
|
24
24
|
```
|
25
|
-
#!/bin/
|
25
|
+
#!/bin/sh
|
26
26
|
|
27
27
|
apt-get update
|
28
28
|
apt-get install -qyf ruby
|
29
29
|
gem install bundler
|
30
30
|
|
31
|
-
bundle install --
|
31
|
+
bundle install --local --quiet
|
32
|
+
|
33
|
+
# Runs the lib/install.rb hook
|
34
|
+
bundle exec charmkit install
|
35
|
+
```
|
36
|
+
|
37
|
+
In other hooks call *charmkit* with the execing hook (eg. **hooks/config-changed**)
|
38
|
+
|
39
|
+
```
|
40
|
+
#!/bin/sh
|
41
|
+
|
42
|
+
bundle exec charmkit config-changed
|
43
|
+
```
|
44
|
+
|
45
|
+
Same for **hooks/upgrade-charm**
|
46
|
+
|
47
|
+
```
|
48
|
+
#!/bin/sh
|
49
|
+
|
50
|
+
bundle exec charmkit upgrade-charm
|
32
51
|
```
|
33
52
|
|
34
|
-
|
53
|
+
## Writing Charmkit style hooks
|
54
|
+
|
55
|
+
All Charmkit hooks must reside in the charm's toplevel **lib/** directory. Those
|
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:
|
66
|
+
|
67
|
+
### Syntax
|
35
68
|
|
36
69
|
```ruby
|
37
|
-
#!/usr/bin/env ruby
|
38
|
-
require_relative '../bundle/bundler/setup'
|
39
70
|
require 'charmkit'
|
40
71
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
72
|
+
class ConfigChanged < Charmkit
|
73
|
+
plugin :core
|
74
|
+
plugin :hookenv
|
75
|
+
|
76
|
+
def summon
|
77
|
+
package [
|
78
|
+
'nginx-full', 'php-fpm', 'php-cgi', 'php-curl', 'php-gd', 'php-json',
|
79
|
+
'php-mcrypt', 'php-readline', 'php-mbstring', 'php-xml'
|
80
|
+
], :update_cache
|
81
|
+
|
82
|
+
hook_path = ENV['JUJU_CHARM_DIR']
|
83
|
+
app_path = config 'app_path'
|
45
84
|
|
46
|
-
|
47
|
-
app_path = config 'app_path'
|
85
|
+
mkdir app_path unless is_dir? app_path
|
48
86
|
|
49
|
-
|
87
|
+
release = config 'release'
|
50
88
|
|
51
|
-
|
89
|
+
case release
|
90
|
+
when "stable"
|
91
|
+
resource_path = resource 'stable-release'
|
92
|
+
when "development"
|
93
|
+
resource_path = resource 'development-release'
|
94
|
+
else
|
95
|
+
status :blocked, "Unknown release given #{release}"
|
96
|
+
exit 1
|
97
|
+
end
|
52
98
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
resource_path = resource 'development-release'
|
58
|
-
else
|
59
|
-
status :blocked, "Unknown release given #{release}"
|
60
|
-
exit 1
|
99
|
+
run "tar xf #{resource_path} -C #{app_path} --strip-components=1"
|
100
|
+
|
101
|
+
rm "#{app_path}/conf/install.php" unless !is_file? "#{app_path}/conf/install.php"
|
102
|
+
end
|
61
103
|
end
|
104
|
+
```
|
105
|
+
|
106
|
+
The core of Charmkit is relatively small and everything is handled through
|
107
|
+
plugins. Current plugins are:
|
62
108
|
|
63
|
-
|
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.
|
111
|
+
|
112
|
+
## Packaging the Charm
|
113
|
+
|
114
|
+
You'll want to make sure that any Ruby gems used are packaged with your charm so
|
115
|
+
that you aren't forcing users to try to download those dependencies during
|
116
|
+
deployment.
|
117
|
+
|
118
|
+
Easiest way to package your deps is:
|
64
119
|
|
65
|
-
rm "#{app_path}/conf/install.php" unless !is_file? "#{app_path}/conf/install.php"
|
66
120
|
```
|
121
|
+
$ bundle package
|
122
|
+
```
|
123
|
+
|
124
|
+
This will place your deps inside `vendor/cache` which will be uploaded when
|
125
|
+
executing a `charm push .`
|
67
126
|
|
68
127
|
## Development
|
69
128
|
|
@@ -88,4 +147,3 @@ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
88
147
|
|
89
148
|
The gem is available as open source under the terms of
|
90
149
|
the [MIT License](http://opensource.org/licenses/MIT).
|
91
|
-
|
data/charmkit.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'charmkit/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "charmkit"
|
8
|
-
spec.version = Charmkit
|
8
|
+
spec.version = Charmkit.version
|
9
9
|
spec.authors = ["Adam Stokes"]
|
10
10
|
spec.email = ["battlemidget@users.noreply.github.com"]
|
11
11
|
|
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.13"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
29
30
|
end
|
data/examples/CKfile
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# -*- mode:ruby -*-
|
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
|
+
depends_on "nginx-full"
|
75
|
+
depends_on "php-fpm"
|
76
|
+
depends_on "php-cgi"
|
77
|
+
depends_on "php-curl"
|
78
|
+
depends_on "php-gd"
|
79
|
+
depends_on "php-json"
|
80
|
+
depends_on "php-mcrypt"
|
81
|
+
depends_on "php-readline"
|
82
|
+
depends_on "php-mbstring"
|
83
|
+
depends_on "php-xml"
|
84
|
+
|
85
|
+
hook "install" do
|
86
|
+
release = "#{config['release']}-release"
|
87
|
+
app_path = config 'app_path'
|
88
|
+
hook_path = ENV['JUJU_CHARM_DIR']
|
89
|
+
run "tar xf #{resource[release]} -C #{app_path} --strip-components=1"
|
90
|
+
rm "#{app_path}/conf/install.php" if is_file? "#{app_path}/conf/install.php"
|
91
|
+
cp "#{hook_path}/templates/acl.auth.php", "#{app_path}/conf/acl.auth.php"
|
92
|
+
cp "#{hook_path}/templates/local.php", "#{app_path}/conf/local.php"
|
93
|
+
cp "#{hook_path}/templates/plugins.local.php", "#{app_path}/conf/plugin.local.php"
|
94
|
+
file "/etc/dokuwiki-release", content: release
|
95
|
+
case release
|
96
|
+
when "stable"
|
97
|
+
version = cat "#{app_path}/VERSION"
|
98
|
+
run "application-version-set '#{version}'"
|
99
|
+
when "development"
|
100
|
+
t = Time.now
|
101
|
+
version = t.strftime "%Y-%m-%d"
|
102
|
+
run "application-version-set 'development-#{version}'"
|
103
|
+
else
|
104
|
+
status :blocked, "Unable to set proper application version"
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
hook "config-changed" do
|
110
|
+
app_path = config 'app_path'
|
111
|
+
hook_path = ENV['JUJU_CHARM_DIR']
|
112
|
+
installed_release = cat "/etc/dokuwiki-release"
|
113
|
+
release = config 'release'
|
114
|
+
if !installed_release.eql? release
|
115
|
+
run './hooks/install'
|
116
|
+
end
|
117
|
+
|
118
|
+
admin_user = config 'admin_user'
|
119
|
+
admin_password = config 'admin_password'
|
120
|
+
admin_name = config 'admin_name'
|
121
|
+
admin_email = config 'admin_email'
|
122
|
+
template "#{hook_path}/templates/users.auth.php",
|
123
|
+
"#{app_path}/conf/users.auth.php",
|
124
|
+
admin_user: admin_user,
|
125
|
+
admin_password: admin_password,
|
126
|
+
admin_name: admin_name,
|
127
|
+
admin_email: admin_email
|
128
|
+
|
129
|
+
template "#{hook_path}/templates/vhost.conf",
|
130
|
+
"/etc/nginx/sites-enabled/default",
|
131
|
+
public_address: unit['public-address'],
|
132
|
+
app_path: app_path
|
133
|
+
|
134
|
+
chown_R 'www-data', 'www-data', app_path
|
135
|
+
run "systemctl restart nginx"
|
136
|
+
status :active, "Ready"
|
137
|
+
end
|
data/examples/basic.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative './plugin_loader'
|
2
2
|
|
3
|
-
run 'ls -l /tmp'
|
4
|
-
status :active, "running application status..."
|
5
|
-
package ['znc', 'znc-perl', 'znc-python'], :update_cache
|
6
|
-
is_installed? 'znc'
|
3
|
+
# run 'ls -l /tmp'
|
4
|
+
# status :active, "running application status..."
|
5
|
+
# package ['znc', 'znc-perl', 'znc-python'], :update_cache
|
6
|
+
# is_installed? 'znc'
|
data/exe/charmkit
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class String
|
2
|
+
# Simple classify to rename our hooks to their proper class
|
3
|
+
#
|
4
|
+
# charmkit config-changed
|
5
|
+
#
|
6
|
+
# This will load config-changed.rb and classify it's name to
|
7
|
+
# ConfigChanged.
|
8
|
+
#
|
9
|
+
# Note most libraries use '_'(underscore) for word separation whereas
|
10
|
+
# Juju hooks are '-'(hyphenated).
|
11
|
+
def classify
|
12
|
+
return self.split('-').collect!{ |w| w.capitalize }.join
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Charmkit
|
2
|
+
module Plugins
|
3
|
+
module HookEnv
|
4
|
+
module ClassMethods
|
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
|
data/lib/charmkit/version.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class Charmkit
|
2
|
+
def self.version
|
3
|
+
Gem::Version.new VERSION::STRING
|
4
|
+
end
|
5
|
+
|
6
|
+
module VERSION
|
7
|
+
MAJOR = 0
|
8
|
+
MINOR = 3
|
9
|
+
PATCH = 5
|
10
|
+
PRE = nil
|
11
|
+
|
12
|
+
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
13
|
+
end
|
3
14
|
end
|
data/lib/charmkit.rb
CHANGED
@@ -1,9 +1,71 @@
|
|
1
|
-
require "charmkit/runner"
|
2
|
-
require "charmkit/hook-tools"
|
3
|
-
require "charmkit/package"
|
4
|
-
require "charmkit/template"
|
5
|
-
require "charmkit/fs"
|
6
1
|
require "charmkit/version"
|
7
2
|
|
8
|
-
|
9
|
-
|
3
|
+
class Charmkit
|
4
|
+
# A generic exception by Charmkit
|
5
|
+
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
|
+
end
|
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.3.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-command
|
@@ -66,10 +66,25 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
69
83
|
description: ''
|
70
84
|
email:
|
71
85
|
- battlemidget@users.noreply.github.com
|
72
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- charmkit
|
73
88
|
extensions: []
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
@@ -84,15 +99,16 @@ files:
|
|
84
99
|
- bin/console
|
85
100
|
- bin/setup
|
86
101
|
- charmkit.gemspec
|
102
|
+
- examples/CKfile
|
87
103
|
- examples/basic.rb
|
104
|
+
- examples/plugin_loader.rb
|
88
105
|
- examples/template.rb
|
89
106
|
- examples/templates/user_auth.txt
|
107
|
+
- exe/charmkit
|
90
108
|
- lib/charmkit.rb
|
91
|
-
- lib/charmkit/
|
92
|
-
- lib/charmkit/
|
93
|
-
- lib/charmkit/
|
94
|
-
- lib/charmkit/runner.rb
|
95
|
-
- lib/charmkit/template.rb
|
109
|
+
- lib/charmkit/extend/string_tools.rb
|
110
|
+
- lib/charmkit/plugins/core.rb
|
111
|
+
- lib/charmkit/plugins/hookenv.rb
|
96
112
|
- lib/charmkit/version.rb
|
97
113
|
homepage: http://charmkit.org
|
98
114
|
licenses:
|
data/lib/charmkit/fs.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Charmkit
|
4
|
-
module DSL
|
5
|
-
FileUtils.singleton_methods.each do |m|
|
6
|
-
define_method m, FileUtils.method(m).to_proc
|
7
|
-
end
|
8
|
-
def is_file?(path)
|
9
|
-
return File.exists? path
|
10
|
-
end
|
11
|
-
def is_dir?(path)
|
12
|
-
return Dir.exists? path
|
13
|
-
end
|
14
|
-
def spew(dst, content)
|
15
|
-
File.write(dst, content)
|
16
|
-
end
|
17
|
-
def slurp(src)
|
18
|
-
return File.read(src)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/charmkit/hook-tools.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# Hook tools module for exposing things such as status-set and action-set
|
2
|
-
module Charmkit
|
3
|
-
module DSL
|
4
|
-
# calls status-set in juju environment
|
5
|
-
def status(level=:maintenance, msg="")
|
6
|
-
levels = [:maintenance, :active, :blocked, :waiting]
|
7
|
-
raise unless levels.include?(level)
|
8
|
-
run "status-set #{level.to_s} '#{msg}'"
|
9
|
-
end
|
10
|
-
|
11
|
-
def config(item)
|
12
|
-
out, err = run "config-get #{item}"
|
13
|
-
return out.chomp
|
14
|
-
end
|
15
|
-
|
16
|
-
def resource(item)
|
17
|
-
out, err = run "resource-get #{item}"
|
18
|
-
return out.chomp
|
19
|
-
end
|
20
|
-
|
21
|
-
def unit(item)
|
22
|
-
out, err = run "unit-get #{item}"
|
23
|
-
return out.chomp
|
24
|
-
end
|
25
|
-
|
26
|
-
def action(item)
|
27
|
-
out, err = run "action-get #{item}"
|
28
|
-
return out.chomp
|
29
|
-
end
|
30
|
-
|
31
|
-
def action=(item)
|
32
|
-
out, err = run "action-set #{item}"
|
33
|
-
return out.chomp
|
34
|
-
end
|
35
|
-
|
36
|
-
def log(msg)
|
37
|
-
run "juju-log #{msg}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/charmkit/package.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Charmkit
|
2
|
-
module DSL
|
3
|
-
# installs apt packages
|
4
|
-
def package(packages, *opts)
|
5
|
-
if opts.include?(:update_cache)
|
6
|
-
run "apt-get update"
|
7
|
-
end
|
8
|
-
run "apt-get install -qyf #{packages.join(' ')}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def is_installed?(package)
|
12
|
-
begin
|
13
|
-
run "dpkg -s #{package}" and return true
|
14
|
-
rescue
|
15
|
-
return false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/charmkit/runner.rb
DELETED
data/lib/charmkit/template.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
module Charmkit
|
4
|
-
module DSL
|
5
|
-
class TemplateRenderer
|
6
|
-
def self.empty_binding
|
7
|
-
binding
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.render(template_content, locals = {})
|
11
|
-
b = empty_binding
|
12
|
-
locals.each { |k, v| b.local_variable_set(k, v) }
|
13
|
-
ERB.new(template_content).result(b)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def template(src, dst, **context)
|
18
|
-
rendered = TemplateRenderer.render(File.read(src), context)
|
19
|
-
File.write(dst, rendered)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|