我们正在使用Packer在GCP计算实例中构建映像。Packer尝试根据项目和图像抓取图像,如下所示:
https://www.googleapis.com/compute/v1/projects/<project-name>/global/images/<image-name>?alt=json
然后抛出一个错误:oauth2: cannot fetch token: Post https://accounts.google.com/o/oauth2/token: dial tcp 108.177.111.84:443: i/o timeout
基于安全原则,我们的计算实例没有外部IP地址,因此无法访问internet。在这种情况下,accounts.google.com
不再可访问。那么我们如何验证google apis呢?
我尝试启用防火墙规则并为internet访问提供路由。但根据here的要求,如果实例没有外部IP地址,它仍然无法访问。
这意味着我们必须有一种单独的方法来验证googleapis。但是Packer支持这一点吗?
下面是我们的包装器构建器:
"builders": [
{
"type": "googlecompute",
"project_id": "test",
"machine_type": "n1-standard-4",
"source_image_family": "{{user `source_family`}}",
"source_image": "{{user `source_image`}}",
"source_image_project_id": "{{user `source_project_id`}}",
"region": "{{user `region`}}",
"zone": "{{user `zone`}}",
"network": "{{user `network`}}",
"subnetwork": "{{user `subnetwork`}}",
"image_name": "test-{{timestamp}}",
"disk_size": 10,
"disk_type": "pd-ssd",
"state_timeout": "5m",
"ssh_username": "build",
"ssh_timeout": "1000s",
"ssh_private_key_file": "./gcp-instance-key.pem",
"service_account_email": "test-account@test-mine.iam.gserviceaccount.com",
"omit_external_ip": true,
"use_internal_ip": true,
"metadata": {
"user": "build"
}
}
发布于 2019-06-20 09:32:04
要手动完成您想要执行的操作,您需要在项目内的工作计算实例上或在网络上启用了对等的vpc中打开ssh通道您要访问的计算是。
如果您随后将CI与gitlab-ci之类的runner一起使用,请确保在同一vpc内或在具有对等的vpc中创建runner。
如果您不想创建具有外部ip的计算机,您可以尝试打开到该项目的vpn连接,并通过vpn完成此操作。
https://stackoverflow.com/questions/56658329
复制