从 Cloud Build 容器到 Google Compute Engine 实例的数据传输出现问题
Problem with data transfer from Cloud Build container to Google Compute Engine instance
-
continuous-integration
-
continuous-deployment
-
google-compute-engine
-
google-cloud-platform
-
google-cloud-build
目前我正在使用 Cloud Build 生成一些我需要部署到 GCE 实例的工件。为此,我尝试使用 gcloud 构建器和以下参数:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'scp', '--zone=<zone_id>', '<local_path>', '<google compute engine instance name>:<instance_path>']
构建失败并出现以下错误:
ERROR: (gcloud.compute.scp) Could not SSH into the instance. It is
possible that your SSH key has not propagated to the instance yet. Try
running this command again. If you still cannot connect, verify that
the firewall and instance are set to accept ssh traffic.
我已经在我的实例上打开了 22 端口,但这对我没有帮助。
你们能帮我解决这个问题吗?
在我的构建定义中我需要 check/fix 哪些要点?
也许你可以给我一个建议,我可以使用哪个构建器而不是 gcloud 将我的数据从 Cloud Build 容器传送到 GCE实例?
一些尝试:
1.Make 确定你可以正常 ssh way.
Troubleshooting SSH 如果第一步失败。
2.Try 将 SSH 目标从 'instancename' 更改为 'username@instance' 以指示 VM 内的用户名,例如
username@InstanceName
您必须找到一种方法来生成和定位 SSH Key Files 以便构建器连接到 GCE 实例:
google_compute
google_compute.pub
google_compute_known_hosts
它们与您用来从 Cloud Shell 或 Local Computer[=52 直接连接到实例的那些相同=],但这次连接必须由构建器自己完成。
像 SSH Key Generation 中解释的那样以交互方式将文件生成到构建器的身份路径(通过 cd ~ && pwd
测试,通常:/builder/home/.ssh
)。
建立连接后,通过 gsutil
将这些文件复制到 Google Cloud Storage。此步骤只需执行一次。
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', '-rP', '${_BUIKDER_HOME}', 'gs://${_BUCKET_NAME}/builder/']
substitutions:
_BUCKET_NAME: <bucket_name>
_BUIKDER_HOME: <builder_home>
timeout: "60s"
您可以将这些关键文件带到您的工作区。如果您愿意,那么它们将需要保留在存储中。
此放置的目的是它们将用于重新连接到实例,因为每次启动构建器时,它都会被配置回默认阶段,因此文件将不再存在。
密钥文件准备就绪后,您就可以像下面那样执行 scp transfer
:
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', '-rP', 'gs://${_BUCKET_NAME}/builder/.ssh'], '_${_BUILDER_HOME}']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'scp', '--recurse', '--zone', '${_ZONE}', '${_LOCAL_PATH}', '${_USER_NAME}@${_INSTANCE_NAME}:${INSTANCE_PATH}']
substitutions:
_ZONE: <zone>
_USER_NAME: <user_name>
_LOCAL_PATH: <local_path>
_BUCKET_NAME: <bucket_name>
_BUILDER_HOME: : <builder_home>
_INSTANCE_NAME: <instance_name>
_INSTANCE_PATH: <instance_path>
timeout: "60s"
注意:使用'--recurse'标志为或none只复制一个文件。
continuous-integration
continuous-deployment
google-compute-engine
google-cloud-platform
google-cloud-build
目前我正在使用 Cloud Build 生成一些我需要部署到 GCE 实例的工件。为此,我尝试使用 gcloud 构建器和以下参数:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'scp', '--zone=<zone_id>', '<local_path>', '<google compute engine instance name>:<instance_path>']
构建失败并出现以下错误:
ERROR: (gcloud.compute.scp) Could not SSH into the instance. It is
possible that your SSH key has not propagated to the instance yet. Try
running this command again. If you still cannot connect, verify that
the firewall and instance are set to accept ssh traffic.
我已经在我的实例上打开了 22 端口,但这对我没有帮助。
你们能帮我解决这个问题吗?
在我的构建定义中我需要 check/fix 哪些要点?
也许你可以给我一个建议,我可以使用哪个构建器而不是 gcloud 将我的数据从 Cloud Build 容器传送到 GCE实例?
一些尝试:
1.Make 确定你可以正常 ssh way.
Troubleshooting SSH 如果第一步失败。
2.Try 将 SSH 目标从 'instancename' 更改为 'username@instance' 以指示 VM 内的用户名,例如
username@InstanceName
您必须找到一种方法来生成和定位 SSH Key Files 以便构建器连接到 GCE 实例:
google_compute
google_compute.pub
google_compute_known_hosts
它们与您用来从 Cloud Shell 或 Local Computer[=52 直接连接到实例的那些相同=],但这次连接必须由构建器自己完成。
像 SSH Key Generation 中解释的那样以交互方式将文件生成到构建器的身份路径(通过 cd ~ && pwd
测试,通常:/builder/home/.ssh
)。
建立连接后,通过 gsutil
将这些文件复制到 Google Cloud Storage。此步骤只需执行一次。
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', '-rP', '${_BUIKDER_HOME}', 'gs://${_BUCKET_NAME}/builder/']
substitutions:
_BUCKET_NAME: <bucket_name>
_BUIKDER_HOME: <builder_home>
timeout: "60s"
您可以将这些关键文件带到您的工作区。如果您愿意,那么它们将需要保留在存储中。
此放置的目的是它们将用于重新连接到实例,因为每次启动构建器时,它都会被配置回默认阶段,因此文件将不再存在。
密钥文件准备就绪后,您就可以像下面那样执行 scp transfer
:
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args: ['cp', '-rP', 'gs://${_BUCKET_NAME}/builder/.ssh'], '_${_BUILDER_HOME}']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['compute', 'scp', '--recurse', '--zone', '${_ZONE}', '${_LOCAL_PATH}', '${_USER_NAME}@${_INSTANCE_NAME}:${INSTANCE_PATH}']
substitutions:
_ZONE: <zone>
_USER_NAME: <user_name>
_LOCAL_PATH: <local_path>
_BUCKET_NAME: <bucket_name>
_BUILDER_HOME: : <builder_home>
_INSTANCE_NAME: <instance_name>
_INSTANCE_PATH: <instance_path>
timeout: "60s"
注意:使用'--recurse'标志为