EDIT: I found the issue from .pyc files. For some reason some compiler has created .pyc files which contained old code. When I uploaded files to the server, server won't compile .py files. Instead it will run .pyc files uploaded from my computer. I deleted all .pyc files, deployed, and now the server runs fresh code /EDIT
When I run gcloud app deploy I quite often deploy a wrong version of my app. My app is running on GAE standard environment is written using Python 2.7.
I can easily reproduce the problem by having one of my urls return a hard coded string, for example "test1". Now when I change this between deployments, I quite often receive a previously written string from the endpoint.
When running the app on the local server the changed return string is correct, but after deploy the string can be from an earlier version.
I have to deploy my app to both test and production environments and I am worried about deploying wrong code. When deploying the gcloud console correctly shows that only 2 files are being uploaded (if I have only edited the static return string).
I have tried killing all other versions from the App Engine console.
Also tried using flag --stop-previous-version.
I have also tried adding new endpoints and after gcloud says the deployment was successful these endpoints are still inaccessible.
How can I make sure my current code gets deployed correctly?
1) Make sure you change the version number in app.yaml
2) Go to
https://console.cloud.google.com/appengine/versions?project={your project id}
to tell GCP which version to serve, and which to stop.
Your note regarding the pyc files suggests that you may have customized your app.yaml's skip_files section and accidentally wiped its default values in the process, which would normally prevent deploying pyc (and other potentially interfering files) to GAE. From that doc (emphasis mine):
The skip_files has the following default:
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
The default pattern excludes Emacs backup files with names of the form
#...# and ...~, .pyc and .pyo files, files in an RCS revision control directory, and Unix hidden files with names beginning with a
dot (.).
To extend the above regular expression list, copy and paste the above
list into your app.yaml and add your own regular expressions.
So to no longer worry about manual cleaning the .pyc files make sure you still have the above patterns in your skip_files section, in particular - ^(.*/)?.*\.py[co]$ which is the one responsible for the .pyc files.
Related
Im trying to upload to my server a static file that contains photos from a previous version which has been overwritten since then (same name, different image). I think the upload skips these files, how can I make it go over these files?
Increase the deployment verbosity using the --verbosity option for gcloud app deploy and you'll see exactly which files are skipped and which aren't (you may need to modify them again since you already attempted to deploy the most recent versions).
But it could very well be a caching issue, see App Engine: Static Files Not Updating on Deploy.
I am starting to use modules in my python Google Appengine app.
I managed to test my configuration locally (on the dev server) and everything is working fine.
I want to test my changes on a side version online and didn't find a place that states whether the dispatch configuration will affect only my side version or my main serving version also (that's dangerous).
I know that cron.yaml is not a version specific file, how about dispatch.yaml?
Is it safe to deploy a side version with a dispatch file?
Thanks
From Configuration Files:
Optional application-level configuration files (dispatch.yaml,
cron.yaml, index.yaml, and queue.yaml) are included in the top
level app directory.
So no, you can't test a dispatch.yaml file change without affecting all versions of all your app's services/modules since it's an app-level configuration.
To be able to test app-level config file changes I'm using an entirely separate application as a staging environment.
Hi I am a newbie to Django AND Python. Working currently on a dummy project using Django 1.9. So following the excellent Django Documentation I could complete the deployment using apache/mod_wsgi and it is running on a test web server on my local machine.
But I am wondering about the Python source files :
I have given the path to my development directory - say /Python-labs/mysite/ to mod_wsgi and apache configuration ( httpd.conf ) files. This development directory obviously contains all the .py files - the Python source files.
No-where in the documentation i found any mention to remove the source files etc. So I googled but could not get anything as a standard step to remove source files from the production deployment.
Got this - the closest to what I am asking for :
Django Remove Source Files
Django Deployment Without Source Code
but again it does not make it crystal clear about the questions below :
My Questions :
Is it a standard step in Django deployment to remove source files or not ?
( or Did I miss something very obvious from the documentation ? )
Is it Ok if we put .py files on production server ? Or is it intended that way ?
Thanks a lot in Advance !
It is typical to deploy source files with Django. As long as the project is set properly (__init__.py included for all project/app directories) then Django will compile .py files to .pyc.
To answer your questions -
1. Don't serve your production files directly; use a good VCS to push files to your production server or, if quick and dirty, copy your project to your production server. But uncompiled .py files are standard for most Django projects.
2. Yes.
For more insight, this question may help.
I know this issue has been discussed before, but I am struggling to find a starightforward explanation of how to approach configuration between local development and production server.
What I have done so far: I had one my_app_config.py file that had a section with machine / scenario (test vs production) sections I could just comment out. I would develop with my local machine path hardcoded, test database connection string, my test spreadsheet location, etc. When it comes time to deploy the code to the server, I comment out the "test" section and uncomment the "production section". As you may guess, this is wrought with errors.
I recently adopted the Python ConfigParser library to use .ini files. Now, I have the following lines in my code
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read(os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'settings',
'my_app_config.ini')))
database_connect_string_admin = config.get('Database', 'admin_str')
The problems with this are many...
I need to have the import at the top of every file
The filename my_app_config.ini can't change. So, I rely on comments within the content of the .ini file to know which one I'm dealing with. They are stored in a folder tree so I know which is which.
notice the path to the config file is defined here. So, depending where the python file lives in the tree structure dictates if I get a copy / paste error.
I tried to set environment variables at the beginning of the program, but all the imports for all modules are performed right away at code launch. I was getting "not found" errors left and right.
What I want: To understand how to keep all the configurations stored in one place that is not easy to lose track of what I am doing. I want an easy way to keep these configuration files (ideally one file or script) under version control (security is a whole other issue, I digress). I want to be able to seamlessly switch contexts (local-test, local-production, serverA-test, serverA-production, serverB-test, serverB-production) My app uses
my_app_config.ini read by my parser
uwsgi.ini read by the uwsgi application server emperor
web_config.py used by the flask application
nginx.conf symlinked to the web server's configuration
celery configuration
not to mention different paths for everything (ideally handled within the magic config handling genie). I imagine once I figure this out I will be embarrassed it took so long to grasp.
Are Environment variables what I am trying to do here?
You have to try `simple-settings. It will resolve all you issues. One way set environment variable
in development
$ export SIMPLE_SETTINGS=settings.general,settings.development
$ python app.py
in production
$ export SIMPLE_SETTINGS=settings.general,settings.production
$ python app.py
You can keep `` development.pyandproduction.py` not in a repository for security reasons.
Example
settings/general.py
SIMPLE_CONF = 'simple'
app.py
from simple_settings import settings
print(settings.SIMPLE_CONF)
The documentation indicated many more features and benefits.
I am following a step-by-step tutorial blog on the flask micro framework for python.
I bumped into an issue, when they require me to 'setup' a configuration file in the root of the application folder, so it can easily be accessible if needed.
They called it config.py.
My question is, if the local path to my application is /home/test/application1/, should I create the file inside the ./application1/ directory? What gets me confused in this somewhat obvious question is that I did a quick search for other config.py files in the local directory inside /home/test/application1/, where I found 4 other files. There were in the following directories:
/home/test/application1/flask/lib/python2.7/site-packages/flask/testsuite/config.py
/home/test/application1/flask/lib/python2.7/site-packages/flask/config.py
/home/test/application1/flask/local/lib/python2.7/site-packages/flask/testsuite/config.py
/home/test/application1/flask/local/lib/python2.7/site-packages/flask/config.py
So should I create a new config.py file in the directory that I first mentioned or should I add some lines in one of the previously created config.py files.
Here is the source of the step-by-step tutorial:
It is at the beginning, right after Configuration.
Unlike other frameworks, Flask does not have a lot of rules, in general you can implement things in the way they make sense to you.
But note that the other config.py files that you found are all in the virtual environment, and are all scripts that come with Flask. They have nothing to do with the application configuration.
I wrote the tutorial you are following. In the tutorial I'm putting config.py outside of the application package. This is what I like, I consider the configuration separate from the application. My thinking is that you should be able to run the same application with different configuration files, so that for example, you can have a production configuration, a testing configuration and a development configuration, all different.
I hope this helps.