├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── cmd └── hap │ ├── cli │ ├── build.go │ ├── c.go │ ├── commands.go │ ├── create.go │ ├── deploy.go │ ├── exec.go │ └── push.go │ ├── logger.go │ └── main.go ├── git.go ├── git_test.go ├── hapfile.go ├── hapfile_test.go ├── remote.go ├── remote_test.go ├── ssh.go └── ssh_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | .DS_Store 27 | bin 28 | pkg 29 | 30 | *.swp 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ======================= 3 | All attempts to improve this software are greatly appreciated. 4 | 5 | Discussions 6 | ----------- 7 | Open an issue. 8 | 9 | Standards 10 | --------- 11 | Follow the rules of `gofmt`. A pre-commit hook is highly recommended. 12 | 13 | Develop 14 | ------------- 15 | 1. Fork. 16 | 2. Write tests. 17 | 3. Write code. 18 | 4. Submit Pull Requests. 19 | 5. Repeat 2-4 20 | 21 | Disclaimer 22 | ---------- 23 | All contributions are property of their respective authors and this project. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 GWoo (https://github.com/gwoo) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Lithium, Union of Rad, nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 20 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Hap - the simple and effective provisioner 2 | # Copyright (c) 2019 GWoo (https://github.com/gwoo) 3 | 4 | .PHONY: bin/hap bin/hap-linux-amd64 bin/hap-darwin-amd64 test 5 | VERSION := $(shell git describe --always --dirty --tags) 6 | VERSION_FLAGS := -ldflags "-X main.Version=$(VERSION)" 7 | 8 | bin/hap: bin 9 | go build -v $(VERSION_FLAGS) -o $@ ./cmd/hap 10 | 11 | bin/hap-linux-amd64: bin 12 | GOOS=linux GOARCH=amd64 go build -v $(VERSION_FLAGS) -o $@ ./cmd/hap 13 | 14 | bin/hap-darwin-amd64: bin 15 | GOOS=darwin GOARCH=amd64 go build -v $(VERSION_FLAGS) -o $@ ./cmd/hap 16 | 17 | test: 18 | go test -v ./... 19 | 20 | bin: 21 | mkdir bin -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hap - A simple and effective provisioner. 2 | 3 | Hap helps manage build scripts with git and run them concurrently on multiple remote hosts using composable blocks. 4 | 5 | First, `hap create` to setup a new local repo. Then add hosts to the generated Hapfile. Once hosts are in place, run `hap build` to 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 or use the `--force` param. 6 | 7 | To run arbitrary commands use `hap c`, and to execute individual scripts with `hap exec`. 8 | `hap c` will not push the latest or run from the current directory or use the environment files, those must be added as part of the command. 9 | `hap exec` will push the latest, use the current directory and the environment. 10 | 11 | If you only have one host, just use the `default` section. Then the `-h,--host` flag while running `hap` is not necessary. 12 | 13 | Make sure every build script is executable before committing to the local repo. 14 | 15 | ## Installation 16 | 17 | #### via Go 18 | 19 | go get -u github.com/gwoo/hap/cmd/hap 20 | 21 | #### Binaries 22 | 23 | darwin/amd64 24 | 25 | curl -L -C - -o /usr/local/bin/hap https://github.com/gwoo/hap/releases/download/v2.6/hap-darwin-amd64; chmod a+x /usr/local/bin/hap 26 | 27 | linux/amd64 28 | 29 | curl -L -C - -o /usr/local/bin/hap https://github.com/gwoo/hap/releases/download/v2.6/hap-linux-amd64; chmod a+x /usr/local/bin/hap 30 | 31 | ## Basic Workflow 32 | 33 | - Run `hap create ` 34 | - Modify `Hapfile` 35 | - Run `hap -h build` 36 | 37 | ## Environment Variables 38 | 39 | Hap exports `HAP_HOSTNAME`, `HAP_USER`, `HAP_ADDR`, `HAP_IP`, `HAP_PORT` for use in scripts. You can add your own by using the `env` section or the `env` statement in the `host` section. 40 | 41 | ## Hapfile 42 | 43 | The Hapfile uses [git-config](http://git-scm.com/docs/git-config#_syntax) syntax. There are 5 sections, `default`, `host`, `build`, `include`, and `env`. 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`, `env`. 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`, `cmd`, or `env` are permitted for each host. In addition, an `include` section accepts multiple `path` statements and an `env` section accepts multiple `file` statements. 44 | 45 | ### sections 46 | 47 | - `host`: Holds the configuration for a machine 48 | - `addr`: the host:port of the remote machine 49 | - `dir`: base directory on the remote machine 50 | - `username`: the name of the user to login and run commands 51 | - `password`: password for ssh password based authentication 52 | - `identity`: path to ssh private key for key based authentication 53 | - `build`: one or more groups of commands to run 54 | - `cmd`: one or more commands to run on a specific host 55 | - `env`: one or more environment files to apply to this host (can override env sections) 56 | - `deploy`: Holds the configuration for a deploy 57 | - `host`: one or more hosts 58 | - `build`: one or more groups of commands to run 59 | - `cmd`: one or more commands to run on a specific host 60 | - `env`: one or more environment files to apply to this host (can override env sections) 61 | - `build`: sets of commands to run 62 | - `cmd`: one or more commands to run 63 | - `default` : Holds the standard configurations that can be applied to all hosts 64 | - 65 | - `include`: Allows other files to be included in the current configuration 66 | - `path`: a path to the Hapfile the hap 67 | - `env`: make variables available to the all commands 68 | - `file`: path to a file that can be sourced 69 | 70 | ## Example Hapfile 71 | 72 | A default build is specified, so init.sh and update.sh are executed for each host. 73 | Host `one` specifies two commands, notify.sh and cleanup.sh, to be run after the default build commands. For host `one`, the `HAP_HOSTNAME` will be `one`, the `HAP_USER` will be `root`, and the `HAP_ADDR` will be `10.0.20.10:22`. Host `two` specifies no commands, so only the default build will be applied. For host `two`, the `HAP_HOSTNAME` will be `two`, the `HAP_USER` will be `admin`, and the `HAP_ADDR` will be `10.0.20.11:22`. There is also a `deploy` that will return the hostname for `one` and `two`. 74 | 75 | [default] 76 | username = "root" 77 | identity = "~/.ssh/id_rsa" 78 | build = "initialize" ; applied to all hosts 79 | 80 | [host "one"] 81 | addr = "10.0.20.10:22" 82 | cmd = "./notify.sh" 83 | cmd = "./cleanup.sh" 84 | 85 | [host "two"] 86 | username = "admin" 87 | identity = "~/.ssh/admin_rsa" 88 | addr = "10.0.20.11:22" 89 | 90 | [deploy "get-hostname"] 91 | host = one 92 | host = two 93 | cmd = hostname 94 | 95 | [build "initialize"] 96 | cmd = ./init.sh 97 | cmd = ./update.sh 98 | cmd = echo "initialized" 99 | 100 | ## Usage 101 | 102 | Usage of ./bin/hap: 103 | --dry=false: Show commands without running them. 104 | -f, --file="Hapfile": Location of a Hapfile. 105 | --force=false: Force build even if it happened before. 106 | --help=false: Show help 107 | -h, --host="": Host to use for commands. Use glob patterns to match multiple hosts. Use --host=* for all hosts. 108 | -v, --verbose=false: [deprecated] Verbose mode is always on 109 | 110 | Available Commands: 111 | hap build Run the builds and commands from the Hapfile. 112 | hap c Run an arbitrary command on the remote host. 113 | hap create Create a new Hapfile at . 114 | hap deploy Run the named deploy defined in the Hapfile. 115 | hap exec