Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying automatically Node app to App Engine with Cloud Build and VPC connector

i have a Problem during deploying an App Engine app with Cloud Build and VPC connector to my MongodDB Atlas Database.

When i deploy it with gcloud, it works perfectly with this command: gcloud beta app deploy

But i want CI (Continuous integration) to be implemented with Cloud Build. During the Cloud build following error appears:

Step #3: #============================================================#
Step #3: #= Uploading 2 files to Google Cloud Storage                =#
Step #3: #============================================================#
Step #3: File upload done.
Step #3: Updating service [nodeapi]...
Step #3: .......................................................................................................................................................................................failed.
Step #3: ERROR: (gcloud.beta.app.deploy) Error Response: [7] Error attaching GCE network to app.
Step #3: 
Step #3: Details: [
Step #3:   [
Step #3:     {
Step #3:       "@type": "type.googleapis.com/google.rpc.ResourceInfo",
Step #3:       "resourceName": "projects/visifingc/global/networks/default",
Step #3:       "resourceType": "Network"
Step #3:     }
Step #3:   ]
Step #3: ]
Step #3: 
Finished Step #3
ERROR
ERROR: build step 3 "gcr.io/cloud-builders/gcloud" failed: exit status 1

My app.yaml file:

runtime: nodejs10
service: nodeapi
vpc_access_connector:
  name: "projects/visifingc/locations/europe-west1/connectors/app-engine"

network:
  name: default

And cloudbuild.yaml:

steps:
  - name: node:10.15.1
    entrypoint: npm
    args: ["install"]
  - name: node:10.15.1
    entrypoint: npm
    args: ["run", "build"]
  - name: "gcr.io/cloud-builders/gcloud"
    args: ["beta","app","deploy"]

When a I look in App Engine to the configuration of Instance which was deployed (but with the error, therefore not really deployed) following App Engine Instance Configuration can be seen:

runtime: nodejs10
env: standard
instance_class: F1
handlers:
  - url: .*
    script: auto
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic
network: {}

As you can see, something is wrong with the network because it is empty.

Could you help me please to find a solution? I thought it could be a rights problems, therefore i tried to give to all the accounts access rights to VPC, but id didn't helped. Mostly i am following the defined setup with VPC network which is described here: https://cloud.google.com/appengine/docs/standard/nodejs/connecting-vpc

like image 419
Dave W. Avatar asked Nov 02 '19 20:11

Dave W.


People also ask

Which command is used to deploy application on App Engine?

Deploy your application to App Engine using the gcloud app deploy command. This command automatically builds a container image by using the Cloud Build service and then deploys that image to the App Engine flexible environment.


2 Answers

I ran into the same problem, and it turns out it was a permission issue after all. For us, the fix was to give "Compute Network Admin" permissions to the CI/CD process.

like image 103
Craig Silverstein Avatar answered Sep 30 '22 14:09

Craig Silverstein


I was having this issue earlier and struggled with it for a while. Solved it be changing from "gcloud beta app deploy" to simply "gcloud app deploy." Don't know why the beta version isn't working (especially if it was working from your CLI).

I know this isn't a satisfying answer, but hopefully it puts you on the right track!

BEFORE:

steps:
  - name: "gcr.io/google-containers/busybox"
    args: ["sed", "-i", "s/PROJECT_ID/${PROJECT_ID}/g", "app.yaml"]
  - name: "gcr.io/cloud-builders/gcloud"
    args: ["beta", "app", "deploy"]

AFTER:

steps:
  - name: "gcr.io/google-containers/busybox"
    args: ["sed", "-i", "s/PROJECT_ID/${PROJECT_ID}/g", "app.yaml"]
  - name: "gcr.io/cloud-builders/gcloud"
    args: ["app", "deploy"]
like image 30
J. Page Avatar answered Sep 30 '22 15:09

J. Page