hap

package module
v0.0.0-...-46dc964 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2015 License: BSD-3-Clause Imports: 16 Imported by: 0

README

Hap - A simple and effective provisioner.

Hap helps manage build scripts with git and run them concurrently on multiple remote hosts using composable blocks.

First, hap create to setup a new local repo. Then add hosts to the generated Hapfile.Once hosts are in place, hap init will setup the remote hosts. Finally, hap build will execute the build blocks and commands specified in the Hapfile for each host. After hap build a .happened file is saved with the current sha of remote repo. To run hap build again a new commit is required.

Tun arbitrary commands use hap c, and to execute individual scripts with hap exec.

If you only have one host, just use the default section. Then the -all or -host flag while running hap is not necessary.

Make sure every build script is executable before committing to the local repo.

Installation

via Go
go get github.com/gwoo/hap/cmd/hap
Binaries

darwin/amd64

curl -L -C - -O https://github.com/gwoo/hap/releases/download/v1.4/hap-darwin-amd64; chmod a+x hap-darwin-amd64

linux/amd64

curl -L -C - -O https://github.com/gwoo/hap/releases/download/v1.4/hap-linux-amd64; chmod a+x hap-linux-amd64

Basic Workflow

  • Run hap create <name>
  • Modify Hapfile
  • Run hap init and hap build

Environment Variables

Hap exports HAP_HOSTNAME, HAP_USER, HAP_ADDR for use in scripts.

Hapfile

The Hapfile uses git-config syntax. There are 3 sections, default, host, and build. The default section holds host config that will be applied to all hosts. The host section holds a named host config. A host config includes addr, username, password, identity, build, and cmd. Only addr is required. The identity should point to a local ssh private key that has access to the host via the authorized_keys. The build section holds mulitple cmds that could be applied to a host. Multiple build and cmd are permitted for each host.

Example Hapfile

A default build is specified, so init.sh and update.sh are executed for each host. Host one specifies two commands, notify.sh and cleanup.sh, to be run after the default build commands.

[default]
username = "root"
identity = "~/.ssh/id_rsa"
build = "default" ; applied to all hosts

[host "one"]
addr = "10.0.20.10:22"
cmd = "./notify.sh"
cmd = "./cleanup.sh"

[host "two"]
addr = "10.0.20.11:22"

[build "default"]
cmd = ./init.sh
cmd = ./update.sh

Usage

Usage of hap:
  -all=false: Use ALL the hosts.
  -host="": Individual host to use for commands.
  -v=false: Verbose flag to print command log.

Available Commands:
hap build			Run the builds and commands from the Hapfile.
hap c <command>		Run an arbitrary command on the remote host.
hap create <name>	Create a new Hapfile at <name>.
hap exec <script>	Execute a script on the remote host.
hap init			Initialize a new remote host.
hap push			Push current repo to the remote.

License

The BSD License http://opensource.org/licenses/bsd-license.php.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientConfig

func NewClientConfig(config SshConfig) (*ssh.ClientConfig, error)

Construct a new client config

func NewKey

func NewKey(key string) (interface{}, error)

Parse and return the interface for the key type (rsa, dss, etc)

func NewKeyFile

func NewKeyFile(key string) (string, error)

Get the data in the key file

func NewRemoteWriter

func NewRemoteWriter(host string, w io.Writer) io.Writer

Writer with [host] prepended to output

func NewSigner

func NewSigner(key string) (ssh.Signer, error)

Create a new signer

Types

type Build

type Build struct {
	Cmd []string
}

type Default

type Default Host

The default settings

type Git

type Git struct {
	Repo string
	Work string
}

Git struct

func (Git) Commit

func (g Git) Commit(message string) ([]byte, error)

Add and Commit all files, including untracked to the repo

func (Git) Exists

func (g Git) Exists() error

Check whether the git executable exists

func (Git) Push

func (g Git) Push(branch string) ([]byte, error)

Force push to the remote repo

type Hapfile

type Hapfile struct {
	Default Default
	Hosts   map[string]*Host  `gcfg:"host"`
	Builds  map[string]*Build `gcfg:"build"`
}

The Hapfile

func NewHapfile

func NewHapfile() (Hapfile, error)

Construct a new hapfile config

func (Hapfile) GetHosts

func (h Hapfile) GetHosts(name string, all bool) map[string]*Host

Get list of hosts

func (Hapfile) Host

func (h Hapfile) Host(name string) *Host

Get a host based on the name If the name is empty, and if default addr exists, return default otherwise return a random host

func (Hapfile) String

func (h Hapfile) String() string

Return the hapfile config as json

type Host

type Host struct {
	Name     string
	Addr     string
	Username string
	Identity string
	Password string
	Build    []string
	Cmd      []string
	// contains filtered or unexported fields
}

A remote machine

func (*Host) BuildCmds

func (h *Host) BuildCmds(builds map[string]*Build)

Combine the builds and cmds

func (*Host) Cmds

func (h *Host) Cmds() []string

Get the cmds to build

func (*Host) SetDefaults

func (h *Host) SetDefaults(d Default)

Use the defaults to fill in missing host specific config

type Remote

type Remote struct {
	Git  Git
	Dir  string
	Host *Host
	// contains filtered or unexported fields
}

The remote machine to provision

func NewRemote

func NewRemote(host *Host) (*Remote, error)

Construct a new remote machine

func (*Remote) Build

func (r *Remote) Build() error

Execute the builds and cmds First execute builds specified in Hapfile Then execute any cmds specified in Hapfile

func (*Remote) Close

func (r *Remote) Close() error

End session with remote machine

func (*Remote) Connect

func (r *Remote) Connect() error

Start ssh session to remote machine.

func (*Remote) Env

func (r *Remote) Env() string

Return preset environment variables to pass to execute

func (*Remote) Execute

func (r *Remote) Execute(commands []string) error

Shell out to the multiple commands or run one

func (*Remote) Initialize

func (r *Remote) Initialize() error

Setup a git repo on the remote machine

func (*Remote) Push

func (r *Remote) Push() error

Update repo on the remote machine

func (*Remote) PushSubmodules

func (r *Remote) PushSubmodules() error

Initialize and Push submodules into proper location on remote

type RemoteWriter

type RemoteWriter struct {
	// contains filtered or unexported fields
}

Writer with host and io.Writer

func (*RemoteWriter) Write

func (hw *RemoteWriter) Write(p []byte) (int, error)

Implement io.Writer interface

type SshConfig

type SshConfig struct {
	Addr         string
	Username     string
	Identity     string
	Password     string
	ClientConfig *ssh.ClientConfig
}

Config necessary for ssh connections

Directories

Path Synopsis
cmd
hap command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL