{"id":23127677,"url":"https://github.com/hlfshell/node-packer","last_synced_at":"2025-10-06T22:17:36.960Z","repository":{"id":22088537,"uuid":"25418210","full_name":"hlfshell/node-packer","owner":"hlfshell","description":"A node module for allowing programmatic control of the useful Packer.IO tool","archived":false,"fork":false,"pushed_at":"2016-11-18T15:11:51.000Z","size":39,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-08T05:24:09.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hlfshell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-19T04:52:19.000Z","updated_at":"2025-01-01T20:33:40.000Z","dependencies_parsed_at":"2022-08-05T15:18:04.860Z","dependency_job_id":null,"html_url":"https://github.com/hlfshell/node-packer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hlfshell/node-packer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fnode-packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fnode-packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fnode-packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fnode-packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlfshell","download_url":"https://codeload.github.com/hlfshell/node-packer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fnode-packer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278687688,"owners_count":26028535,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-17T09:14:27.440Z","updated_at":"2025-10-06T22:17:36.926Z","avatar_url":"https://github.com/hlfshell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-packer\n===================\nA convenient wrapper module to control Packer\n\n```js\n  var newImage = new PackerFile()\n\n  newImage.shellCmd('sudo apt-get update')\n    .shellCmd('sudo apt-get install -y nginx mysql nodejs')\n    .uploadFile('/my/app')\n    .chefClient('http://chefServer:8012')\n    .build()\n```\n\nThis is a BETA module. Pull requests, input, stories of the module in use, and constructive criticisms are highly welcome. I'll try to be active in maintaining.\n\n1. \u003ca href='#the-basics'\u003eThe Basics\u003c/a\u003e\n  - \u003ca href='#installation'\u003eInstallation\u003c/a\u003e\n  - \u003ca href='#usage'\u003eUsage\u003c/a\u003e\n  - \u003ca href='#packercmd-vs-packerfile'\u003epackerCmd VS PackerFile\u003c/a\u003e\n2. \u003ca href='#packercmd-documentation'\u003epackerCmd Documentation\u003c/a\u003e\n  - \u003ca href='#packercmdcommand'\u003epackerCmd.command\u003c/a\u003e\n  - \u003ca href='#packercmdbuild'\u003epackerCmd.build\u003c/a\u003e\n3. \u003ca href='#packerfile-documentation'\u003ePackerFile Documentation\u003c/a\u003e\n  - \u003ca href='#core-functions'\u003eCore functions\u003c/a\u003e\n  - \u003ca href='#new-packerfile'\u003enew PackerFile()\u003c/a\u003e\n  - \u003ca href='#packerfilefilepath'\u003ePackerFile.filePath\u003c/a\u003e\n  - \u003ca href='#packerfilewrite'\u003ePackerFile.write\u003c/a\u003e\n  - \u003ca href='#packerfilebuild'\u003ePackerFile.build\u003c/a\u003e\n  - \u003ca href='#packerfileread'\u003ePackerFile.read\u003c/a\u003e\n  - \u003ca href='#packerfileclean'\u003ePackerFile.clean\u003c/a\u003e\n  - \u003ca href='#packerfilejson'\u003ePackerFile.json\u003c/a\u003e\n4. \u003ca href='#builder-functions'\u003eBuilder functions\u003c/a\u003e\n  - \u003ca href='#packerfileaddbuilder'\u003ePackerFile.addBuilder\u003c/a\u003e\n  - \u003ca href='#packerfileaddamazonebs'\u003ePackerFile.addAmazonEBS\u003c/a\u003e\n  - \u003ca href='#packerfileaddamazoninstance'\u003ePackerFile.addAmazonInstance\u003c/a\u003e\n  - \u003ca href='#packerfileaddamazonchroot'\u003ePackerFile.addAmazonChroot\u003c/a\u003e\n  - \u003ca href='#packerfileadddigitalocean'\u003ePackerFile.addDigitalOcean\u003c/a\u003e\n  - \u003ca href='#packerfileadddocker'\u003ePackerFile.addDocker\u003c/a\u003e\n  - \u003ca href='#packerfileaddgooglecomputeengine'\u003ePackerFile.addGoogleComputeEngine\u003c/a\u003e\n  - \u003ca href='#packerfileaddnullbuilder'\u003ePackerFile.addNullBuilder\u003c/a\u003e\n  - \u003ca href='#packerfileaddopenstack'\u003ePackerFile.addOpenStack\u003c/a\u003e\n  - \u003ca href='#packerfileaddparallelsiso'\u003ePackerFile.addParallelsISO\u003c/a\u003e\n  - \u003ca href='#packerfileaddparallelspvm'\u003ePackerFile.addParallelsPVM\u003c/a\u003e\n  - \u003ca href='#packerfileaddqemu'\u003ePackerFIle.addQEMU\u003c/a\u003e\n  - \u003ca href='#packerfileaddvirtualboxiso'\u003ePackerFile.addVirtualBoxISO\u003c/a\u003e\n  - \u003ca href='#packerfileaddvirtualboxovf'\u003ePackerFile.addVirtualBoxOVF\u003c/a\u003e\n  - \u003ca href='#packerfileaddvmwareiso'\u003ePackerFile.addVMWareISO\u003c/a\u003e\n  - \u003ca href='#packerfileaddvmwarevmx'\u003ePackerFile.addVMWareVMX\u003c/a\u003e\n  - \u003ca href='#provisioner-functions'\u003eProvisioner functions\u003c/a\u003e\n  - \u003ca href='#packerfileaddprovisioner'\u003ePackerFile.addProvisioner\u003c/a\u003e\n  - \u003ca href='#packerfileshellcmd'\u003ePackerFile.shellCmd\u003c/a\u003e\n  - \u003ca href='#packerfileuploadfile'\u003ePackerFile.uploadFile\u003c/a\u003e\n  - \u003ca href='#packerfileansible'\u003ePackerFile.ansible\u003c/a\u003e\n  - \u003ca href='#packerchefclient'\u003ePacker.chefClient\u003c/a\u003e\n  - \u003ca href='#packerfilechefsolo'\u003ePackerFile.chefSolo\u003c/a\u003e\n  - \u003ca href='#packerfilepuppetmasterless'\u003ePackerFile.puppetMasterless\u003c/a\u003e\n  - \u003ca href='#packerfilesaltmasterless'\u003ePackerFile.saltMasterless\u003c/a\u003e\n5. \u003ca href='#post-processors'\u003ePost-Processors\u003c/a\u003e\n  - \u003ca href='#packerfileaddpostprocessor'\u003ePackerFile.addPostProcessor\u003c/a\u003e\n  - \u003ca href='#packerfilecompress'\u003ePackerFile.compress\u003c/a\u003e\n  - \u003ca href='#packerfiledockerimport'\u003ePackerFile.dockerImport\u003c/a\u003e\n  - \u003ca href='#packerfiledockerpush'\u003ePackerFile.dockerPush\u003c/a\u003e\n  - \u003ca href='#packerfiledockersave'\u003ePackerFile.dockerSave\u003c/a\u003e\n  - \u003ca href='#packerfiledockertag'\u003ePackerFile.dockerTag\u003c/a\u003e\n  - \u003ca href='#packerfilevagrant'\u003ePackerFile.vagrant\u003c/a\u003e\n  - \u003ca href='#packerfilevagrantcloud'\u003ePackerFile.vagrantCloud\u003c/a\u003e\n  - \u003ca href='#packerfilevsphere'\u003ePackerFile.vsphere\u003c/a\u003e\n\n\n# The Basics\n\nPacker is a very useful command line application to generate server images across a multitude of services such as Amazon, Heroku, or local applications such as Docker or VirtualBox. It was created by HashiCorp, of which I am not associated with beyond being a fan.  I've created a node wrapper to allow me to programmatically control the tool as part of a larger project, and am sharing the results here.\n\n\n## Installation\n\n```bash\nnpm install node-packer\n```\n\n\n## Usage\n\n```js\nvar packerCmd = require('node-packer').packerCmd\nvar PackerFile = require('node-packer').PackerFile\n```\n\n\n### packerCmd VS PackerFile\n\npackerCmd is a command line wrapper for the build command for Packer. It also formats the output in a few ways. Currently, there are only a few commands in Packer that are machine-readable compatible, and only the build command seems to make sense being built. As such, the other commands haven't been built out yet. They are TBD.\n\nPackerFile is a helpful class wrapped around packerCmd - you don't need to bring in packerCmd unless you need to manually control the builder.\n\nIn other words, packerCmd allows you to execute commands on a packer file on your system. PackerFile manages that file, or removes the need for the file, as well as allows the execution of builds on that file.\n\n\n## Packer.io Documentation\n\nI will not attempt to explain every nook and cranny of required parameters or what Packer.io is doing in the background -for that, I suggest you turn to the tool's [documentation](http://www.packer.io/docs).\n\nI have tried to keep parameter names the same throughout the module. If an attribute can be passed in is mentioned in the docs, it works here.\n\n\n# packerCmd Documentation\n\npackerCmd currently only wraps the build command, and formats output from the console.\n\n\n### packerCmd.command\n\n```js\npackerCmd.command(command, file, options)\n```\n\npackerCmd.command creates the command string for a packer.io command on a given file. It shall pass options from a simple javascript object as -key=value.\n\n* command - The command to execute. build, inspect, version, etc\n* file - The file to execute the command on\n* opts - A javascript object. The function will take the keys from options, and then pass them in the outputted command string as -key=value\n\n### packerCmd.build\n\n```js\npackerCmd.build(file, options, cb)\n```\n\npackerCmd.build executes and handles the output formatting of a Packer.IO build command.\n\n* file - the Packer file to execute the command on\n* options - the options object to add to the command string\n* cb - the callback\n\nCallback example:\n\n```js\nfunction(err, output){\n  if(err) {\n    console.error('Uh-oh...', err)\n  } else {\n    console.log('Hooray! It worked', output)\n  }\n}\n```\n\nPlease note that there is an additional, secret option not passed in as a command string to Packer.IO - outputType.\noutputType is stripped from the options object before being passed into the command string, and used to request different types of output. The following options are available:\n\n* raw - The straight up string output from Packer.IO\n* delimited - An array of arrays, seperated by newlines and then commas.\n* results - The default option - a javascript object describing the output artifacts for each builder\n* all - an object with keys of the above types, with their respective output formats\n\n\n# PackerFile Documentation\n\n\nPackerFile allows you to do this:\n```js\nvar PackerFile = require('node-packer').PackerFile\n\nvar newImage = new PackerFile()\nnewImage.addAmazonEBS(process.env.AMAZON_ACCESS_TOKEN,\n    process.env.AMAZON_SECRET_TOKEN,\n    't1.micro',\n    'us-east-1',\n    'ami-3d8457d',\n    'ubuntu')\n .shellCmd('sleep 30')\n .shellCmd('sudo apt-get update')\n .shellCmd('sudo apt-get install nodejs')\n .uploadFile('path/to/my/app')\n .build()\n```\n\n...and have Packer.io create an amazon image for deployment that is a base ubuntu install with nodejs installed.\n\nAll commands are chainable, or can be standalone.\n\nAll PackerFile objects have the following attributes:\n\n* filePath - the current filepath of the PackerFile. Can be null if it's only being worked on in memory.\n* builders - an [] of builder objects\n* provisioners - an [] of provisioner objects\n* variables - an [] of variable objects\n* post-processors - an [] of post-processor objects\n\n## Core functions\n\n### new PackerFile()\n\n```js\nvar packerFile = new PackerFile(opts)\n```\n* opts - an optional parameter. If it's passed in, it has all attributes for the PackerFile. If the filePath is included, it will immediately call this.read()\n\n\n### PackerFile.filePath\n\n```js\npackerFile.filePath(filePath)\n```\n\nEquivalent to packerFile.filePath = 'something', but allows function chaining.\n\n\n### PackerFile.write\n\n```js\npackerFile.write([workingDirectory,] cb)\n```\n\nWill write the PackerFile in memory to a file. If there is a filePath set, it will attempt to write to that file path. Otherwise it will generate one with a random file name. If workingDirectory is provided, it shall use that directory to generate the file. Otherwise, it will work locally (whatever './' is at the time)\n\nPlease note that, while calling it without a callback is possible, and the write function is chainable, that the function is asynchronous and thus chaining more functions into it does not mean it waits for the build to be complete.\n\nCallback example:\n\n```js\npackerFile.write(function(err){\n  if(err) {\n    console.error('Oh noes!', err)\n  } else {\n    console.log('Hooray!')\n  }\n})\n```\n\n\n### PackerFile.build\n\n```js\npackerFile.build([opts,] cb)\n```\n\nWill attempt a build by calling packerCmd.build. The opts parameter is optional. If filePath is set, it shall immediately start the build on that file and NOT write. If there is no filePath set, then it will call write() and, upon completion (either success or failure) shall call .clean()\n\nPlease note that, while calling it without a callback is possible, and the build function is chainable, that the function is asynchronous and thus chaining more functions into it does not mean it waits for the build to be complete.\n\nCallback example:\n\n```js\npackerFile.build(function(err, output){\n  if(err) {\n    console.error('Fiddlesticks! Something went wrong :-(', err)\n  } else {\n    console.log('The formatted output from the build:', output)\n  }\n})\n```\n\n\n### PackerFile.read\n\n```js\npackerFile.read(cb)\n```\n\nWill read the current filePath, if any. It shall then convert it to a JSON file and attempt to assign them from the PackerFile. Useful if you have pre-written PackerFiles that you want to start manipulating/build off of.\n\nCallback example:\n\n```js\npackerFile.write(function(err){\n  if(err) {\n    console.error('Oh gum drops :-/', err)\n  } else {\n    console.log('My life has never been greater - it worked')\n  }\n})\n```\n\n\n### PackerFile.clean\n\n```js\npackerFile.clean(cb)\n```\n\nWill destroy the filePath, if it exists. This is called by build if you call it without a filePath set.\n\nCallback example:\n\n```js\npackerFile.write(function(err){\n  if(err) {\n    console.error('The system ignored our request', err)\n  } else {\n    console.log('Squeaky clean')\n  }\n})\n```\n\n\n### PackerFile.json\n\n```js\npackerFile.json()\n```\n\nReturns the same JSON we write to the Packer file in .write()\n\n\n## Builder functions\n\nBuidler functions consist of a core function - addBuilder - and wrapper functions that merely, in turn, call that. All functions are chainable.\n\nAll builder functions list out required or suggested required attributes from the Packer.IO documentation, with an additional opts parameter where you can specify any additional, unlisted parameters.\n\nAll builder functions allow the passing of an object as its only parameter that defines the entirety of the builder. Type is not required on helper functions save addBuilder.\n\nFor additional documentation on individual builders, please refer to the [Packer.io docs](http://www.packer.io/docs).\n\n\n### PackerFile.addBuilder\n\n```js\npackerFile.addBuilder(builderType, opts)\n```\n\nCore builder function. Requires type to be specified, all other options passed as a simple key/value javascript object.\n\n\n### PackerFile.addAmazonEBS\n\n```js\npackerFile.addAmazonEBS(access_key, secret_key, instance_type, region, source_ami, ssh_username, opts)\n```\n\n\n### PackerFile.addAmazonInstance\n\n```js\npackerFile.addAmazonInstance(access_key, secret_key, account_id, source_ami, ssh_username, region, instance_type, ami_name, s3_bucket, x509_cert_path, x509_key_path, opts)\n```\n\n\n### PackerFile.addAmazonChroot\n\n```js\npackerFile.addAmazonChroot(access_key, secret_key, source_ami, ami_name, opts)\n```\n\n\n### PackerFile.addDigitalOcean\n\n```js\npackerFile.addDigitalOcean(api_token, opts)\n```\n\n\n### PackerFile.addDocker\n\n```js\npackerFile.addDocker(commit, export_path, image, opts)\n```\n\n\n### PackerFile.addGoogleComputeEngine\n\n```js\npackerFile.addGoogleComputeEngine(account_file, client_secrets_file, private_key_file, project_id, source_image, bucket_name, zone, opts)\n```\n\n\n### PackerFile.addNullBuilder\n\n```js\npackerFile.addNullBuilder(host, ssh_username, ssh_password, ssh_private_key_file, opts)\n```\n\n\n### PackerFile.addOpenStack\n\n```js\npackerFile.addOpenStack(username, password, flavor, provider, image_name, source_image, opts){\n```\n\n\n### PackerFile.addParallelsISO\n\n```js\npackerFile.addParallelsISO(parallels_tools_flavor, ssh_username, iso_url, iso_checksum, iso_checksum_type, opts)\n```\n\n\n### PackerFile.addParallelsPVM\n\n```js\npackerFile.addParallelsPVM(parallels_tools_flavor, ssh_username, source_path, opts)\n```\n\n\n### PackerFIle.addQEMU\n\n```js\npackerFile.addQEMU(ssh_username, iso_url, iso_checksum, iso_checksum_type, opts)\n```\n\n\n### PackerFile.addVirtualBoxISO\n\n```js\npackerFile.addVirtualBoxISO = function(ssh_username, iso_url, iso_checksum, iso_checksum_type, opts)\n```\n\n\n### PackerFile.addVirtualBoxOVF\n\n```js\npackerFile.addVirtualBoxOVF(ssh_username, source_path, opts)\n```\n\n\n### PackerFile.addVMWareISO\n\n```js\npackerFile.addVMWareISO(ssh_username, iso_url, iso_checksum, iso_checksum_type, opts)\n```\n\n\n### PackerFile.addVMWareVMX\n\n```js\npackerFile.addVMWareVMX(ssh_username, source_path, opts)\n```\n\n\n## Provisioner functions\n\nProvisioner functions add, in order of calling, the provisioner to the Packer File. They are all built off of addProvisioner, and follow the same convention as builders - they can accept a single object as the first and only attribute.\n\n\n### PackerFile.addProvisioner\n\n```js\npackerFile.addProvisioner(provisionerType, opts)\n```\n\nCore provisioner function - all other provisioner functions use this.\n\n\n### PackerFile.shellCmd\n\n```js\npackerFile.shellCmd(cmds[, force])\n```\n\nShell command has a unique attribute and approach compared to normal provisioners. The cmds variable accepts either a string or array of strings. If the last provisioner added was also a shell cmd, it will append the commands to the inline/shell command provisioner instead of creating a new provisioner. This can be overruled by setting force to true.\n\n\n### PackerFile.uploadFile\n\n```js\npackerFile.uploadFile(source, destination)\n```\n\n\n### PackerFile.ansible\n\n```js\npackerFile.ansible(playbook_file, opts)\n```\n\n\n### Packer.chefClient\n\n```js\npackerFile.chefClient(node_name, opts)\n```\n\n\n### PackerFile.chefSolo\n\n```js\npackerFile.chefSolo(run_list, opts)\n```\n\n\n### PackerFile.puppetMasterless\n\n```js\npackerFile.puppetMasterless(manifest_file, opts)\n```\n\n\n### PackerFile.saltMasterless\n\n```js\npackerFile.saltMasterless(local_state_tree, opts)\n```\n\n\n## Post-Processors\n\nPost-Processors can be added and manipulated in PackerFile, but beyond that the management of each post-processor is left as an exercise to the user for now. They work the same way as provisioners above.\n\n\n### PackerFile.addPostProcessor\n\n```js\npackerFile.addPostProcessor(processorType, opts)\n```\n\n\n### PackerFile.compress\n\n```js\npackerFile.compress(path)\n```\n\n\n### PackerFile.dockerImport\n\n```js\npackerFile.dockerImport(repository, tag)\n```\n\n\n### PackerFile.dockerPush\n\n```js\npackerFile.dockerPush(opts)\n```\n\n\n### PackerFile.dockerSave\n\n```js\npackerFile.dockerSave(path)\n```\n\n\n### PackerFile.dockerTag\n\n```js\npackerFile.dockerTag(repository, tag)\n```\n\n\n### PackerFile.vagrant\n\n```js\npackerFile.vagrant(opts)\n```\n\n\n### PackerFile.vagrantCloud\n\n```js\npackerFile.vagrantCloud(access_token, box_tag, version, opts)\n```\n\n\n### PackerFile.vsphere\n\n```js\npackerFile.vsphere(username, password, host, datacenter, cluster, resource_pool, vm_name, opts)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlfshell%2Fnode-packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlfshell%2Fnode-packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlfshell%2Fnode-packer/lists"}