Google App Engine does not deploy two services (seem to be overriding each other)

Viewed 193

I have a Django backend and an Angular frontend and i'm trying to deploy both of them to a Google App Engine Standard app as two services within the same app.

The directory looks like this:

-backend
--cloudbuild.yaml
--app.yaml
-- ...
-frontend
--cloudbuild.yaml
--app.yaml
-- ...
-cloudbuild.yaml

The main cloudbuild.yaml goes through each folder and looks for a cloudbuild.yaml file and submits the build:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    for d in */; do
      config="${d}cloudbuild.yaml"
      if [[ ! -f "${config}" ]]; then
        continue
      fi

      echo "Building $d ... "
      (
        gcloud builds submit $d --config=${config}
      ) &
    done
    wait

When i push the code to my Github repo, they get deployed successfully. However, both logs show something like below:

Step #2: Beginning deployment of service [default]...
Step #2: #============================================================#
Step #2: #= Uploading 0 files to Google Cloud Storage =#
Step #2: #============================================================#
Step #2: File upload done.
Step #2: Updating service [default]...
Step #2: ................................done.
Step #2: Setting traffic split for service [default]...
Step #2: .....done.
Step #2: Deployed service [default] to [https://thisapp.appspot.com]

So it seems like one is overriding the other as the default service. When I go to the services page, there is only one service which is the default one.

I know that we first have to deploy the default service and then the rest. However i thought since the main cloudbuild.yaml submits the build one by one, then there would be a default service and the second build would create a second service.

The other two cloudbuild.yaml files are as below:

steps:

  # Install node packages
  - name: 'gcr.io/cloud-builders/npm'
    args: [ 'install' ]

  # Build productive files
  - name: 'gcr.io/cloud-builders/npm'
    args: [ 'run', 'build', '--prod']

  # Deploy to google cloud app egnine
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', '--version=prod']
steps:

  - name: 'python:3.7'                                                                                                                               
    entrypoint: python3                                                               
    args: ['-m', 'pip', 'install', '-t', '.', '-r', 'requirements.txt'] 

  - name: 'python:3.7'                                                            
    entrypoint: python3                                                           
    args: ['./manage.py', 'collectstatic', '--noinput']

  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', '--version=prod']

I'd be grateful if you can help me on this.

Thanks

1 Answers

It is happening because in your app.yaml file, you have not provided the service tag. If service tag is not provided, the service will be deployed as default service. For e.g. when you deploy your frontend, it is getting deployed as default service. And then you deploy your backend, it is also getting deployed as default service overriding the existing default service. or the vice versa.

Add the service tag in your frontend's app.yaml:

service: frontend
runtime: nodejs10

You may keep the backend as default service i.e. no service tag in backend's app.yaml

Related