Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • v0.1.0
  • v0.2.0
  • v0.3.0
  • v0.4.0
  • v0.5.0
  • v0.5.1
  • v0.5.2
8 results

Target

Select target project
  • nimrod/pre-commit-hooks
1 result
Select Git revision
  • main
  • v0.1.0
  • v0.2.0
  • v0.3.0
  • v0.4.0
  • v0.5.0
  • v0.5.1
  • v0.5.2
8 results
Show changes
Commits on Source (3)
--- ---
include: include:
- project: shore/ci-templates - project: shore/ci-stuff
file: templates/pre-commit.yml file: templates/pre-commit.yml
pre-commit-try-repo: pre-commit-try-repo:
...@@ -21,7 +21,7 @@ pre-commit-try-repo: ...@@ -21,7 +21,7 @@ pre-commit-try-repo:
/etc/apt/sources.list.d/hashicorp.list /etc/apt/sources.list.d/hashicorp.list
# yamllint enable rule:line-length # yamllint enable rule:line-length
- apt-get update - apt-get update
- apt-get install -y terraform - apt-get install -y terraform packer
script: script:
- pre-commit try-repo --all-files ./ - pre-commit try-repo --all-files ./
cache: cache:
......
...@@ -57,7 +57,7 @@ repos: ...@@ -57,7 +57,7 @@ repos:
--line-length=79 --line-length=79
- repo: https://github.com/PyCQA/prospector.git - repo: https://github.com/PyCQA/prospector.git
rev: 1.5.1b0 rev: 1.5.3
hooks: hooks:
- id: prospector - id: prospector
args: args:
......
...@@ -37,6 +37,27 @@ ...@@ -37,6 +37,27 @@
types: [terraform] types: [terraform]
entry: terraform-validate entry: terraform-validate
- id: packer-fix
name: Fix Packer templates
description: Fix known backwards incompatibilities in Packer templates
language: python
entry: packer-fix
types: [json, hcl]
- id: packer-fmt
name: Format Packer templates
description: Rewrites all Packer configuration files to a canonical format
language: python
entry: packer-fmt
types: [hcl]
- id: packer-validate
name: Validate Packer templates
description: Checks that the Packer template is valid
language: python
entry: packer-validate
types: [json, hcl]
- id: poetry-check - id: poetry-check
name: poetry check name: poetry check
description: Validate pyproject.toml files using Poetry description: Validate pyproject.toml files using Poetry
......
...@@ -22,6 +22,9 @@ A collection of [pre-commit](https://pre-commit.com/) hooks. ...@@ -22,6 +22,9 @@ A collection of [pre-commit](https://pre-commit.com/) hooks.
- id: docker-compose - id: docker-compose
- id: terraform-fmt - id: terraform-fmt
- id: terraform-validate - id: terraform-validate
- id: packer-fmt
- id: packer-fix
- id: packer-validate
- id: poetry-check - id: poetry-check
- id: branch-merge-conflict - id: branch-merge-conflict
``` ```
...@@ -50,6 +53,18 @@ Requires an installed `terraform`. ...@@ -50,6 +53,18 @@ Requires an installed `terraform`.
Validate Terraform modules using `terraform validate`. Validate Terraform modules using `terraform validate`.
Requires an installed `terraform`. Requires an installed `terraform`.
### `packer-fix`
Fix known backwards incompatibilities in Packer templates.
### `packer-fmt`
Rewrites all Packer configuration files to a canonical format (just HCL files).
### `packer-validate`
Checks that the Packer template is valid.
### `poetry-check` ### `poetry-check`
Validate `pyproject.toml` files using Poetry. Validate `pyproject.toml` files using Poetry.
......
"""Fix known backwards incompatibilities in Packer templates."""
import argparse
import locale
import pathlib
import sys
import hooks.utils
def packer_fix(file):
"""Runs packer fix.
If the invocation succeeds, overwrite the file with the fixed output from
packer. If it fails, fail.
"""
proc = hooks.utils.run(["packer", "fix", file])
if proc.returncode > 0:
return 1
# pylint: disable=invalid-name
with open(file, "w", encoding=locale.getpreferredencoding()) as fh:
fh.write(proc.stdout)
return 0
def main():
"""Main entrypoint."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", nargs="+", type=pathlib.Path)
args = parser.parse_args()
hooks.utils.check_executable("packer")
return hooks.utils.bulk_check(
packer_fix,
args.file,
)
if __name__ == "__main__":
sys.exit(main())
"""Rewrites all Packer configuration files to a canonical format."""
import argparse
import pathlib
import sys
import hooks.utils
def main():
"""Main entrypoint."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", nargs="+", type=pathlib.Path)
args = parser.parse_args()
hooks.utils.check_executable("packer")
return hooks.utils.bulk_check(
lambda x: hooks.utils.check_file(["packer", "fmt", "-diff", x]),
args.file,
)
if __name__ == "__main__":
sys.exit(main())
"""Checks that the Packer template is valid."""
import argparse
import pathlib
import sys
import hooks.utils
def main():
"""Main entrypoint."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", nargs="+", type=pathlib.Path)
args = parser.parse_args()
hooks.utils.check_executable("packer")
return hooks.utils.bulk_check(
lambda x: hooks.utils.check_file(["packer", "validate", x]),
args.file,
)
if __name__ == "__main__":
sys.exit(main())
...@@ -19,6 +19,9 @@ setup( ...@@ -19,6 +19,9 @@ setup(
"docker-compose-validate=hooks.docker_compose_validate:main", "docker-compose-validate=hooks.docker_compose_validate:main",
"terraform-validate=hooks.terraform_validate:main", "terraform-validate=hooks.terraform_validate:main",
"terraform-fmt=hooks.terraform_fmt:main", "terraform-fmt=hooks.terraform_fmt:main",
"packer-fix=hooks.packer_fix:main",
"packer-fmt=hooks.packer_fmt:main",
"packer-validate=hooks.packer_validate:main",
"poetry-check=hooks.poetry_check:main", "poetry-check=hooks.poetry_check:main",
] ]
}, },
......
{
"variables": {
"access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
"secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}"
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `access_key`}}",
"secret_key": "{{user `access_key`}}",
"region": "us-east-1",
"source_ami": "ami-de0d9eb7",
"instance_type": "t1.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}"
}]
}
build {
name = "alpine"
description = <<EOF
This build creates alpine images for versions :
* v3.12
For the following builders :
* virtualbox-iso
EOF
// the common fields of the source blocks are defined in the
// source.builder-type.pkr.hcl files, here we only set the fields specific to
// the different versions of ubuntu.
source "source.virtualbox-iso.base-alpine-amd64" {
name = "3.12"
iso_url = local.iso_url_alpine_312
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
output_directory = "virtualbox_iso_alpine_312_amd64"
boot_command = local.alpine_312_floppy_boot_command
boot_wait = "10s"
}
source "source.vsphere-iso.base-alpine-amd64" {
name = "3.12"
vm_name = "alpine-3.12"
iso_url = local.iso_url_alpine_312
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
boot_command = local.alpine_312_floppy_boot_command_vsphere
boot_wait = "10s"
}
source "source.vmware-iso.esxi-base-alpine-amd64" {
name = "3.12-from-esxi"
iso_url = local.iso_url_alpine_312
iso_checksum = "file:${local.iso_checksum_url_alpine_312}"
boot_command = local.alpine_312_floppy_boot_command_vsphere
}
provisioner "shell" {
inline = ["echo hi"]
}
}