skip to Main Content

I’ve been using lambda for some time and haven’t provisioned a classic machine in a while.

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.

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

2

Answers


  1. Chosen as BEST ANSWER

    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.

    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). Which then pulls the latest Docker image with the fresh code.

    {
      "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). Out of frustration I skipped docker and instead used a startup.sh script.

    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.

    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

    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)

    I hope this helps, your workflow is up to you and or your team. Leverage Docker, gcloud, and bash when you can


  2. If you are using Github, you can use this extensions
    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.

    If you want a native solution, Cloud Build helps to you
    more -> Google cloud build with Compute Engine

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search