|
| 1 | +# `pre-commit-packer` |
| 2 | + |
| 3 | +> Packer-specific hooks for use with [pre-commit](https://pre-commit.com). |
| 4 | +
|
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Requirements](#requirements) |
| 8 | +- [Dependencies](#dependencies) |
| 9 | +- [Usage](#usage) |
| 10 | + - [List of Hooks](#list-of-hooks) |
| 11 | + - [Configuring Hooks](#configuring-hooks) |
| 12 | + - [Using Docker](#using-docker) |
| 13 | +- [Notes](#notes) |
| 14 | +- [Author Information](#author-information) |
| 15 | +- [License](#license) |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +- `pre-commit` version `1.15.0` or newer |
| 20 | + |
| 21 | +## Dependencies |
| 22 | + |
| 23 | +- `packer` for hooks that are prefixed with `packer-` |
| 24 | +- `docker` for hooks that are prefixed with `docker-` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +The hooks in this repository can be used by adding the following stub to your `.pre-commit-config.yaml` file: |
| 29 | + |
| 30 | +```yaml |
| 31 | +--- |
| 32 | + - |
| 33 | + repo: https://github.com/operatehappy/pre-commit-packer |
| 34 | + rev: 1.0.0 |
| 35 | + hooks: |
| 36 | + - id: packer-validate |
| 37 | + files: packer*.json |
| 38 | + |
| 39 | + - id: packer-fix |
| 40 | + files: packer*.json |
| 41 | + |
| 42 | + - id: packer-validate-and-fix |
| 43 | + files: packer*.json |
| 44 | +``` |
| 45 | +
|
| 46 | +### List of Hooks |
| 47 | +
|
| 48 | +- `packer-validate` wraps the `validate` [command](https://packer.io/docs/commands/validate.html) to parse Packer template(s) and check template configuration against any used builders, provisioners, and processors. |
| 49 | + |
| 50 | +- `packer-fix` wraps the `fix` [command](https://packer.io/docs/commands/fix.html) and attempts to fix (known) backwards incompatibilities in Packer template(s). |
| 51 | + |
| 52 | +- `packer-validate-and-fix` wraps the `fix` [command](https://packer.io/docs/commands/fix.html) and additionally validates the fixed Packer template(s). |
| 53 | + |
| 54 | +### Configuring Hooks |
| 55 | + |
| 56 | +All hooks accept the following configuration options: |
| 57 | + |
| 58 | +- `files` accepts a string (wildcards are supported) to define which file(s) the hook should target |
| 59 | +- `args` accepts an array with one or more valid command-specific CLI arguments |
| 60 | + |
| 61 | +The `files` configuration option defaults to `packer.json` |
| 62 | + |
| 63 | +The `args` configuration option is most useful with the `packer-validate` action as it allows for passing additional arguments such as a path to a variables file (`-var-file=packer.vars.json`). The upstream documentation for the `validate` command provides an overview of all [available options](https://packer.io/docs/commands/validate.html#options). |
| 64 | + |
| 65 | +### Using Docker |
| 66 | + |
| 67 | +The hooks provided by `pre-commit-packer` support invocation through a containerized version of the Packer [Docker Image](https://hub.docker.com/r/hashicorp/packer). |
| 68 | + |
| 69 | +This invocation defaults to the `light` [tag](https://hub.docker.com/r/hashicorp/packer/tags?page=1&name=light), but is otherwise functionally identical to a direct invocation via the `packer` binary. |
| 70 | + |
| 71 | +The Docker-specific hooks are prefixed with `docker-`: |
| 72 | + |
| 73 | +- `packer-validate` becomes `docker-packer-validate` |
| 74 | +- `packer-fix` becomes `docker-packer-fix` |
| 75 | +- `packer-validate-and-fix` becomes `docker-packer-validate-and-fix` |
| 76 | + |
| 77 | +## Notes |
| 78 | + |
| 79 | +- In the [code example](#usage), the `1.0.0` version of `pre-commit-packer` has been selected. The [Releases](https://github.com/operatehappy/pre-commit-packer/releases) tab provides an overview of all available versions. |
| 80 | + |
| 81 | +## Author Information |
| 82 | + |
| 83 | +This repository is maintained by the contributors listed on [GitHub](https://github.com/operatehappy/pre-commit-packer/graphs/contributors) |
| 84 | + |
| 85 | +Development of this module was sponsored by [Operate Happy](https://github.com/operatehappy). |
| 86 | + |
| 87 | +## License |
| 88 | + |
| 89 | +Licensed under the Apache License, Version 2.0 (the "License"). |
| 90 | + |
| 91 | +You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) |
| 92 | + |
| 93 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any kind, either express or implied. |
| 94 | + |
| 95 | +See the License for the specific language governing permissions and limitations under the License. |
0 commit comments