Is Appengine dispatch.yaml file affecting a specific module version? - python

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.

Related

"gcloud app deploy", deploys wrong version

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.

"gcloud app deploy" does not override the static folder

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.

Using different dbs on production and test environment

I want to use a test db on my test environment, and the production db on production environment in my Python application.
How should I handle routing to two dbs? Should I have an untracked config.yml file that has the test db's connection string on my test server, and the production db's connection string on production server?
I'm using github for version control and travis ci for deployment.
Let's take Linux environment for example. Often, the user level configuration of an application is placed under your home folder as a dot file. So what you can do is like this:
In your git repository, track a sample configure file, e.g., config.sample.yaml, and put the configuration structure here.
When deploying, either in test environment or production environment, you can copy and rename this file as a dot-file, e.g., $HOME/.{app}.config.yaml. Then in your application, you can read this file.
If you are developing an python package, you can make the file copy operation done in the setup.py. There are some advantages:
You can always track the structure changes of your configuration file.
Separate configuration between test and production enviroment.
More secure, you do not need to code your import db connection information in the public file.
Hope this would be helpful.

Deploy Django project using wsgi and virtualenv on shared webhosting server without root access

I have a Django project which I would like to run on my shared webspace (1und1 Webspace) running on linux. I don't have root access and therefore can not edit apache's httpd.conf or install software system wide.
What I did so far:
installed squlite locally since it is not available on the server
installed Python 3.5.1 in ~/.localpython
installed virtualenv for my local python
created a virtual environment in ~/ve_tc_lb
installed Django and Pillow in my virtual environment
cloned my django project from git server
After these steps, I'm able to run python manage.py runserver in my project directory and it seems to be running (I can access the login screen using lynx on my local machine).
I read many postings on how to configure fastCGI environments, but since I'm using Django 1.9.1, I'm depening on wsgi. I saw a lot about configuring django for wsgi and virtualenv, but all examples required access to httpd.conf.
The shared web server is apache.
I can create a new directory in my home with a sample hello.py and it is working when I enter the url, but it is (of course) using the python provided by the server and not my local installation.
When I change the first line indicating which python version to use to my virtual environment (#!/path/to/home/ve_tc_lb/bin/python), it seems to use the correct version in the virtual environment. Since I'm using different systems for developing and deployment, I'm not sure whether it is a good idea to e.g. add such a line in my djangoproject/wsgi.py.
Update 2016-06-02
A few more things I tried:
I learned that I don't have access to the apache error logs
read a lot about mod_wsgi and django in various sources which I just want to share here in case someone needs them in the future:
modwsgi - IntegrationWithDjango.wiki
debug mod_wsgi installation (only applicable if you are root)
mod_wsgi configuration guide
I followed the wsgi test script installation here - but the wsgi-file is just displayed in my browser instead of beeing executed.
All in all it seems like my provider 1und1 did not install wsgi extensions (even though the support told me a week ago it would be installed)
Update 2016-06-12: I got a reply from support (after a week or so :-S ) confirming that they dont have mod_wsgi but wsgiref...
So I'm a bit stuck here - which steps should I do next?
I'll update the question regularly based on comments and remarks. Any help is appreciated.
Since your apache is shared, I don't expect you can change the httpd.conf but use instead your solution. My suggestion is:
If you have multiple servers you will deploy your project (e.g. testing, staging, production), then do the following steps for each deploy target.
In each server, create a true wsgi.py file which you will never put in versioning systems. Pretty much like you would do with a local_settings.py file. This file will be named wsgy.py since most likely you cannot edit the apache settings (since it is shared) and that name will be expected for your wsgi file.
The content for the file will be:
#!/path/to/your/virtualenv/python
from my_true_wsgi import *
Which will be different for each deploy server, but the difference will be, most likely, in the shebang line to locate the proper python interpreter.
You will have a file named my_true_wsgi to have it matching the import in the former code. That file will be in the versioning systems, unlike the wsgi.py file. The contents of such file is the usual contents of the wsgi.py on any regular django project, just that you are not using that name directly.
With this solution you can have several different wsgi files with no conflict on shebangs.
You'll have to use a webhost that supports Django. See https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts. Personally, I've used WebFaction and was quite happy with it, their support was great and customer service very responsive.

pyroot folder of a python module

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.

Categories