Packer_HyperV-ISO_GCP_Image

5 views
Skip to first unread message

CHARLY RAYAPPAN

unread,
Sep 2, 2021, 3:47:52 AMSep 2
to Packer
Hi All,

I am working on to build GCP golden image. I am using HyperV-ISO builder to build the image.

I am using following approach to build the image

Building base image(VHDX) in HyperV environemnt (Success)
Converting VHDX to Disk.raw using qumu.exe (Because GCP support disk.raw format) (Success)
Compressing disk.raw into tar.gz format (Ex.tar -cf filename.tar.gz F:\disk.raw) (Success)
Uploading compressed tar.gz file to GCS bucket (Success)
Creating image from tar.gz file in GCS bucket (gcloud compute images create testimg --project=xxx --source-uri=https://storage.googleapis.com/xxx/rhel8.raw.tar.gz --storage-location=us) (Failure)

ERROR: (gcloud.compute.images.create) Could not fetch resource:
 - The tar archive is not a valid image.

I need your valuable solution here.

template.Json

{
    "variables": {
      "disk_size_rhel_8": "30720",
      "iso_url_rhel_8_0": "F:\\ISOs\\rhel-8.4-x86_64-dvd.iso",
      "iso_checksum_rhel_8_0": "48f955712454c32718dcde858dea5aca574376a1d7a4b0ed6908ac0b85597811",
      "iso_checksum_type": "sha256",
      "output_directory": "F:\\gcp_image_build\\Imagesnew\\"
    },
    "provisioners": [
      {
        "type": "shell",
        "execute_command": "bash '{{.Path}}'",
        "script": "scripts/rhel_prep.sh"
      },
      {
        "type": "shell",
        "execute_command": "bash '{{.Path}}'",
        "script": "scripts/install_ansible.sh"
      },
      {
        "type": "shell",
        "execute_command": "bash '{{.Path}}'",
        "script": "scripts/redhat_cleanup.sh"
      }
    ],
    "builders": [
      {
        "type": "hyperv-iso",
        "boot_command": [
          "<esc><wait>",
          "linux ks=http://{{ .HTTPIP }}:{{ .HTTPPort}}/ks_rhel_8_4.cfg<enter><wait>"
        ],
        "boot_wait": "10s",
        "cpus": 1,
        "disk_size": "{{ user `disk_size_rhel_8` }}",
        "enable_dynamic_memory": false,
        "enable_mac_spoofing": true,
        "generation": 1,
        "http_directory": "F:\\gcp_image_build\\rhel_iso\\http",
        "http_port_min": 8000,
        "http_port_max": 9000,
        "iso_url": "{{ user `iso_url_rhel_8_0` }}",
        "iso_checksum_type": "{{ user `iso_checksum_type` }}",
        "iso_checksum": "{{ user `iso_checksum_rhel_8_0` }}",
        "output_directory": "{{ user `output_directory` }}",
        "memory": 2048,
        "skip_export": true,
        "ssh_username": "root",
        "ssh_password": "l!nux",
        "ssh_port": 22,
        "ssh_timeout": "4h",
        "shutdown_command": "echo '{{ user `ssh_username` }}'|sudo -S /sbin/halt -h -p",
        "switch_name": "ImageBuild",
        "vm_name": "disk.raw"
      }
    ],
    "post-processors": [
                       {
                              "type": "shell-local",
                              "execute_command": ["cmd.exe","/C","{{.Command}}"],
                              "inline": ["scripts/copy.bat"]
                       },
                         {
                                 "type": "shell-local",
                                 "inline": [
                                          "gcloud auth activate-service-account --key-file *** --project=***",
                                          "gsutil -m cp 'F:\\gcp_image_build\\rhel_iso\\diskraw\\rhel8.raw.tar.gz' gs://***/",
                                          "gcloud compute images create rhelimg8 --source-uri gs://***/rhel8.raw.tar.gz --project=***"
                                           ]
                         },
      {
        "output": "manifest.json",
        "strip_path": true,
        "type": "manifest"
      }
    ]
  }


Reply all
Reply to author
Forward
0 new messages