skip to Main Content

I usually deploy my NodeJS app to Google App Engine and ignore all docker assets when deploying by a .gcloudignore file as below:

.git
.gitignore
Dockerfile
docker-compose.yml
nginx/
redis-data/
.vscode/
.DS_Store
.prettierrc
README.md
node_modules/
.env

Last week I have successfully deployed my app to App Engine without any problems. But today (without any changes except source code) it failed and threw me an Error:

ERROR: (gcloud.app.deploy) There is a Dockerfile in the current directory, and the runtime field in /Users/tranphongbb/Works/unstatic/habitify-annual-report-backend/app.yaml is currently set to [runtime: nodejs]. To use your Dockerfile to build a custom runtime, set the runtime field to [runtime: custom]. To continue using the [nodejs] runtime, please remove the Dockerfile from this directory.

Even when removing the .gcloudignore file and go with the skip_files option in app.yaml, it still failed.

My source tree:

.dockerignore
.eslintrc.json
.gcloudignore
.gitignore
.prettierrc
.vscode
Dockerfile
README.md
app.yaml
docker-compose.yml
nginx
package.json
src

2

Answers


  1. I reproduced your issue by cloning both Node.js App Engine Flex Quickstart and adding a Dockerfile to the same folder as the app.yaml file.
    Indeed, I received the same error message as you did. But I was able to see that if I move the Dockerfile to a different directory, the deploy succeeds. It seems that gcloud app deploy doesn’t respect the .gcloudignore file.

    For node.js in the Flexible Environment, there’s no skip_files entry in the App Engine Official Documentation.

    To ignore your files defined in .gcloudignore file, please run the command gcloud beta app deploy which worked for me to ignore the Dockerfile when using Nodejs Runtime in app.yaml or you can use gcloud app deploy command but move your Dockerfile to another directory.

    Login or Signup to reply.
  2. The purpose of the .gcloudignore file is to avoid certain files to be uploaded to App Engine, Cloud Functions, etc, deployments which is documented here. When using gcloud app deploy this command will notice if there is a Dockerfile and will correlate that in the app.yaml there is set runtime: custom. In case that condition is not meet, you’ll get a similar error message as follows:

    ERROR: (gcloud.app.deploy) There is a Dockerfile in the current directory, and the runtime field in path/app.yaml is currently set to [runtime: nodejs]. To use your Dockerfile to build a custom runtime, set the runtime field to [runtime: custom]. To continue using the [nodejs] runtime, please remove the Dockerfile from this directory.
    

    Now the last question, why does this work with gcloud beta app deploy and not with gcloud app deploy?

    Checking at the source code of the Cloud SDK which can be viewed by anyone, the gcloud app deploy has the following code which makes the verification mentioned before:

    if info.runtime == 'custom':
        if has_dockerfile and has_cloudbuild:
          raise CustomRuntimeFilesError(
              ('A custom runtime must have exactly one of [{}] and [{}] in the '
               'source directory; [{}] contains both').format(
                   config.DOCKERFILE, runtime_builders.Resolver.CLOUDBUILD_FILE,
                   source_dir))
        elif has_dockerfile:
          log.info('Using %s found in %s', config.DOCKERFILE, source_dir)
          return False
        elif has_cloudbuild:
          log.info('Not using %s because cloudbuild.yaml was found instead.',
                   config.DOCKERFILE)
          return True
        else:
          raise NoDockerfileError(
              'You must provide your own Dockerfile when using a custom runtime. '
              'Otherwise provide a "runtime" field with one of the supported '
              'runtimes.')
      else:
        if has_dockerfile:
          raise DockerfileError(
              'There is a Dockerfile in the current directory, and the runtime '
              'field in {0} is currently set to [runtime: {1}]. To use your '
              'Dockerfile to build a custom runtime, set the runtime field to '
              '[runtime: custom]. To continue using the [{1}] runtime, please '
              'remove the Dockerfile from this directory.'.format(info.file,
    

    On the other hand the gcloud beta app deploy does not do this verification at all (assuming I reviewed the correct code):

    if runtime == 'custom' and self in (self.ALWAYS,
                                        self.WHITELIST_BETA,
                                        self.WHITELIST_GA):
      return needs_dockerfile
    

    In conclusion, the .gcloudignore will prevent some files/folder to be uploaded but not will be considered when doing some pre-checks of this command. In this case a Dockerfile should be considered since it could be part of the deployment.

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