charmkit 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/README.md +46 -94
  4. data/charmkit.gemspec +3 -3
  5. data/examples/Charmkitfile +66 -0
  6. data/examples/basic.rb +6 -0
  7. data/examples/demo/Gemfile +10 -0
  8. data/examples/demo/Gemfile.lock +64 -0
  9. data/examples/demo/README.md +27 -0
  10. data/examples/demo/Rakefile +9 -0
  11. data/examples/demo/config.yaml +2 -0
  12. data/examples/demo/hooks/config-changed +3 -0
  13. data/examples/{my-demo-charm → demo}/hooks/install +3 -5
  14. data/examples/demo/hooks/leader-elected +3 -0
  15. data/examples/demo/hooks/leader-settings-changed +3 -0
  16. data/examples/demo/hooks/start +3 -0
  17. data/examples/demo/hooks/stop +3 -0
  18. data/examples/demo/hooks/update-status +3 -0
  19. data/examples/demo/hooks/upgrade-charm +3 -0
  20. data/examples/demo/metadata.yaml +9 -0
  21. data/examples/load-charmkit-file.rb +2 -0
  22. data/examples/plugin_loader.rb +9 -0
  23. data/examples/template.rb +6 -0
  24. data/examples/templates/user_auth.txt +1 -0
  25. data/exe/charmkit +5 -0
  26. data/lib/charmkit.rb +6 -7
  27. data/lib/charmkit/cli.rb +124 -0
  28. data/lib/charmkit/dependencies.rb +26 -0
  29. data/lib/charmkit/helpers.rb +5 -0
  30. data/lib/charmkit/helpers/crypt.rb +8 -6
  31. data/lib/charmkit/helpers/fs.rb +0 -15
  32. data/lib/charmkit/helpers/hookenv.rb +10 -0
  33. data/lib/charmkit/helpers/runner.rb +2 -1
  34. data/lib/charmkit/helpers/template.rb +1 -0
  35. data/lib/charmkit/hook.rb +47 -0
  36. data/lib/charmkit/scroll.rb +15 -0
  37. metadata +48 -29
  38. data/examples/my-demo-charm/Gemfile +0 -5
  39. data/examples/my-demo-charm/Gemfile.lock +0 -15
  40. data/examples/my-demo-charm/README.md +0 -45
  41. data/examples/my-demo-charm/Rakefile +0 -63
  42. data/examples/my-demo-charm/config.yaml +0 -21
  43. data/examples/my-demo-charm/copyright +0 -21
  44. data/examples/my-demo-charm/hooks/config-changed +0 -3
  45. data/examples/my-demo-charm/hooks/upgrade-charm +0 -3
  46. data/examples/my-demo-charm/icon.svg +0 -322
  47. data/examples/my-demo-charm/metadata.yaml +0 -18
  48. data/examples/my-demo-charm/readme +0 -1
  49. data/examples/my-demo-charm/tasks/vim.rb +0 -8
  50. data/examples/my-demo-charm/templates/acl.auth.php +0 -10
  51. data/examples/my-demo-charm/templates/local.php +0 -15
  52. data/examples/my-demo-charm/templates/plugins.local.php +0 -12
  53. data/examples/my-demo-charm/templates/users.auth.php +0 -11
  54. data/examples/my-demo-charm/templates/vhost.conf +0 -42
  55. data/examples/render_inline.rb +0 -59
  56. data/lib/charmkit/extend/string_tools.rb +0 -14
  57. data/lib/charmkit/plugins/nginx.rb +0 -8
  58. data/lib/charmkit/plugins/php.rb +0 -19
  59. data/lib/charmkit/version.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cab89bb4367d2520c771adeccc76c45e4098adfc
4
- data.tar.gz: 351e253c40b3dd3b8470bb54315e5acc76a61d67
3
+ metadata.gz: 34c131cea62bf4d8cf2e3fd63e5919962c62fa37
4
+ data.tar.gz: c0252140b1e1f42646961889f077950e6f1989c3
5
5
  SHA512:
6
- metadata.gz: 0aee6d94779fd83872a7d733a14b70b7bde72cc815e2a077a224d95aa6f6e5fe2968d0c72a68b956263044c2553803528d3ff360ae99ff8846a6565ab55a9433
7
- data.tar.gz: 5889275117a7f500349ae48e1c17758015419ab2ad3b4e305b33078327b8a07e4202993d286f61963e6eb489dfecb9241a2205d172d07fbd8ca5ac7196c3c0c4
6
+ metadata.gz: df357ff4b8222ae01e4e5d724dbd4d5e813216ee378b4e3d3e37de6a2ed958adfaf03eb51fcbc2dcf3ee5558f709351ee02cd90b70a53c2934ddc5a390aec6da
7
+ data.tar.gz: 12e5bc325ced514f7a5858d3685ef4b43bed7082715497cfe0db8828d02ef582aadd782201c0cb3f9feaaa572f4f1db9f88cf2604a58b1cf4a1893399d3e4a80
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4.0
data/README.md CHANGED
@@ -19,29 +19,27 @@ 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
-
25
22
  In **hooks/install**:
26
23
 
27
24
  ```
28
25
  #!/bin/sh
29
26
 
30
27
  apt-get update
31
- apt-get install -qyf ruby bundler --no-install-recommends
28
+ apt-get install -qyf ruby --no-install-recommends
29
+ gem install bundler
32
30
 
33
- bundle install --local --quiet --without development
31
+ bundle install --local --quiet
34
32
 
35
- bundle exec rake dokuwiki:install
33
+ # Runs the lib/install.rb hook
34
+ bundle exec charmkit hook install
36
35
  ```
37
36
 
38
- In other hooks call the relevant rake tasks, for example, in
39
- **hooks/config-changed**:
37
+ In other hooks call *charmkit* with the execing hook (eg. **hooks/config-changed**)
40
38
 
41
39
  ```
42
40
  #!/bin/sh
43
41
 
44
- bundle exec rake dokuwiki:config_changed
42
+ bundle exec charmkit hook config-changed
45
43
  ```
46
44
 
47
45
  Same for **hooks/upgrade-charm**
@@ -49,126 +47,80 @@ Same for **hooks/upgrade-charm**
49
47
  ```
50
48
  #!/bin/sh
51
49
 
52
- bundle exec rake dokuwiki:install
50
+ bundle exec charmkit hook upgrade-charm
53
51
  ```
54
52
 
55
53
  ## Writing Charmkit style hooks
56
54
 
57
- All Charmkit hooks will reside in a normal **Rakefile**.
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 hook 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:
58
66
 
59
67
  ### Syntax
60
68
 
61
69
  ```ruby
62
- require 'charmkit'
63
- require 'charmkit/plugins/nginx'
64
- require 'charmkit/plugins/php'
70
+ class ConfigChanged < Charmkit::Hook
71
+ use :nginx
65
72
 
66
- namespace :dokuwiki do
73
+ summon do
74
+ package [
75
+ 'php-fpm', 'php-cgi', 'php-curl', 'php-gd', 'php-json',
76
+ 'php-mcrypt', 'php-readline', 'php-mbstring', 'php-xml'
77
+ ], :update_cache
67
78
 
68
- desc "Install Dokuwiki"
69
- task :install => ["nginx:install", "php:install"] do
70
- app_path = `config-get app_path`
71
- resource_path = `resource-get stable-release`
72
79
  hook_path = ENV['JUJU_CHARM_DIR']
80
+ app_path = path(config('app_path'))
73
81
 
74
- mkdir_p app_path unless Dir.exists? app_path
82
+ mkdir app_path
75
83
 
76
- `tar xf #{resource_path} -C #{app_path} --strip-components=1`
77
- rm "#{app_path}/conf/install.php" if File.exists? "#{app_path}/conf/install.php"
78
- cp "#{hook_path}/templates/acl.auth.php", "#{app_path}/conf/acl.auth.php"
79
- cp "#{hook_path}/templates/local.php", "#{app_path}/conf/local.php"
80
- cp "#{hook_path}/templates/plugins.local.php", "#{app_path}/conf/plugin.local.php"
84
+ resource_path = path(resource('stable-release'))
85
+ run "tar xf #{resource_path} -C #{app_path} --strip-components=1"
81
86
 
82
- version = File.read "#{app_path}/VERSION"
83
- `application-version-set '#{version}'`
84
- `status-set active Dokuwiki Install finished.`
87
+ rm app_path/"conf/install.php"
88
+ status :active, "Dokuwiki configuration updated."
85
89
  end
86
90
 
87
- desc "Configure Dokuwiki"
88
- task :config_changed do
89
- app_path = `config-get app_path`
90
- hook_path = ENV['JUJU_CHARM_DIR']
91
-
92
- admin_user = `config-get #{admin_user}`
93
- admin_password = `config-get admin_password`
94
- admin_name = `config-get admin_name`
95
- admin_email = `config-get admin_email`
96
- template "#{hook_path}/templates/users.auth.php",
97
- "#{app_path}/conf/users.auth.php",
98
- admin_user: admin_user,
99
- admin_password: admin_password,
100
- admin_name: admin_name,
101
- admin_email: admin_email
102
-
103
- template "#{hook_path}/templates/vhost.conf",
104
- "/etc/nginx/sites-enabled/default",
105
- public_address: unit('public-address'),
106
- app_path: app_path
107
-
108
- chown_R 'www-data', 'www-data', app_path
109
-
110
- # TODO: service :restart, "nginx"
111
- # TODO: service :restart, "php7.0-fpm"
112
- `systemctl restart php7.0-fpm`
113
- `systemctl restart nginx`
114
- `status-set active Ready`
91
+ test do
92
+ cmd.test '-e /etc/passwd'
115
93
  end
116
94
  end
117
95
  ```
118
96
 
119
- The core of Charmkit contains a few helpers such as template rendering but
120
- otherwise kept relatively small.
121
-
122
- **Charmkit** does have a sense of "plugins" which are really **rake** tasks that
123
- reside in *charmkit/plugin/{name}* as seen in the example syntax above.
97
+ The core of Charmkit is relatively small and everything is handled through
98
+ scrolls (read
99
+ plugins). [Visit Charmkit Scrolls](https://github.com/charmkit/charmkit-scrolls)
100
+ for more information.
124
101
 
125
- ## Using local plugins
126
102
 
127
- In addition to the plugins(read: rake tasks) you can add your own to the charm
128
- itself. To add a task either create a directory inside your charm (eg.
129
- **tasks**) and name the file something relvant. For example, to create a plugin
130
- that will install **vim** you would do the following inside your charm directory:
131
-
132
- Create a file **tasks/vim.rb** with the below syntax:
103
+ ## Packaging the Charm
133
104
 
134
- ```ruby
135
- namespace :vim do
136
- desc "install vim"
137
- task :install do
138
- system("apt-get install -qyf vim")
139
- end
140
- end
141
105
  ```
142
-
143
- And in your **Rakefile** include it in using the **require_relative** syntax:
144
-
145
- ```ruby
146
- require 'charmkit'
147
- require_relative 'tasks/vim'
106
+ $ bundle exec charmkit build
148
107
  ```
149
108
 
150
- Now you can install **vim** with the rake command or utilize the tasks inside
151
- your **Rakefile**:
109
+ This will package and cache all required gems, along with making sure the necessary
110
+ scrolls are included. The output will be a charm that you can deploy via:
152
111
 
153
112
  ```
154
- bundle exec rake vim:install
113
+ $ juju deploy dist/.
155
114
  ```
156
115
 
157
- ## Packaging the Charm
158
-
159
- You'll want to make sure that any Ruby gems used are packaged with your charm so
160
- that you aren't forcing users to try to download those dependencies during
161
- deployment.
116
+ ## Uploading to charm store
162
117
 
163
- Easiest way to package your deps is:
118
+ Once the charm is built simply run:
164
119
 
165
120
  ```
166
- $ bundle package
121
+ $ charm push dist/.
167
122
  ```
168
123
 
169
- This will place your deps inside `vendor/cache` which will be uploaded when
170
- executing a `charm push .`
171
-
172
124
  ## Development
173
125
 
174
126
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
data/charmkit.gemspec CHANGED
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'charmkit/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "charmkit"
8
- spec.version = Charmkit.version
7
+ spec.version = "1.0.0"
9
8
  spec.authors = ["Adam Stokes"]
10
9
  spec.email = ["battlemidget@users.noreply.github.com"]
11
10
 
@@ -21,9 +20,10 @@ Gem::Specification.new do |spec|
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ["lib"]
23
22
 
24
- spec.add_dependency "tty-command"
23
+ spec.add_dependency "tty-command", "~> 0.2.0"
25
24
  spec.add_dependency "activesupport"
26
25
  spec.add_dependency "thor"
26
+ spec.add_dependency "rake"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.13"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,66 @@
1
+ # -*- mode:ruby -*-
2
+
3
+ depends_on "nginx-full"
4
+ depends_on "php-fpm"
5
+ depends_on "php-cgi"
6
+ depends_on "php-curl"
7
+ depends_on "php-gd"
8
+ depends_on "php-json"
9
+ depends_on "php-mcrypt"
10
+ depends_on "php-readline"
11
+ depends_on "php-mbstring"
12
+ depends_on "php-xml"
13
+
14
+ hook "install" do
15
+ release = "#{config['release']}-release"
16
+ app_path = config 'app_path'
17
+ hook_path = ENV['JUJU_CHARM_DIR']
18
+ run "tar xf #{resource[release]} -C #{app_path} --strip-components=1"
19
+ rm "#{app_path}/conf/install.php" if is_file? "#{app_path}/conf/install.php"
20
+ cp "#{hook_path}/templates/acl.auth.php", "#{app_path}/conf/acl.auth.php"
21
+ cp "#{hook_path}/templates/local.php", "#{app_path}/conf/local.php"
22
+ cp "#{hook_path}/templates/plugins.local.php", "#{app_path}/conf/plugin.local.php"
23
+ file "/etc/dokuwiki-release", content: release
24
+ case release
25
+ when "stable"
26
+ version = cat "#{app_path}/VERSION"
27
+ run "application-version-set '#{version}'"
28
+ when "development"
29
+ t = Time.now
30
+ version = t.strftime "%Y-%m-%d"
31
+ run "application-version-set 'development-#{version}'"
32
+ else
33
+ status :blocked, "Unable to set proper application version"
34
+ exit 1
35
+ end
36
+ end
37
+
38
+ hook "config-changed" do
39
+ app_path = config 'app_path'
40
+ hook_path = ENV['JUJU_CHARM_DIR']
41
+ installed_release = cat "/etc/dokuwiki-release"
42
+ release = config 'release'
43
+ if !installed_release.eql? release
44
+ run './hooks/install'
45
+ end
46
+
47
+ admin_user = config 'admin_user'
48
+ admin_password = config 'admin_password'
49
+ admin_name = config 'admin_name'
50
+ admin_email = config 'admin_email'
51
+ template "#{hook_path}/templates/users.auth.php",
52
+ "#{app_path}/conf/users.auth.php",
53
+ admin_user: admin_user,
54
+ admin_password: admin_password,
55
+ admin_name: admin_name,
56
+ admin_email: admin_email
57
+
58
+ template "#{hook_path}/templates/vhost.conf",
59
+ "/etc/nginx/sites-enabled/default",
60
+ public_address: unit['public-address'],
61
+ app_path: app_path
62
+
63
+ chown_R 'www-data', 'www-data', app_path
64
+ run "systemctl restart nginx"
65
+ status :active, "Ready"
66
+ end
data/examples/basic.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative './plugin_loader'
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'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "charmkit", :github => "charmkit/charmkit"
5
+ gem "rake"
6
+ gem "rspec"
7
+
8
+ # If you wish to load additional scrolls add those here
9
+ gem "charmkit-scroll-nginx", :github => "charmkit/charmkit-scrolls-nginx"
10
+
@@ -0,0 +1,64 @@
1
+ GIT
2
+ remote: git://github.com/charmkit/charmkit-scrolls-nginx.git
3
+ revision: d0a7493d4832de2588a136afb8b312569b8a1158
4
+ specs:
5
+ charmkit-scroll-nginx (0.2.0)
6
+
7
+ GIT
8
+ remote: git://github.com/charmkit/charmkit.git
9
+ revision: 9dc6a1acb34c8c0bf63977e68b5c60ab74242b87
10
+ specs:
11
+ charmkit (1.0.2)
12
+ activesupport
13
+ thor
14
+ tty-command (~> 0.2.0)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ activesupport (5.0.1)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (~> 0.7)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ concurrent-ruby (1.0.4)
25
+ diff-lcs (1.3)
26
+ equatable (0.5.0)
27
+ i18n (0.7.0)
28
+ minitest (5.10.1)
29
+ pastel (0.6.1)
30
+ equatable (~> 0.5.0)
31
+ tty-color (~> 0.3.0)
32
+ rake (12.0.0)
33
+ rspec (3.5.0)
34
+ rspec-core (~> 3.5.0)
35
+ rspec-expectations (~> 3.5.0)
36
+ rspec-mocks (~> 3.5.0)
37
+ rspec-core (3.5.4)
38
+ rspec-support (~> 3.5.0)
39
+ rspec-expectations (3.5.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-mocks (3.5.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.5.0)
45
+ rspec-support (3.5.0)
46
+ thor (0.19.4)
47
+ thread_safe (0.3.5)
48
+ tty-color (0.3.0)
49
+ tty-command (0.2.0)
50
+ pastel (~> 0.6.0)
51
+ tzinfo (1.2.2)
52
+ thread_safe (~> 0.1)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ charmkit!
59
+ charmkit-scroll-nginx!
60
+ rake
61
+ rspec
62
+
63
+ BUNDLED WITH
64
+ 1.13.7
@@ -0,0 +1,27 @@
1
+ # Overview
2
+
3
+ My charm Overview
4
+
5
+ # Usage
6
+
7
+ $ juju deploy demo
8
+
9
+ # Developers
10
+
11
+ How developers can contribute
12
+
13
+ # Maintainers
14
+
15
+ How QA and others can test your charm
16
+
17
+ # Author
18
+
19
+ Your name <mememe@email.com>
20
+
21
+ # Copyright
22
+
23
+ 2016 Your name
24
+
25
+ # License
26
+
27
+ MIT
@@ -0,0 +1,9 @@
1
+ require 'charmkit'
2
+
3
+ desc "Install hook"
4
+ task :install do
5
+ use :nginx
6
+ nginx.add_host "test", :php
7
+ deps.install
8
+ end
9
+
@@ -0,0 +1,2 @@
1
+ options: {}
2
+
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ bundle exec rake config_changed
3
+
@@ -1,8 +1,6 @@
1
1
  #!/bin/sh
2
-
3
2
  apt-get update && apt-get install -qyf ruby bundler --no-install-recommends
4
-
5
- bundle install --local --quiet
6
-
3
+ bundle install --local --quiet --without development
7
4
  # Do install task
8
- bundle exec rake dokuwiki:install
5
+ bundle exec rake install
6
+