{"id":13729222,"url":"https://github.com/abhi1693/python-packer","last_synced_at":"2025-04-10T00:33:53.488Z","repository":{"id":41904253,"uuid":"315363578","full_name":"abhi1693/python-packer","owner":"abhi1693","description":"A Python interface for packer.io","archived":false,"fork":false,"pushed_at":"2024-12-20T05:01:16.000Z","size":104,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-02T16:25:54.906Z","etag":null,"topics":["hacktoberfest","hashicorp","hashicorp-packer","packer","packer-builder","packer-images","packer-provisioner","packer-scripts","packer-template","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhi1693.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-23T15:48:09.000Z","updated_at":"2025-01-29T20:16:26.000Z","dependencies_parsed_at":"2023-02-01T19:46:17.955Z","dependency_job_id":"7acc20e1-b166-447c-8b66-8d1527790e46","html_url":"https://github.com/abhi1693/python-packer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi1693%2Fpython-packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi1693%2Fpython-packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi1693%2Fpython-packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhi1693%2Fpython-packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhi1693","download_url":"https://codeload.github.com/abhi1693/python-packer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239088383,"owners_count":19579432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","hashicorp","hashicorp-packer","packer","packer-builder","packer-images","packer-provisioner","packer-scripts","packer-template","python","python3"],"created_at":"2024-08-03T02:00:57.048Z","updated_at":"2025-02-16T04:33:20.279Z","avatar_url":"https://github.com/abhi1693.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["Custom Provisioners"],"readme":"python-packer\n=============\n\nA Python interface for [packer.io](http://www.packer.io)\n\n## Compatibility\n\n| Python Packer Release | Packer Release |\n| --------------------- | -------------- |\n| v1.0.0                | v1.7.4         |\n| v1.0.1                | v1.7.4         |\n| v1.0.2                | v1.7.4         |\n| v1.0.3                | v1.7.4         |\n| v1.0.4                | v1.7.4         |\n| v1.0.5                | v1.7.4         |\n| v1.0.6                | v1.7.4         |\n\n## Installation\n\nYou must have Packer installed prior to using this client though as installer class is provided to install packer for you.\n\n```shell\npip install git+https://github.com/abhi1693/python-packer@main\n```\n\n## Usage Examples\n\n### [Packer.build()](https://www.packer.io/docs/command-line/build.html)\n\n```python\nimport packer\n\ntemplate = 'path/to/template'\nexc = []\nonly = ['my_first_image', 'my_second_image']\nvars = {\"variable1\": \"value1\", \"variable2\": \"value2\"}\nvar_file = 'path/to/var/file'\npacker_exec_path = '/usr/bin/packer'\n\np = packer.Packer(template=template, exc=exc, only=only, vars=vars,\n                  var_file=var_file, exec_path=packer_exec_path)\np.build(parallel=True, debug=False, force=False)\n```\n\n\n### [Packer.fix()](https://www.packer.io/docs/command-line/fix.html)\n\n```python\n...\n\np = packer.Packer(template, ...)\noutput_file = '/tmp/template_fixed.json'\nprint(p.fix(output_file))\n```\n\nThe `output_file` parameter will write the output of the `fix` function to a file.\n\n\n### [Packer.inspect()](https://www.packer.io/docs/command-line/inspect.html)\n\nA `-machine-readable` (mrf) argument is provided.\n\nIf the `mrf` argument is set to `True`, the output will be parsed and an object containing the parsed output will be exposed as a dictionary containing the components:\n\n```python\nimport packer\n\np = packer.Packer(template, ...)\nresult = p.inspect(mrf=True)\nprint(result.parsed_output)\n# print(result.stdout) can also be used here\n```\n\n```json\n\"variables\": [\n  {\n    \"name\": \"aws_access_key\",\n    \"value\": \"{{env `AWS_ACCESS_KEY_ID`}}\"\n  },\n  {\n    \"name\": \"aws_secret_key\",\n    \"value\": \"{{env `AWS_ACCESS_KEY`}}\"\n  }\n],\n\"provisioners\": [\n  {\n    \"type\": \"shell\"\n  }\n],\n\"builders\": [\n  {\n    \"type\": \"amazon-ebs\",\n    \"name\": \"amazon\"\n  }\n]\n```\n\nIf the `mrf` argument is set to `False`, the output will not be parsed but rather returned as is:\n\n```python\n...\n\np = packer.Packer(template, ...)\nresult = p.inspect(mrf=True)\nprint(result.stdout)\n\n# output:\nOptional variables and their defaults:\n\n  aws_access_key          = {{env `AWS_ACCESS_KEY_ID`}}\n  aws_secret_key          = {{env `AWS_ACCESS_KEY`}}\n\nBuilders:\n\n  amazon                   (amazon-ebs)\n\nProvisioners:\n\n  shell\n\n...\n\n```\n\n\n### [Packer.push()](https://www.packer.io/docs/command-line/push.html)\n\nYou must be logged into Atlas to use the `push` function:\n\n```python\n...\n\np = packer.Packer(template, ...)\natlas_token = 'oi21mok3mwqtk31om51o2joj213m1oo1i23n1o2'\np.push(create=True, token=atlas_token)\n```\n\n### [Packer.validate()](https://www.packer.io/docs/command-line/validate.html)\n\n```python\n...\n\np = packer.Packer(template, ...)\np.validate(syntax_only=False)\n```\n\n### Packer.version()\n\n```python\n...\n\np = packer.Packer(template, ...)\nprint(p.version())\n```\n\n### PackerInstaller.install()\n\nThis installs packer to `packer_path` using the `installer_path` and verifies that the installation was successful.\n\n```python\n\npacker_path = '/usr/bin/'\ninstaller_path = 'Downloads/packer_1.7.4_linux_amd64.zip'\n\np = packer.Installer(packer_path, installer_path)\np.install()\n```\n\n## Shell Interaction\n\nThe [sh](http://amoffat.github.io/sh/) Python module is used to execute Packer.\nAs such, return values from all functional methods (`validate`, `build`, etc..) other than the `version` method\nwill return an `sh` execution object. This is meant for you to be able to read stdout, stderr, exit codes and more after executing the commands. With the progression of `python-packer` less abstract objects will return and more concise return values will be provided.\n\nAdditionally, to verify that all errors return with as much info as possible, error handling is done gently. Most errors will raise an `sh` exception so that you're able to interact with them. Again, as this module progresses, these exceptions will be handled properly.\n\n\n## Testing\n\nTests have not been developed yet.\n\n```shell\ngit clone git@github.com:abhi1693/python-packer.git\ncd python-packer\npip install tox\ntox\n```\n\n## Contributions..\n\n..are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhi1693%2Fpython-packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhi1693%2Fpython-packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhi1693%2Fpython-packer/lists"}