【发布时间】:2020-06-28 02:01:49
【问题描述】:
我正在使用他们的 App Engine 和 Compute Engine 在 Google Cloud 中开发一个项目。我在 Compute Engine 上设置了一个虚拟机实例,名称为“instance-1”。在这个实例上是 python 文件(file.py):
name = '<REPLACE_WITH_YOUR_NAME>'
print(name)
嗯,这不完全是 file.py,但这个概念适用于下面。此外,我有一个用 NodeJS 编写的 App Engine 项目,它通过 Google 的 Compute Engine API 连接到这个实例。以下是我对此的看法:
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-east1-b');
const vm_name = 'instance-1';
const vm = zone.vm(vm_name);
const my_name = "David Weiss"
// TODO: insert the variable my_name into the python code file.py where it says '<REPLACE_WITH_YOUR_NAME>'
// In my head, it would look something like this: vm.getFile('file.py', 'write').replace('<REPLACE_WITH_YOUR_NAME>', my_name);
获得实例“instance-1”后,我不知道如何使用 NodeJS 和 Compute Engine API 修改(甚至添加/替换/删除)其上的文件。这可以做到吗?如果无法替换 file.py 中的文本,我可以删除整个文件并编写一个全新的文件,其中已插入 my_name。
【问题讨论】:
-
您无法使用 API 直接修改 Compute Engine 上的文件。您可以使用 SSH/SFTP 进行文件传输。一个更简单的策略是部署到 GitHub 或 Cloud Storage,然后将文件拉取到在启动/重启时运行的启动文件中的 Compute Engine。此外,Cloud Build 专为构建和部署应用而设计。
标签: python node.js google-app-engine google-cloud-platform google-compute-engine