簡體   English   中英

Packer 不會在 GCloud 上創建圖像

[英]Packer won't create image on GCloud

我一直在使用 HashiCorp 的工具(Packer 和 Terraform)創建圖像,然后在 AWS 上使用 Jenkins 構建 VM。 現在我有一個在 GCloud 上的項目,我已經成功配置 Terraform 來創建一個 VM,但是當我嘗試運行 packer 時,我收到以下錯誤 root@packer packer]# packer build createImage.json

googlecompute output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Error getting source image for instance creation: Could not find image, centos-7, in projects, [<PROJECT_ID> centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:
==> googlecompute: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body: 
==> googlecompute: * googleapi: got HTTP response code 400 with body:
Build 'googlecompute' errored: Error getting source image for instance creation: Could not find image, centos-7, in projects, [PROJECT_ID centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:

* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 

==> Some builds didn't complete successfully and had errors:
--> googlecompute: Error getting source image for instance creation: Could not find image, centos-7, in projects, [PROJECT_ID centos-cloud coreos-cloud debian-cloud google-containers opensuse-cloud rhel-cloud suse-cloud ubuntu-os-cloud windows-cloud gce-nvme]: 11 error(s) occurred:

* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 
* googleapi: got HTTP response code 400 with body: 

==> Builds finished but no artifacts were created.

這是我的 createImage.json

{
 "variables": {
    "project_id": "PROJECT_ID"
  },
 "builders": [
    {
      "type": "googlecompute",
      "region": "europe-west1",
      "zone": "europe-west1-b",
      "project_id": "{{user `project_id`}}",
      "source_image_family": "centos-7",
      "image_name": "My-Test-Image",
      "disk_size": 10,
      "machine_type": "f1-micro",
      "ssh_username": "centos"
    }
  ]
}

我應該提到,我使用的服務帳戶甚至被授予所有者權限,以確保我沒有權限問題。 有沒有人知道為什么我在 AWS 上遇到這個問題時效果很好。

由於您沒有使用"account_file"指定 JSON 服務帳戶密鑰,因此我假設您是從 GCP 中作為服務帳戶運行的 VM 實例運行打包程序,並且此類服務帳戶是具有Owner角色的帳戶.

我將首先檢查服務帳戶是否在 VM 詳細信息中正確配置,以及雲 API 訪問范圍是否按照此Packer 文檔中的描述定義:

  • Compute Engine 的“讀寫”
  • “存儲”的“完整”

此外,即使我認為這與此問題無關,您也不應該按照 本文檔使用f1-microg1-small機器類型構建圖像。

最后,我建議在Packer 社區論壇或任何其他官方渠道中也發布此問題。

您能否列出 GCloud 上的可用圖像並將此信息用於您的 json 配置文件:

gcloud compute images list --filter centos

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM