"gcloud app deploy" hangs on "Building and pushing image for service" - google-app-engine

I suddenly can't deploy using gcloud app deploy.
It hangs on "Building and pushing image for service [default]". At that time, the Python process takes 99% CPU, and continues until the deploy times out. I've tried upgrading Python to no avail.
It occurs regardless of Google Appengine Project. Have tried installing different versions of gcloud CLI to no avail.
My teammates can deploy successfully using the same commands. Any ideas?
EDIT:
The app.yaml file:
runtime: nodejs
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 6
disk_size_gb: 10
env_variables:
...
Output of my gcloud app deploy verbosity=debug: https://gist.github.com/bbarton/05b8ae514849a5731101afb5ae639357

Related

gcloud app deploy trying to push old code

I have an app engine flexible environment running in Python. There was a syntax error in one of the python files, so when I ran the deploy command, it failed with the error "Application startup error! Code: APP_CONTAINER_CRASHED" showing me the syntax error. I went ahead and fixed the error, and when I tried to re-deploy, it still showed me the old error with the old code in the stack trace. The command i am using to deploy is this :
gcloud app deploy --version=6
The code being pushed is getting cached somewhere and I am unable to figure out how to clear the cache. I am using gcloudignore file and its content are as follows :
.gcloudignore
.git
.gitignore
__pycache__/
/setup.cfg
EDIT : My app.yaml file is as follows :
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app --timeout 3600
runtime_config:
python_version: 3
beta_settings:
cloud_sql_instances: ai4sg-armman:asia-south1:mmitra-armaan-10gb-cloudsql,ai4sg-armman:asia-south1:mmitra-predictions
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 8
memory_gb: 45
disk_size_gb: 1000
The full terminal logs can be found here : https://justpaste.it/4y1px

Why can't I override the timeout on my Google Cloud Build?

I am attempting to setup a CI Pipeline using Google Cloud Build.
I am attempting to deploy a MeteorJS app which has a lengthy build time - the default build timeout for GCB is 10 minutes and it was recommended here that I increase the timeout.
I have setup my cloudbuild.yaml file with the timeout option increased to 20 minutes:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
timeout: 1200s
I have a Trigger setup in GCB connected to a Bitbucket Repo and when I push a change and the Trigger fires, I get 2 new builds - one coming from Bitbucket and one whose source is Google Cloud Storage.
Once 10 minutes of build time has elapsed, the build from Cloud Storage will timeout which will cause the Bitbucket build to fail as well with Error Response: [4] DEADLINE_EXCEEDED
Occasionally, for whatever reason, the Cloud Storage build will finish in under 10 minutes which will allow the Bitbucket build to finish successfully and deploy.
If I attempt to cancel/stop the Cloud Storage build, it will also stop the Bitbucket build.
The screenshot below shows 2 attempts of the exact same build with differing results.
I do not understand where this second Cloud Storage Build is coming from, but it does not seem to be affected by the settings in my yaml file or my global GCP settings.
I have attempted to run the following commands from the gcloud CLI:
gcloud config set app/cloud_build_timeout 1200
gcloud config set builds/timeout 1200
gcloud config set container/build-timeout 1200
I have also attempted to use a high CPU build machine to speed up the process but it did not seem to have any effect.
Any insight would be greatly appreciated - I feel that I have exhausted every possible combination of Google Search keywords I can think up!
This timeout error comes from app engine deployment itself which has 10 min timeout by default.
You will need to update app/cloud_build_timeout property inside container itself like this:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args: ['-c', 'gcloud config set app/cloud_build_timeout 1200 && gcloud app deploy']
timeout: 1200s
Update
Actually simpler solution:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
timeout: 1200s
timeout: 1200s

Problem with nltk during app deployment on google cloud

I tried to deploy my application on gcloud app engine, when the deployment finish and I tried to brows the URL, I got 502 server error. The log shows that there is problem with nltk package:
[31m>>> import nltk
>>> nltk.download('punkt')
[0m
Searched in:
- '/root/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/env/nltk_data'
- '/env/lib/nltk_data'
- ''
I have put the necessary hardware requirement on my app.yaml file :
service: vapi
runtime: python
env: flex
health_check:
enable_health_check: True
check_interval_sec: 5
timeout_sec: 4
unhealthy_threshold: 2
healthy_threshold: 2
entrypoint: gunicorn -b :$PORT wsgi:app
runtime_config:
python_version: 3.5
resources:
cpu: 2
memory_gb: 8
disk_size_gb: 20
I have tried to install the nltk packages into one of the search path shown in the log above.
also, I have created app engine configuration file:
# appengine_config.py
from google.appengine.ext import vendor
# Add any libraries install in the "lib" folder.
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
any suggestions?
You're mixing up the documentation for the standard environment with the one for the flexible environment.
Installing dependencies into the lib directory and using a appengine_config.py file is specific for the 1st generation standard environment.
For the flexible environment you specify your python dependencies using the requirements.txt file, see Using Python Libraries:
The Python runtime will automatically install all dependencies
declared in your requirements.txt during deployment.
For non-python dependencies or those which aren't pip-installable you can use a custom runtime, see Up-to-date pip with AppEngine Python flex env?
Maybe of interest: How to tell if a Google App Engine documentation page applies to the 1st/2nd generation standard or the flexible environment

Elasticsearch deployment on google app engine flex

Is it possible to deploy Elasticsearch on App engine flex environment using a docker image.
I have tried the following
My files on the local machine
Folder : elasticsearch
app.yaml
Dockerfile
docker-entrypoint.sh
config folder(containing elasticsearch.yml)file
Contents of app.yaml
runtime: custom
env: flex
Dockerfile and docker-entrypoint.sh copied from https://github.com/GoogleCloudPlatform/elasticsearch-docker/tree/master/5/5.2.0
Modifications to the Dockerfile
replaced EXPOSE 9200 9300 to EXPOSE 8080
Modification to the elasticsearch.yml
cluster.name: "beaconinside-docker-cluster"
path.data: /usr/share/elasticsearch/data
http.host: 0.0.0.0
http.port: 8080
discovery.zen.minimum_master_nodes: 1
I build a container using the docker file on my local machine
docker build -t elasticdemo .
Then, I run the container
docker run -p 8080:8080 elasticdemo
I am able to access elasticsearch on 0.0.0.0:8080
Problem:
I am trying to deploy elasticsearch as an app to Google app engine flex environment
gcloud app deploy app.yaml --version elasticdocker --project myproject
The deployment fails with the following error
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
I was expected elasticsearch to deploy as an app and be available on the deployed url.
Could you please provide pointers/help/suggestions with this approach?
While you can deploy ES to App Engine Flexible environment it's not particularly useful. The VMs hosting GAE Flexible containers are restarted regularly as part of maintenance and whatever data is stored on the local disk will be lost on restart. If you want to use local disk for long term storage, I'd suggest to deploy the GCE VM's (or alternatively use a solution from the GCP Marketplace) or deploy to GKE which supports persistent disks
As for the actual question: you probably don't have a health check handler and therefore App Engine Flexible environment doesn't consider your app healthy after deploying it. The error message is useless, I agree.
From the GAE Flexible docs for building custom images:
"A health check is an HTTP request to the URL /_ah/health. A healthy application should respond with status code 200."
Alternatively you can turn off health checks by adding into app.yaml
enable_health_check: False

CLI 400 error deploying to Google App Engine

Today I got a new error when trying to deploy my application to Google App Engine via the command line:
Updating module [default]...-ERROR: (gcloud.preview.app.deploy) Server responded with code [400]:
Bad Request Unexpected HTTP status 400.
Your app may not have more than 120 versions.
Please delete one of the existing versions before trying to create a new version.
I am deploying to the top level using --promote, not creating other versions. How do I fix this error?
There is also a way to do this via command line if that interests you.
gcloud preview app versions list
gcloud preview app modules delete <module_name> --version=<version_number>
UPDATE 2017
(see also CLI 400 error deploying to Google App Engine
)
List all versions:
gcloud app versions list
Delete versions v1 and v2:
gcloud app versions delete v1 v2
https://cloud.google.com/sdk/gcloud/reference/app/versions/
So I found a way to do it through the web GUI (https://console.developers.google.com). If you go to the "App Engine" tab there is a "Versions" option. Click that and it will take you to a listing of versions. Apparently one is created each time you deploy with --promote in addition to one for each version you deploy. These can be selected and then there is a trash can to click on them to delete them.
While this is not the CLI solution I would have liked, it works.
The previous answer for the command line is deprecated now. The alternative is the following:
To list all versions:
gcloud app versions list
To delete a version:
gcloud app versions delete v1 v2
More info on: https://cloud.google.com/sdk/gcloud/reference/app/versions/delete
Hope it helps!
If someone is looking for cloudbuild.yaml changes for this then here is the sample YAML config file
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', '<dockerRepository>', '.' ]
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
- name: "gcr.io/cloud-builders/gcloud"
entrypoint: 'bash'
args:
- '-eEuo'
- 'pipefail'
- '-c'
- |-
gcloud app versions list --format="value(version.id)" --sort-by="~version.createTime" | tail -n +6 | xargs -r gcloud app versions delete --quiet
To remove the last version only for a specific service. Keep in mind you could have several services in the same GCP.
Fist get the service name
gcloud services list --available
and then, remove it
gcloud app versions list --format="value(version.id)" --sort-by="~version.createTime" --service=SERVICE_NAME | tail -n -1 | xargs gcloud app versions delete --quiet

Resources