{"record":{"id":"ba002c2cb8fe3df3","repo":"oven-sh/bun","slug":"packer-template-not-found-templatefile","errorCode":null,"errorMessage":"Packer template not found: ${templateFile}","messagePattern":"Packer template not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/machine.mjs","lineNumber":1160,"sourceCode":"  return data.access_token;\n}\n\n/**\n * Build a Windows image using Packer (Azure only).\n * Packer handles VM creation, bootstrap, sysprep, and gallery capture via WinRM.\n * This eliminates all the Azure Run Command issues (output truncation, x64 emulation,\n * PATH not refreshing, stderr false positives, quote escaping).\n */\nasync function buildWindowsImageWithPacker({ os, arch, release, command, ci, agentPath, bootstrapPath }) {\n  const { getSecret } = await import(\"./utils.mjs\");\n\n  // Determine Packer template\n  const templateName = arch === \"aarch64\" ? \"windows-arm64\" : \"windows-x64\";\n  const templateDir = resolve(import.meta.dirname, \"packer\");\n  const templateFile = join(templateDir, `${templateName}.pkr.hcl`);\n\n  if (!existsSync(templateFile)) {\n    throw new Error(`Packer template not found: ${templateFile}`);\n  }\n\n  // Get Azure credentials from Buildkite secrets\n  const clientId = await getSecret(\"AZURE_CLIENT_ID\");\n  const clientSecret = await getSecret(\"AZURE_CLIENT_SECRET\");\n  const subscriptionId = await getSecret(\"AZURE_SUBSCRIPTION_ID\");\n  const tenantId = await getSecret(\"AZURE_TENANT_ID\");\n  const resourceGroup = await getSecret(\"AZURE_RESOURCE_GROUP\");\n  const location = (await getSecret(\"AZURE_LOCATION\")) || \"eastus2\";\n  const galleryName = (await getSecret(\"AZURE_GALLERY_NAME\")) || \"bunCIGallery2\";\n\n  // Image naming must match getImageName() in ci.mjs:\n  //   [publish images] / normal CI: \"windows-x64-2019-v13\"\n  //   [build images]:               \"windows-x64-2019-build-37194\"\n  const imageKey = arch === \"aarch64\" ? \"windows-aarch64-11\" : \"windows-x64-2019\";\n  const imageDefName =\n    command === \"publish-image\"\n      ? `${imageKey}-v${getBootstrapVersion(os)}`","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/machine.mjs#L1142-L1178","documentation":"buildWindowsImageWithPacker() resolves scripts/packer/windows-arm64.pkr.hcl (aarch64) or windows-x64.pkr.hcl from the script's own directory and throws when existsSync fails — the checkout is missing the template or it was renamed without updating this mapping.","triggerScenarios":"Running machine.mjs from a partial/shallow checkout without scripts/packer; the .pkr.hcl file deleted or renamed locally; import.meta.dirname resolving somewhere unexpected after moving the script.","commonSituations":"Local edit renaming the template; sparse CI checkout; running a copied script outside the repo.","solutions":["Confirm the file exists: scripts/packer/windows-arm64.pkr.hcl and windows-x64.pkr.hcl","`git restore scripts/packer/` if deleted, or re-clone fully","If you renamed a template, update templateName/templateFile construction in machine.mjs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const templateFile = join(resolve(import.meta.dirname, 'packer'), `${templateName}.pkr.hcl`);\nif (!existsSync(templateFile)) {\n  throw new Error(`Packer template not found: ${templateFile} — run from a full checkout of the bun repo`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run machine.mjs from a complete repo checkout (scripts/packer/ included)","When renaming packer templates, grep machine.mjs for the old name","Add a CI step asserting the template files exist before the bake job starts"],"tags":["packer","files","ci","azure"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}