项目作者: charmkit

项目描述 :
elegantly elegant charm authoring
高级语言: Ruby
项目地址: git://github.com/charmkit/charmkit.git
创建时间: 2016-11-28T17:22:10Z
项目社区:https://github.com/charmkit/charmkit

开源协议:MIT License

下载


Charmkit Gem Version

elegantly elegant charm authoring

Installation

Add this line to your application’s Gemfile:

  1. gem 'charmkit'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install charmkit

Usage

Define all install, configure, upgrade tasks within a normal Rakefile. The
hooks will then need to just call those tasks:

In hooks/install:

  1. #!/bin/sh
  2. apt-get update
  3. apt-get install -qyf ruby bundler --no-install-recommends
  4. bundle install --local --quiet --without development
  5. bundle exec charmkit dokuwiki install

In other hooks call the relevant rake tasks, for example, in
hooks/config-changed:

  1. #!/bin/sh
  2. bundle exec charmkit dokuwiki config-changed

Same for hooks/upgrade-charm

  1. #!/bin/sh
  2. bundle exec charmkit dokuwiki install

Writing Charmkit style hooks

TBD: Needs updating as rakefile’s are being migrated to Thor

All Charmkit hooks will reside in a normal Rakefile.

Syntax

  1. require 'charmkit'
  2. require 'charmkit/plugins/nginx'
  3. require 'charmkit/plugins/php'
  4. namespace :dokuwiki do
  5. desc "Install Dokuwiki"
  6. task :install => ["nginx:install", "php:install"] do
  7. app_path = `config-get app_path`
  8. resource_path = `resource-get stable-release`
  9. hook_path = ENV['JUJU_CHARM_DIR']
  10. mkdir_p app_path unless Dir.exists? app_path
  11. `tar xf #{resource_path} -C #{app_path} --strip-components=1`
  12. rm "#{app_path}/conf/install.php" if File.exists? "#{app_path}/conf/install.php"
  13. cp "#{hook_path}/templates/acl.auth.php", "#{app_path}/conf/acl.auth.php"
  14. cp "#{hook_path}/templates/local.php", "#{app_path}/conf/local.php"
  15. cp "#{hook_path}/templates/plugins.local.php", "#{app_path}/conf/plugin.local.php"
  16. version = File.read "#{app_path}/VERSION"
  17. `application-version-set '#{version}'`
  18. `status-set active Dokuwiki Install finished.`
  19. end
  20. desc "Configure Dokuwiki"
  21. task :config_changed do
  22. app_path = `config-get app_path`
  23. hook_path = ENV['JUJU_CHARM_DIR']
  24. admin_user = `config-get #{admin_user}`
  25. admin_password = `config-get admin_password`
  26. admin_name = `config-get admin_name`
  27. admin_email = `config-get admin_email`
  28. template "#{hook_path}/templates/users.auth.php",
  29. "#{app_path}/conf/users.auth.php",
  30. admin_user: admin_user,
  31. admin_password: admin_password,
  32. admin_name: admin_name,
  33. admin_email: admin_email
  34. template "#{hook_path}/templates/vhost.conf",
  35. "/etc/nginx/sites-enabled/default",
  36. public_address: unit('public-address'),
  37. app_path: app_path
  38. chown_R 'www-data', 'www-data', app_path
  39. # TODO: service :restart, "nginx"
  40. # TODO: service :restart, "php7.0-fpm"
  41. `systemctl restart php7.0-fpm`
  42. `systemctl restart nginx`
  43. `status-set active Ready`
  44. end
  45. end

The core of Charmkit contains a few helpers such as template rendering but
otherwise kept relatively small.

Charmkit does have a sense of “plugins” which are really rake tasks that
reside in charmkit/plugin/{name} as seen in the example syntax above.

Using local plugins

In addition to the plugins(read: rake tasks) you can add your own to the charm
itself. To add a task either create a directory inside your charm (eg.
tasks) and name the file something relvant. For example, to create a plugin
that will install vim you would do the following inside your charm directory:

Create a file tasks/vim.rb with the below syntax:

  1. namespace :vim do
  2. desc "install vim"
  3. task :install do
  4. system("apt-get install -qyf vim")
  5. end
  6. end

And in your Rakefile include it in using the require_relative syntax:

  1. require 'charmkit'
  2. require_relative 'tasks/vim'

Now you can install vim with the rake command or utilize the tasks inside
your Rakefile:

  1. bundle exec rake vim:install

Packaging the Charm

You’ll want to make sure that any Ruby gems used are packaged with your charm so
that you aren’t forcing users to try to download those dependencies during
deployment.

Easiest way to package your deps is:

  1. $ bundle package

This will place your deps inside vendor/cache which will be uploaded when
executing a charm push .

Development

After checking out the repo, run bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run bin/console for an interactive
prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To
release a new version, update the version number in version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push
git commits and tags, and push the .gem file
to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at
https://github.com/charmkit/charmkit. This project is intended to be a safe,
welcoming space for collaboration, and contributors are expected to adhere to
the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of
the MIT License.