I am trying to deploy my app using Google App Engine. I have edited app.yaml to reflect the flexible environment and also gave all the app information. Below is the app.yaml file.
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
Once the deployment is in progress, I am getting the following error
[2018-08-24 06:57:14 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-08-24 06:57:14 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-08-24 06:57:14 +0000] [1] [INFO] Using worker: sync
[2018-08-24 06:57:14 +0000] [7] [INFO] Booting worker with pid: 7
App Deployed
Failed to find application: 'main'
[2018-08-24 06:57:14 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-08-24 06:57:14 +0000] [1] [INFO] Shutting down: Master
[2018-08-24 06:57:14 +0000] [1] [INFO] Reason: App failed to load.
Please note that App Deployed is the line in my print statement. It is getting executed. But the deployment is getting failed
Thank you in advance
In your app.yaml, you're starting gunicorn with gunicorn -b :$PORT main:app. This tells it to look for the object app in the file main.py
The error you're getting comes from gunicorn and occurs when you have a main.py file, but it does not have an app object in it.
You probably want to set up a Flask app as follows:
from flask import Flask
app = Flask(__name__)
See a full example app here: https://cloud.google.com/appengine/docs/flexible/python/quickstart#hello_world_code_review
I have had the same issue.
Failed to find application: 'main'
The reason in my case was that I had a directory called also main in the root project directory.
drwxr-xr-x 2 user staff 64 Nov 30 10:12 main
-rw-r--r-- 1 user staff 1178 Nov 29 20:58 main.py
I guess gunicorn got confused.
The solution (worked for me): to rename main directory.
P.S. Just don't rename it to code directory. It will cause another issue with debugging in PyCharm. :)
My folder structure is looks llike this the main.py is not in the root directory how I can specify this in app.yaml file.
/app
|__main.py
app.yaml
Related
My Python Flask app is able to git push to heroku no problem, but after pushing, when checking the logs with heroku logs --tail, it repeatedly logs:
2022-08-24T17:07:47.065727+00:00 app[web.1]: [2022-08-24 17:07:47 +0000] [21] [INFO] Booting worker with pid: 21
2022-08-24T17:07:47.100592+00:00 app[web.1]: * Serving Flask app 'app'
2022-08-24T17:07:47.100599+00:00 app[web.1]: * Debug mode: off
2022-08-24T17:07:47.101990+00:00 app[web.1]: Permission denied <-- here
2022-08-24T17:07:47.102149+00:00 app[web.1]: [2022-08-24 17:07:47 +0000] [21] [INFO] Worker exiting (pid: 21)
Over and over again with different pid.
My project structure:
MyApp\
src\
static\...
templates\...
app.py
Procfile
requirements.txt
My Procfile is web: gunicorn --pythonpath src app and my app.py is:
# ... imports
app = Flask(__name__)
# ... routes
app.run(host="0.0.0.0", port=80, threaded=True)
I don't know what permission is being denied, or how it is being denied, or how to fix it. Tried searching around, all the results were for "[Errno ...] Permission Denied", which is different from mine.
heroku has set the port itself, so you can't assign flask port=80 here
try this
app.run(host="0.0.0.0", port=int(os.getenv('PORT', 80)), threaded=True)
remember to "import os" at the top
hope this help
My application is in the following structure:
└── wsgi_home
├── __init__.py
├── __init__.pyc
└── main.py
I import everything from a folder called entry:
from entry.main import main as flask_app
app = flask_app(None, is_wsgi=True)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9080)
Every time I run this application using gunicorn I get:
[2022-02-11 09:37:07 +0000] [1406] [INFO] Starting gunicorn 19.10.0
[2022-02-11 09:37:07 +0000] [1406] [INFO] Listening at: http://0.0.0.0:9080 (1406)
[2022-02-11 09:37:07 +0000] [1406] [INFO] Using worker: sync
[2022-02-11 09:37:07 +0000] [1410] [INFO] Booting worker with pid: 1410
Failed to find application object 'main' in 'wsgi_main'
[2022-02-11 09:37:07 +0000] [1410] [INFO] Worker exiting (pid: 1410)
[2022-02-11 09:37:07 +0000] [1406] [INFO] Shutting down: Master
[2022-02-11 09:37:07 +0000] [1406] [INFO] Reason: App failed to load.
How do I fix this issue?
plz changes in your file:-
app = Flask(name)
app.run(debug=False)
Procfile
web: gunicorn app:app
so I'm trying to deploy my Dash app onto Azure using Azure Web App. When I use the "Github Actions" method of deployment, I get the following (I even made my repository public for this):
Package deployment using ZIP Deploy initiated.
##[error]Failed to deploy web package to App Service.
##[error]Deployment Failed with Error: Error: Failed to deploy web package to App Service.
Unauthorized (CODE: 401)
##[warning]Error: Failed to update deployment history.
Unauthorized (CODE: 401)
App Service Application URL: http://my-site.azurewebsites.net
I've also tried deploying with "Kudu App Build" instead of the Github Actions and that "deploys successfully", giving me a status of "Success(Active)" but once I go to my website it fails, then when I go to Diagnosis and solve problems in the azure portal I receive the following error:
2020-06-05T14:32:08.567155259Z
2020-06-05T14:32:08.567159059Z Documentation: http://aka.ms/webapp-linux
2020-06-05T14:32:08.567163159Z Python 3.8.0
2020-06-05T14:32:08.567166959Z Note: Any data outside '/home' is not persisted
2020-06-05T14:32:09.126144120Z Starting OpenBSD Secure Shell server: sshd.
2020-06-05T14:32:09.177989757Z Site's appCommandLine: gunicorn --bind=0.0.0.0 --timeout 600 application:app
2020-06-05T14:32:09.179066899Z Launching oryx with: -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn --bind=0.0.0.0 --timeout 600 application:app'
2020-06-05T14:32:09.289253728Z Oryx Version: 0.2.20200114.13, Commit: 204922f30f8e8d41f5241b8c218425ef89106d1d, ReleaseTagName: 20200114.13
2020-06-05T14:32:09.315423056Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-06-05T14:32:09.322220623Z Build Operation ID: |mqhAw8K+i4s=.a5925a0c_
2020-06-05T14:32:09.937709104Z Writing output script to '/opt/startup/startup.sh'
2020-06-05T14:32:10.656204831Z Found virtual environment .tar.gz archive.
2020-06-05T14:32:10.656991662Z Removing existing virtual environment directory /antenv...
2020-06-05T14:32:10.667494675Z Extracting to directory /antenv...
2020-06-05T14:32:42.888599159Z Using packages from virtual environment antenv located at /antenv.
2020-06-05T14:32:42.891102058Z Updated PYTHONPATH to ':/antenv/lib/python3.8/site-packages'
2020-06-05T14:32:44.966320399Z [2020-06-05 14:32:44 +0000] [42] [INFO] Starting gunicorn 20.0.4
2020-06-05T14:32:44.973255871Z [2020-06-05 14:32:44 +0000] [42] [INFO] Listening at: http://0.0.0.0:8000 (42)
2020-06-05T14:32:44.974184808Z [2020-06-05 14:32:44 +0000] [42] [INFO] Using worker: sync
2020-06-05T14:32:45.047728498Z [2020-06-05 14:32:45 +0000] [44] [INFO] Booting worker with pid: 44
2020-06-05T14:32:50.315649084Z Application object must be callable.
2020-06-05T14:32:50.321677821Z [2020-06-05 14:32:50 +0000] [44] [INFO] Worker exiting (pid: 44)
2020-06-05T14:32:50.630621560Z [2020-06-05 14:32:50 +0000] [42] [INFO] Shutting down: Master
2020-06-05T14:32:50.630656561Z [2020-06-05 14:32:50 +0000] [42] [INFO] Reason: App failed to load.
That was the application error, here is the container error
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-06-05T14:30:22.831Z INFO - Initiating warmup request to container my-site_0_06a70784 for site my-site
2020-06-05T14:30:38.890Z INFO - Waiting for response to warmup request for container my-site_0_06a70784. Elapsed time = 16.0594968 sec
2020-06-05T14:30:54.492Z INFO - Waiting for response to warmup request for container my-site_0_06a70784. Elapsed time = 31.6616936 sec
2020-06-05T14:31:09.663Z ERROR - Container my-site_0_06a70784 for site my-site has exited, failing site start
2020-06-05T14:31:09.695Z ERROR - Container my-site_0_06a70784 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2020-06-05T14:31:10.217Z INFO - Stopping site my-site because it failed during startup.
2020-06-05T14:31:11.646Z INFO - Starting container for site
2020-06-05T14:31:11.647Z INFO - docker run -d -p 4040:8000 --name my-site_0_9c00d1f9 -e WEBSITE_SITE_NAME=my-site -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=my-site.azurewebsites.net -e WEBSITE_INSTANCE_ID=b78e390e9ef390f579e4e316c4d4ea6c7f187e4af48b856ebd3562fda3c5ef4f appsvc/python:3.8_20200101.1 gunicorn --bind=0.0.0.0 --timeout 600 application:app
Here is what my application.py looks like (I've tried several variations of this to no avail):
import app as application
app = application.app
if __name__ == "__main__":
app.run_server(debug=False)
And at the top of my app.py file I have:
app = dash.Dash(__name__)
This is my requirements.txt:
bs4==0.0.1
dash==1.12.0
dash-table==4.7.0
Flask==1.1.2
numpy==1.18.0
pandas==1.0.4
requests==2.12.4
Lastly, this is the startup command I use in the Configuration->General Settings->Startup Command
gunicorn --bind=0.0.0.0 --timeout 600 application:app
The application you should run when deployment is dash.Dash.server(in your case it's app.server), it's the underly Flask application. So, you have to update the second line of your application.py to this:
app = application.server
See more in Dash docs.
Since yesterday GAE is ignoring my entrypoint in the app.yaml
My app.yaml:
runtime: python37
entrypoint: gunicorn -k eventlet -b :$PORT main:app
Leads to the following log output:
2019-04-24 07:39:58 default[20190423t203005] [2019-04-24 07:39:58 +0000] [8] [INFO] Starting gunicorn 19.9.0
2019-04-24 07:39:58 default[20190423t203005] [2019-04-24 07:39:58 +0000] [8] [INFO] Listening at: http://0.0.0.0:8081 (8)
2019-04-24 07:39:58 default[20190423t203005] [2019-04-24 07:39:58 +0000] [8] [INFO] Using worker: threads
But the worker should be eventlet not threads.
This is actually an issue with Google App Engine as far as we can tell. Configured entrypoint is being ignored. Incident started yesterday. Our best guess is it's caused by an update to the process by which configuring the gvisor container's entrypoint happens during deploy (may be either App Engine or gVisor broke it).
If you change your logs to show all logs:
you'll see the execution entry point will always be:
Running /bin/sh /bin/sh -c exec gunicorn main:app --workers 1 -c /config/gunicorn.py
We're in the process of filing a ticket. If you can, you should do the same.
Correct me if I am wrong: I can use gunicorn to deploy a django project, for instance I can deploy my app - helloapp in this way:
$ cd env
$ . bin/activate
(env) $ cd ..
(env) $ pip install -r requirements.txt
(env) root#localhost:/var/www/html/helloapp# gunicorn helloapp.wsgi:application
[2017-05-18 22:22:38 +0000] [1779] [INFO] Starting gunicorn 19.7.1
[2017-05-18 22:22:38 +0000] [1779] [INFO] Listening at: http://127.0.0.1:8000 (1779)
[2017-05-18 22:22:38 +0000] [1779] [INFO] Using worker: sync
[2017-05-18 22:22:38 +0000] [1783] [INFO] Booting worker with pid: 1783
So now my django site is running at http://127.0.0.1:8000.
But it will not be available anymore as soon as I close/ exit my terminal. So how can I have it stayed connected to the port 8000 even if I have closed my terminal?
As with any long-running process, you need to run it as a service under some kind of manager. Since you're on Ubuntu, you probably want to use systemd; full instructions are in the gunicorn deployment docs. Note, you will also need to configure nginx as a reverse proxy in front of gunicorn.