hashicorp / packer-plugin-qemu

Packer plugin for QEMU Builder
https://www.packer.io/docs/builders/qemu
Mozilla Public License 2.0
65 stars 45 forks source link

Add HCP Packer support for the QEMU builders #111

Open afretwell opened 1 year ago

afretwell commented 1 year ago

Overview of the Issue

When I add the hcp_packer_registry block to my builds block I see that my build instantly fails when reaching the hcp_packer_registry block. When I do not add the hcp_packer_registry block I am able to successfully create my Ubuntu image with no issues, I just cant push it to HCP Registry. I have logged into HCP cloud and was able to see that my build is being queued to hcp registry, but always results in failed status because of the issue Im being faced with. All of my parameters from my hcp_packer_registry block are making being sent to hcp successfully but my image is not for some reason. Ive even tried removing all parameters with the exception of bucket_name but still results in this block failing 100% of the time on multiple systems. Assistance would be greatly appreciated.

Reproduction Steps

  1. Add the HCP_CLIENT_ID and HCP_CLIENT_SECRET env vars
  2. Add the hcp_packer_registry block to your build block in your hcl2 file
  3. Run PACKER_LOG=1 packer build ubuntu.pkr.hcl

Packer errors out after post-processors end and returns the error:

==> qemu.ubuntu: Running post-processor:

* Post-processor failed: [TRACE] failed to update Packer registry with image artifacts for "qemu.ubuntu": setting a build to DONE with no published images is not currently supported.
Build 'qemu.ubuntu' errored after 7 minutes 44 seconds: 1 error(s) occurred:

==> Wait completed after 7 minutes 44 seconds
2022/11/26 16:38:51 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2022/11/26 16:38:51 machine readable: qemu.ubuntu,error []string{"1 error(s) occurred:\n\n* Post-processor failed: [TRACE] failed to update Packer registry with image artifacts for \"qemu.ubuntu\": setting a build to DONE with no published images is not currently supported."}

* Post-processor failed: [TRACE] failed to update Packer registry with image artifacts for "qemu.ubuntu": setting a build to DONE with no published images is not currently supported.
==> Builds finished but no artifacts were created.
* Post-processor failed: [TRACE] failed to update Packer registry with image artifacts for "qemu.ubuntu": setting a build to DONE with no published images is not currently supported.

==> Wait completed after 7 minutes 44 seconds

2022/11/26 16:38:51 [INFO] (telemetry) Finalizing.
==> Some builds didn't complete successfully and had errors:
--> qemu.ubuntu: 1 error(s) occurred:

* Post-processor failed: [TRACE] failed to update Packer registry with image artifacts for "qemu.ubuntu": setting a build to DONE with no published images is not currently supported.

==> Builds finished but no artifacts were created.
2022/11/26 16:38:51 waiting for all plugin processes to complete...
2022/11/26 16:38:51 /usr/local/bin/github.com/hashicorp/qemu/packer-plugin-qemu_v1.0.6_x5.0_darwin_amd64: plugin process exited

Packer version

Packer v1.8.4

Simplified Packer Template

packer {
  required_plugins {
    qemu = {
      version = ">= 1.0.6"
      source  = "github.com/hashicorp/qemu"
    }
  }
}

source "qemu" "ubuntu" {
  accelerator               = "tcg"
  boot_command              = [
    "c<wait3s>",
    "set gfxpayload=keep<enter>",
    "linux /casper/vmlinuz autoinstall \"ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\" ",
    "hostname={{.Name}} boot=casper fsck.mode=skip auto=true noprompt noeject<enter>",
    "initrd /casper/initrd<enter>",
    "boot<enter>"
  ]
  boot_wait                 = "10s"
  communicator              = "ssh"
  cpus                      = var.cpus
  disk_size                 = var.disk_size
  format                    = "qcow2"
  headless                  = true
  http_directory            = "./cidata"
  iso_checksum              = var.iso_checksum
  iso_url                   = var.iso_url
  memory                    = var.memory
  output_directory          = "./build"
  skip_compaction           = true
  shutdown_command          = "echo 'ubuntu' | sudo -S -E shutdown -P +1"
  ssh_clear_authorized_keys = false
  ssh_password              = "ubuntu"
  ssh_port                  = 22
  ssh_timeout               = "4h"
  ssh_username              = "ubuntu"
  vm_name                   = var.vm_name
}

build {
  hcp_packer_registry {
    bucket_name = "ubuntu"
    description = "ubuntu base image"
    bucket_labels = {
      "os"             = "ubuntu",
      "ubuntu-version" = "22.04",
      "image"          = "ubuntu"
    }

    build_labels = {
      "build-time"   = timestamp()
      "build-source" = "${var.iso_url}"
    }
  }

  sources = ["source.qemu.ubuntu"]
}

Operating system and Environment details

Log Fragments and crash.log files

PACKER_LOG=1 Error Logs

nywilken commented 1 year ago

Hi there @afretwell thanks for reaching out. Your template is setup correctly. The issue you are running into here is that the QEMU builder is not generating HCP Packer images, as they require some additional metadata.

That said, only a handful of Packer builders work with HCP Packer. I'm going to use this issue as a feature request to add HCP Packer image publishing support to the QEMU builder.

github-actions[bot] commented 1 year ago

This issue has been synced to JIRA for planning.

JIRA ID: HPR-843

afretwell commented 1 year ago

Hi there @afretwell thanks for reaching out. Your template is setup correctly. The issue you are running into here is that the QEMU builder is not generating HCP Packer images, as they require some additional metadata.

That said, only a handful of Packer builders work with HCP Packer. I'm going to use this issue as a feature request to add HCP Packer image publishing support to the QEMU builder.

Amazing to hear, thank you, I'm sure it's not the top of priorities, but is there an average turnaround time for enhancements like this one?

afretwell commented 9 months ago

Any update on this feature for qemu builder?

nodadyoushutup commented 4 days ago

Would really love to hear any updates on this. Really would love this support!