Skip to content

Commit

Permalink
Resolved merge conflict by incorporating both suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanov1609 committed Jul 9, 2018
2 parents a43fc95 + b4741ff commit c072cc2
Show file tree
Hide file tree
Showing 26 changed files with 729 additions and 272 deletions.
22 changes: 1 addition & 21 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,4 @@ Levant is linted, tested and built using make:
make
```

The resulting binary file will be stored in the project root directory and is named `Levant-local` which can be invoked as required. The binary is built by default for the host system only. You can cross-compile and build binaries for a number of different systems and architectures by invoking the build script:

```
./scripts/build.sh
```

The build script outputs the binary files to `/pkg`:

```
darwin-386-levant
darwin-amd64-levant
freebsd-386-levant
freebsd-amd64-levant
freebsd-arm-levant
linux-386-levant
linux-amd64-levant
linux-arm-levant
```

See [docs](https://golang.org/doc/install/source) for the whole list of available `GOOS` and `GOARCH`
values.
The resulting binary file will be stored in the project root directory and is named `levant-local` which can be invoked as required. The binary is built by default for the host system only. If you wish to build for different architectures and operating systems please see the [golang docs](https://golang.org/doc/install/source) for the whole list of available `GOOS` and `GOARCH` values.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
## 0.2.0 (Unreleased)
## 0.2.1 (Unreleased)

IMPROVEMENTS:
* JSON can now be used as a variable file format [GH-210](https://github.com/jrasell/levant/pull/210)

## 0.2.0 (4 July 2018)

IMPROVEMENTS:
* New `scale-in` and `scale-out` commands allow an operator to manually scale jobs and task groups based on counts or percentages [GH-172](https://github.com/jrasell/levant/pull/172)
* New template functions allowing the lookup of variables from Consul KVs as well as ISO-8601 timestamp generation [GH-175](https://github.com/jrasell/levant/pull/175)
* New template functions allowing the lookup of variables from Consul KVs, ISO-8601 timestamp generation and loops [GH-175](https://github.com/jrasell/levant/pull/175), [GH-202](https://github.com/jrasell/levant/pull/202)
* Multiple variable files can be passed on each run, allowing for common configuration to be shared across jobs [GH-180](https://github.com/jrasell/levant/pull/180)
* Provide better command help for deploy and render commands [GH-183](https://github.com/jrasell/levant/pull/184)
* Add `-ignore-no-changes` flag to deploy CLI command which allows the changing on behaviour to exit 0 even if Levant detects 0 changes on plan [GH-196](https://github.com/jrasell/levant/pull/196)

BUG FIXES:
* Fix formatting with version summary output which had erronous quote [GH-170](https://github.com/jrasell/levant/pull/170)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM alpine:latest
LABEL maintainer James Rasell<(jamesrasell@gmail.com)> (@jrasell)
LABEL vendor "jrasell"

ENV LEVANT_VERSION 0.1.1
ENV LEVANT_VERSION 0.2.0

WORKDIR /usr/bin/

Expand Down
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ build: ## Build Levant for development purposes

test: ## Run the Levant test suite with coverage
@echo "==> Running $@..."
@go test -cover -v -tags \
"$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor)
@go test -cover -v -tags -race \
"$(BUILDTAGS)" $(shell go list ./... | grep -v vendor)

release: ## Trigger the release build script
@echo "==> Running $@..."
Expand Down
117 changes: 104 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 10 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,124 +17,31 @@ Levant is an open source templating and deployment tool for [HashiCorp Nomad](ht

* **Canary Auto Promotion**: In environments with advanced automation and alerting, automatic promotion of canary deployments may be desirable after a certain time threshold. Levant allows the user to specify a `canary-auto-promote` time period, which if reached with a healthy set of canaries, will automatically promote the deployment.

* **Multiple Variable File Formats**: Currently Levant supports `.tf`, `.yaml` and `.yml` file extensions for the declaration of template variables. *This is planned to increase in the near future.*
* **Multiple Variable File Formats**: Currently Levant supports `.json`, `.tf`, `.yaml`, and `.yml` file extensions for the declaration of template variables.

* **Auto Revert Checking**: In the event that a job deployment does not pass its healthy threshold and the job has auto-revert enabled; Levant will track the resulting rollback deployment so you can see the exact outcome of the deployment process.

## Download
## Download & Install

* The Levant binary can be downloaded from the [GitHub releases page](https://github.com/jrasell/levant/releases) using `curl -L https://github.com/jrasell/levant/releases/download/0.1.0/linux-amd64-levant -o levant`
* The Levant binary can be downloaded from the [GitHub releases page](https://github.com/jrasell/levant/releases) using `curl -L https://github.com/jrasell/levant/releases/download/0.2.0/linux-amd64-levant -o levant`

* A docker image can be found on [Docker Hub](hub.docker.com/jrasell/levant), the latest version can be downloaded using `docker pull jrasell/levant`.
* A docker image can be found on [Docker Hub](https://hub.docker.com/r/jrasell/levant/), the latest version can be downloaded using `docker pull jrasell/levant`.

* Levant can be built from source by firstly cloning the repository `git clone github.com/jrasell/levant.git`. Once cloned the binary can be built using the `make` command or invoking the `build.sh` script located in the scripts directory.

## Variable File Examples
* There is a [Levant Ansible role](https://github.com/stevenscg/ansible-role-levant) available to help installation on machines. Thanks to @stevenscg for this.

Levant currently supports `.tf`, `.yaml` and `.yml` file extensions for the declaration of template variables and uses opening and closing double squared brackets `[[ ]]` within the templated job file. This is to ensure there is no clash with existing Nomad interpolation which uses the standard `{{ }}` notation.
## Templating

Job Template:
```hcl
job "[[.job_name]]" {
datacenters = ["dc1"]
...
```

`.tf` variables file:
```hcl
variable "job_name" {
default = "jrasell-example"
}
```

`.yaml` or `.yml` variables file:
```yaml
job_name: jrasell-example
```
Levant includes functionality to perform template variables substituion as well as trigger built-in template function to add timestamps or retrive information from Consul. For full details please check out the [templates](./docs/templates.md) documentation page.

## Commands

Levant supports a number of command line arguments which provide control over the Levant binary. Levant also supports autoloading files; where if `levant [deploy,render]` is run, Levant will look in the current working directory for a `levant.[yaml,yml,tf]` file and a single `*.nomad` file to use for the command actions.

### Command: `deploy`

`deploy` is the main entry point into Levant for deploying a Nomad job and supports the following flags which should then be proceeded by the Nomad job template you which to deploy. An example deployment command would look like `levant deploy -log-level=debug example.nomad`.

* **-address** (string: "http://localhost:4646") The HTTP API endpoint for Nomad where all calls will be made.

* **-canary-auto-promote** (int: 0) The time period in seconds that Levant should wait for before attempting to promote a canary deployment.

* **-force-count** (bool: false) Use the taskgroup count from the Nomad job file instead of the count that is obtained from the running job count.

* **-force-batch** (bool: false) Forces a new instance of the periodic job. A new instance will be created even if it violates the job's prohibit_overlap settings.

* **-log-level** (string: "INFO") The level at which Levant will log to. Valid values are DEBUG, INFO, WARNING, ERROR and FATAL.

* **-log-format** (string: "HUMAN") Specify the format of Levant's logs. Valid values are HUMAN or JSON

* **-var-file** (string: "") The variables file to render the template with.

The `deploy` command also supports passing variables individually on the command line. Multiple commands can be passed in the format of `-var 'key=value'`. Variables passed via the command line take precedence over the same variable declared within a passed variable file.

Full example:

```
levant deploy -log-level=debug -address=nomad.devoops -var-file=var.yaml -var 'var=test' example.nomad
```

### Dispatch: `dispatch`

`dispatch` allows you to dispatch an instance of a Nomad parameterized job and utilise Levant's advanced job checking features to ensure the job reaches the correct running state.

* **-address** (string: "http://localhost:4646") The HTTP API endpoint for Nomad where all calls will be made.

* **-log-level** (string: "INFO") The level at which Levant will log to. Valid values are DEBUG, INFO, WARNING, ERROR and FATAL.

* **-log-format** (string: "HUMAN") Specify the format of Levant's logs. Valid values are HUMAN or JSON

* **-meta** (string: "key=vaule") The metadata key will be merged into the job's metadata. The job may define a default value for the key which is overridden when dispatching. The flag can be provided more than once to inject multiple metadata key/value pairs. Arbitrary keys are not allowed. The parameterized job must allow the key to be merged.

The command also supports the ability to send data payload to the dispatched instance. This can be provided via stdin by using "-" for the input source or by specifying a path to a file.

Full example:

```
levant dispatch -log-level=debug -address=nomad.devoops -meta key=value dispatch_job payload_item
```

### Command: `render`

`render` allows rendering of a Nomad job template without deploying, useful when testing or debugging. An example render command would look like `levant render -out job.nomad job.nomad.tpl`, options:

* **-var-file** (string: "") The variables file to render the template with.

* **-output** (string: "") The path to write the rendered template to. The template will be rendered to stdout if this is not set.

Like `deploy`, the `render` command also supports passing variables individually on the command line. Multiple vars can be passed in the format of `-var 'key=value'`. Variables passed via the command line take precedence over the same variable declared within a passed variable file.

Full example:

```
levant render -var-file=var.yaml -var 'var=test' example.nomad
```

### Command: `version`

The `version` command displays build information about the running binary, including the release version.

## Nomad Client
Levant supports a number of command line arguments which provide control over the Levant binary. For detail about each commands and its supported flags, please head over to the [commands](./docs/commands.md) documentation page.

The project uses the Nomad [Default API Client](https://github.com/hashicorp/nomad/blob/master/api/api.go#L191) which means the following Nomad client parameters used by Levant are configurable via environment variables:
## Clients

* **NOMAD_ADDR** - The address of the Nomad server.
* **NOMAD_REGION** - The region of the Nomad servers to forward commands to.
* **NOMAD_NAMESPACE** - The target namespace for queries and actions bound to a namespace.
* **NOMAD_CACERT** - Path to a PEM encoded CA cert file to use to verify the Nomad server SSL certificate.
* **NOMAD_CAPATH** - Path to a directory of PEM encoded CA cert files to verify the Nomad server SSL certificate.
* **NOMAD_CLIENT_CERT** - Path to a PEM encoded client certificate for TLS authentication to the Nomad server.
* **NOMAD_CLIENT_KEY** - Path to an unencrypted PEM encoded private key matching the client certificate from `NOMAD_CLIENT_CERT`.
* **NOMAD_SKIP_VERIFY** - Do not verify TLS certificate.
* **NOMAD_TOKEN** - The SecretID of an ACL token to use to authenticate API requests with.
Levant utilises the Nomad and Consul offical clients and configuration can be done via a number of environment variables. For detail about these please read through the [clients](./docs/clients.md) documentation page.

## Contributing

Expand Down
Loading

0 comments on commit c072cc2

Please sign in to comment.