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
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 usegcloud app deploy
command but move your Dockerfile to another directory.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 usinggcloud app deploy
this command will notice if there is aDockerfile
and will correlate that in theapp.yaml
there is setruntime: custom
. In case that condition is not meet, you’ll get a similar error message as follows:Now the last question, why does this work with
gcloud beta app deploy
and not withgcloud 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:On the other hand the
gcloud beta app deploy
does not do this verification at all (assuming I reviewed the correct code):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 aDockerfile
should be considered since it could be part of the deployment.