Getting packer to be able to change an image from a local GCP bucket

22 views
Skip to first unread message

Wes Quinn

unread,
Aug 21, 2019, 3:57:59 PM8/21/19
to Packer
Hello,

I am working with packerpy and GCP to be able to load an OVA file to a personal bucket and then modify that image and create a new image from that, using the provisioners feature in a JSON file.

I have the process to upload to a personal bucket working, but I can't figure out how to get packer to find my image in my personal bucket.  Packer keeps searching the public area.  I didn't see where I can use a bucket.

Anyone have any idea on how to get packet to modify the image from the personal bucket?

On a separate note, I am able to use packer, in this same manner with AWS, just fine.

Here is an example of my JSON for GCP:

{
  "variables": {
    "disk_size": 150,
    "project_id": "proj-id",
    "result_image": "packer-example-{{timestamp}}",
    "source_image": "rhel-7-5-x86-64-minimal-ova",
    "ssh_password": "password",
    "ssh_timeout": "3m",
    "ssh_username": "user",
    "zone": "us-east-1"
  },
  "builders": [
    {
      "disk_size": "{{user `disk_size`}}",
      "image_name": "{{user `result_image`}}",
      "project_id": "{{user `project_id`}}",
      "source_image": "{{user `source_image`}}",
      "ssh_password": "{{user `ssh_password`}}",
      "ssh_username": "{{user `ssh_username`}}",
      "type": "googlecompute",
      "zone": "{{user `zone`}}"
    }
  ],
  "provisioners": [
    {
      "type": "file",
      "source": "./welcome.sh",
      "destination": "/root/",
      "direction": "upload"
    },
    {
      "type": "shell",
      "inline": [
        "chmod +x welcome.sh",
        "./welcome.sh"
      ]
    }
  ]
}

Here is the Python code that uses the above JSON code:
import argparse
import json
from packerpy import PackerExecutable
parser = argparse.ArgumentParser(description='This script modifies a GCP image in GCP.')
parser.add_argument('-f', '--json_file', required=True, help='The JSON file that contains the changes to make to the image file.')
args = parser.parse_args()
json_file = args.json_file
packer_bin = '/usr/local/bin/packer'
p = PackerExecutable(packer_bin)
(results, output, error) = p.build(json_file)
if results == 0:
  print('Success!')
else:
  print('Error:', error)
print('\nOutput:', output)

If you have any questions, please ask.

Thank you very much!
Wes Quinn

Rickard von Essen

unread,
Aug 21, 2019, 4:40:00 PM8/21/19
to packe...@googlegroups.com
First you have to create an image from the disk in gcs with gcloud, see

Use the --source-uri argument. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/5b866b6d-1ee3-4632-8df9-1c585d710e77%40googlegroups.com.

Rickard von Essen

unread,
Aug 21, 2019, 4:42:02 PM8/21/19
to packe...@googlegroups.com
And to use a non default source image you should set https://packer.io/docs/builders/googlecompute.html#source_image_project_id

Wes Quinn

unread,
Sep 3, 2019, 8:43:55 AM9/3/19
to Packer
Thanks for responding.

So is this a limitation on packer or GCP?

So it is impossible to modify my OVA file, in my personal bucket?

I was just wondering which app is putting the restriction on, since I can do this fine using AWS.

If it is packer, then hopefully I can get someone to change it.

If it is GCP, I can see why from them.

Thanks,
Wes Quinn

On Wednesday, August 21, 2019 at 4:42:02 PM UTC-4, Rickard von Essen wrote:
And to use a non default source image you should set https://packer.io/docs/builders/googlecompute.html#source_image_project_id

To unsubscribe from this group and stop receiving emails from it, send an email to packe...@googlegroups.com.

Rickard von Essen

unread,
Sep 4, 2019, 3:47:44 PM9/4/19
to packe...@googlegroups.com
It's how GCE works.

(You can't do that with AWS for normal EBS backed AMI's either) 

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/51029a11-a2f7-475e-8fa1-402187f5cd53%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages