Skip to content
GitLab
Explore
Sign in
Register
nimrod
pre-commit-hooks
Compare revisions
305a075e515afe7ba9e4e8d966326fc3d5040b7c to 2f72a9780bc1d1c0afee0ff857e77bea8d6116b0
Commits on Source (3)
fixup! Packer hooks.
· b4a1f804
nimrod
authored
Dec 06, 2021
b4a1f804
fixup! Packer hooks.
· 1d2851f1
nimrod
authored
Dec 06, 2021
1d2851f1
fixup! Packer hooks.
· 2f72a978
nimrod
authored
Dec 06, 2021
2f72a978
Hide whitespace changes
Inline
Side-by-side
.pre-commit-config.yaml
View file @
2f72a978
...
...
@@ -10,7 +10,7 @@ repos:
-
id
:
check-yaml
-
id
:
detect-private-key
-
id
:
end-of-file-fixer
exclude
:
VERSION
exclude
:
VERSION
|test_files
-
id
:
trailing-whitespace
-
repo
:
https://github.com/codespell-project/codespell.git
...
...
.pre-commit-hooks.yaml
View file @
2f72a978
...
...
@@ -42,7 +42,7 @@
description
:
Fix known backwards incompatibilities in Packer templates
language
:
python
entry
:
packer-fix
types_or
:
[
json
,
hcl
]
types_or
:
[
json
]
-
id
:
packer-fmt
name
:
Format Packer templates
...
...
README.md
View file @
2f72a978
...
...
@@ -55,7 +55,8 @@ Requires an installed `terraform`.
### `packer-fix`
Fix known backwards incompatibilities in Packer templates.
Fix known backwards incompatibilities in Packer templates (just JSON files,
until support for HCL files is added in Packer).
### `packer-fmt`
...
...
hooks/packer_validate.py
View file @
2f72a978
...
...
@@ -6,6 +6,17 @@ import sys
import
hooks.utils
def
packer_validate
(
file
):
"""
Validate a Packer template.
Run init when needed.
"""
if
str
(
file
).
endswith
(
"
.pkr.hcl
"
)
or
str
(
file
).
endswith
(
"
.pkr.json
"
):
if
hooks
.
utils
.
check_file
([
"
packer
"
,
"
init
"
,
file
])
>
0
:
return
1
return
hooks
.
utils
.
check_file
([
"
packer
"
,
"
validate
"
,
file
])
def
main
():
"""
Main entrypoint.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
...
...
@@ -13,7 +24,7 @@ def main():
args
=
parser
.
parse_args
()
hooks
.
utils
.
check_executable
(
"
packer
"
)
return
hooks
.
utils
.
bulk_check
(
lambda
x
:
hooks
.
utils
.
check_file
([
"
packer
"
,
"
validate
"
,
x
])
,
packer
_
validate
,
args
.
file
,
)
...
...
test_files/packer.json
View file @
2f72a978
{
"builders"
:
[
{
"access_key"
:
"{{user `access_key`}}"
,
"ami_name"
:
"packer-example {{timestamp}}"
,
"instance_type"
:
"t1.micro"
,
"region"
:
"us-east-1"
,
"secret_key"
:
"{{user `access_key`}}"
,
"source_ami"
:
"ami-de0d9eb7"
,
"ssh_username"
:
"ubuntu"
,
"type"
:
"amazon-ebs"
}
],
"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}}"
}]
}
}
test_files/template.pkr.hcl
View file @
2f72a978
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"
packer
{
required_plugins
{
amazon
=
{
version
=
">= 0.0.2"
source
=
"github.com/hashicorp/amazon"
}
}
}
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
source
"amazon-ebs"
"ubuntu"
{
ami_name
=
"learn-packer-linux-aws"
instance_type
=
"t2.micro"
region
=
"us-west-2"
source_ami_filter
{
filters
=
{
name
=
"ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
root-device-type
=
"ebs"
virtualization-type
=
"hvm"
}
most_recent
=
true
owners
=
[
"099720109477"
]
}
ssh_username
=
"ubuntu"
}
provisioner
"shell"
{
inline
=
[
"echo hi"
]
}
build
{
name
=
"learn-packer"
sources
=
[
"source.amazon-ebs.ubuntu"
]
}