NAME

App::CharmKit::Manual::GettingStarted - Getting started with CharmKit

VERSION

version 0.20

Getting Started

Creating a project

All development happens within src/ and the builtin pack command is used for generating the proper hooks/tests and dependencies within that directory so Juju is able to act upon them. Hooks within hooks/ directory are always overwritten, think of this similar to a dist or release directory.

To start a project:

$ charmkit init [--with-hooks] <charm-name>

If used --with-hooks then src/hooks/ will be populated with all the default hooks. A few questions will be prompted and then the project is generated with charmkit.json, config.yaml, metadata.yaml, LICENSE, README.md, and Makefile.

Directory Layout

Once a project is created the structure of your project should look similar to:

charm-project/
  hooks/
    install
    config-changed
    start
    stop
  src/
    hooks/
      install
      config-changed
      start
      stop
    tests/
      00-basic.test
  tests/
    00-basic.test
  config.yaml
  metadata.yaml
  LICENSE
  README.md
  charmkit.json
  Makefile

Creating hooks

By default CharmKit allows the creation of a set of default unit hooks. Those hooks are install, config-changed, start, upgrade-charm, stop.

$ charmkit generate upgrade-charm

Or you can generate all known default unit hooks:

$ charmkit generate -a

A special relation hook can be created with the -r option:

$ charmkit generate -r database-relation-joined

Writing charm hooks

Hooks are written using perl with automatically imported helpers for convenience. When developing hooks they should reside in src/hooks.

A typical hook starts with

#!/usr/bin/env perl

use charm;

log 'Starting install hook for database';

apt_install(['mysql-server', 'nginx', 'php5-fpm'])

my $dbhost = relation_get 'dbhost';
my $dbuser = relation_get 'dbuser';

service_control('nginx', 'restart');

Writing charm tests

Tests are written in the same way and should live in src/tests/*.test.

A typical test starts with

#!/usr/bin/env perl

use charm -tester;

# See if an nginx config file exists
ok (-e '/etc/nginx/sites-enabled/mysite.com', 'found nginx site config');

my $ret = service_status('nginx');
ok ($ret->{error} eq 0, 'nginx is running);

# finish tests
done_testing;

Tests are built in a way that the test runner from the charm reviewers will be able to run and validate your charm. The tests can be executed calling them directly (how the test runner does it) or running with:

$ charmkit test

or

$ prove -lv tests/*.test

Packaging a charm for release

Once development is complete and you have your hooks defined and tests written. Packaging a charm for release to either Git or the Charm Store is a matter of running:

$ charmkit pack

Getting external charms

CharmKit currently supports git endpoints and GitHub syntax username/repo

$ charmkit clone battlemidget/test-charm -o ~/charms/trusty/test-charm

Deploying a charm

$ charmkit deploy test-charm -c ~/charms

The syntax above will allow Juju to find the local charm and which series it belongs too. A requirement of Juju is to have a proper directory structure in the format of charms/<series/<charmname>, where series could be any Distribution release your charm supports, (eg. trusty, precise).

AUTHOR

Adam Stokes <adamjs@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Adam Stokes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.