简体   繁体   English

更改 GCP 计算引擎?

[英]Making changes GCP compute engine?

I've been using lambda for some time and haven't provisioned a classic machine in a while.我使用 lambda 已经有一段时间了,也有一段时间没有配置经典机器了。

What I used to do was run a git hook on the machine so that whenever an update happened via git it would update the code on the machine.我以前做的是在机器上运行一个 git hook,这样每当通过 git 发生更新时,它就会更新机器上的代码。

I'm trying to figure out ways to elegantly make updates to google compute engine.我试图找出优雅地更新谷歌计算引擎的方法。

I'd like to use docker so I can easily spin new instances, but I'm not sure what to do in order to update the node js code on the machine我想使用 docker,这样我就可以轻松地旋转新实例,但我不知道该怎么做才能更新机器上的节点 js 代码

Deploying on compute engine is pretty broad, it depends on your needs.在计算引擎上部署非常广泛,这取决于您的需求。 I ended up using several different methods.我最终使用了几种不同的方法。

With Docker: Inside my package.json I have a command yarn deploy that builds and submits a fresh docker instance to the Google container repository.使用 Docker:在我的 package.json 中,我有一个命令yarn deploy ,它构建并提交一个新的 docker 实例到 Google 容器存储库。

Then it uses gcloud to restart the instance group (I don't think you need a group, the command would be different for single instance, similar concept).然后它使用gcloud重新启动实例组(我认为您不需要一个组,单个实例的命令会有所不同,类似的概念)。 Which then pulls the latest Docker image with the fresh code.然后使用新代码提取最新的 Docker 映像。

{
  "name": "cloudtest",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "NODE_ENV=development npx ts-node src/index.ts",
    "start": "node app.js",
    "docker": "gcloud builds submit --tag gcr.io/disco-skyline-353218/docker-image .",
    "deploy": "yarn docker && yarn restart:instance",
    "compile": "rimraf dist/ && tsc && yarn compile:browser && yarn copy:files && yarn copy:browser",
    "copy:files": "copyfiles -u 1 ./src/*.css dist/",
    "copy:browser": "copyfiles -u 1 ./src/browser/dist/* ./src/browser/lib/* ./src/browser/*.css dist/",
    "compile:browser": "cd ./src/browser && tsc && webpack",
    "restart:instance": "gcloud compute instance-groups managed rolling-action restart gpu-renderer-docker-node-group --zone us-central1-a"
  },
}

I had some issues with Docker and accessing Nvidia GPU drivers inside my container (I think I know how to fix now).我在使用 Docker 和访问容器内的 Nvidia GPU 驱动程序时遇到了一些问题(我想我现在知道如何解决了)。 Out of frustration I skipped docker and instead used a startup.sh script.出于沮丧,我跳过了 docker,而是使用了 startup.sh 脚本。

Still working on making booting up an instance automatic, but my strategy without docker is a bash script that has been tested and to make sure I am using the same OS.仍在努力自动启动实例,但我没有 docker 的策略是一个 bash 脚本,它已经过测试并确保我使用的是相同的操作系统。

I manually installed a --bare git repo on the machine following this https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps我按照https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps在机器上手动安装了一个 --bare git repo

Ideally the startup script will do that and I can easily manage multiple instances this way.理想情况下,启动脚本会这样做,我可以通过这种方式轻松管理多个实例。 Even better would be to go back to my Docker strategy and fix the issues with the drivers (it can be tricky using Google Container Optimized OS)更好的是回到我的 Docker 策略并修复驱动程序的问题(使用 Google Container Optimized OS 可能会很棘手)

I hope this helps, your workflow is up to you and or your team.我希望这会有所帮助,您的工作流程取决于您和/或您的团队。 Leverage Docker , gcloud , and bash when you can尽可能利用Dockergcloudbash

If you are using Github, you can use this extensions https://github.com/marketplace/actions/google-cloud-compute-engine-deploy如果你使用 Github,你可以使用这个扩展https://github.com/marketplace/actions/google-cloud-compute-engine-deploy

If you are using Jenkins, you can connect machine with ssh and update your code.如果您使用 Jenkins,您可以使用 ssh 连接机器并更新您的代码。

If you want a native solution, Cloud Build helps to you more -> Google cloud build with Compute Engine如果您想要原生解决方案,Cloud Build 可以为您提供更多帮助 -> Google Cloud build with Compute Engine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM