Google App Engine, can people download my source code?? (with PHP) - google-app-engine

I'm new to GAE, and have big doutbts on how it works. Mainly the app.yaml configuration file. If i have this structure for example:
/
/index.php
/scripts/script.php
On app.yaml I should write something like this for example (the basic to work), right?
application: myapp
version: 1
runtime: php
api_version: 1
handlers:
- url: /
script: index.php
- url: /scripts/script.php
script: scripts/script.php
Is this correct? And if i have a lot of scripts on the scripts directory, should i put an entry for all of them?
I ask this (I think its a really stupid question but i want to be sure) because i have realised that if i put the scripts directory as a static_dir, like:
- url: /scripts
static_dir: scripts
... if i go to the URL of that file (http://mydomain.com/scripts.script.php) i can download the source code.
So I guess that static_dir is not for accessing a whole directory's content, and as it's name says... is just for static content like photos for example, right? so for each script i should write a line on the app.yaml to be accesible?
Sorry about my stupid question, my english is not so good and i'm new at this so i have this doutbt ;)
Thanks a lot in advance!

You can find some detailed examples here of PHP and app.yaml here:
https://developers.google.com/appengine/docs/php/config/appconfig
If you have a large number of *.php files that you want to make executable, you can use wildcards. For example:
- url: /(.+\.php)$
script: \1
Will map anything URL ending in .php to the equivalent filepath. So
http://myapp.appspot.com/some/directory/file.php
will map to
some/directory/file.php
in your app's directory.

Don't put anything in static directories that you don't want the world to see. static directories are intended as a fast shortcut for serving things like images, CSS, and JavaScript.
.php files (or .py files if you're using Python) need to be 'executed' (evaluated) on the server (App Engine) side. Putting them in a static_dir puts them out of reach of the execution environment, which isn't what you want.

Related

How/where does Google App Engine cache YAML (changing `script`)?

Originally I had this in my app.yaml:
runtime: python39
- url: .*
script: main.app
I changed the script filename to gae.py and so updated app.yaml to thus:
runtime: python39
- url: .*
script: gae.app
The new version no longer starts up:
ModuleNotFoundError: No module named 'main'
I have tried changing the url but it's still trying to use a now-non-existent main.py to load the WSGI application. When I view the source of the version I see the correct app.yaml and file structure; I don't see main mentioned anywhere.
Any ideas?
The problem is not caching but rather that script is no longer used (and is ignored) in the Python 3 world of Google App Engine standard:
script: Optional. Specifies that requests to the specific handler should target your app. The only accepted value for the script element is auto because all traffic is served using the entrypoint command. In order to use static handlers, at least one of your handlers must contain the line script: auto or define an entrypoint element to deploy successfully.
(https://cloud.google.com/appengine/docs/standard/python3/config/appref#handlers_element)
The fix is to override entrypoint which defaults to:
/bin/sh -c exec gunicorn main:app --workers 2 -c /config/gunicorn.py
(https://cloud.google.com/appengine/docs/standard/python3/runtime#application_startup)

Google App Engine skip_files to skip entire folder

I'm editing the app.yaml file so that all files within a particular folder are not uploaded to GAE.
Following the instructions found here, I've tried the following:
skip_files:
- /tester/^(.*/)?\.^(.*/)?$
skip_files:
- /tester/.*
skip_files:
- /tester/^(.*/)?#.*#$
None of the above seems to work, as new files added to the folder tester keep being pushed to GAE.
If your directory is nested inside the project:
skip_files:
- ^(.*/)?.*/some_dir/.*
Seems that this works:
skip_files:
- ^tester/*.*
Based on the results I got, it seems that:
the initial / should not be included.
the caret (^) is needed to tell the system where the string to interpreted begins;
to include any file, the notation *.* seems to work.
Any comment is welcome!

Project Directory Does Not Contain app.yaml

I'm following the instructions here https://console.developers.google.com/start/appengine
I've downloaded and unzipped the project file from that page - it's the python and flask one. When I get to the instruction dev_appserver.py appending-try-python-flask it gives the error.
google.appengine.tools.devappserver2.errors.AppConfigNotFoundError: "." is a directory but does not contain app.yaml or app.yml
It most certainly does contain an app.yaml file. It looks like this.
application: hello-flask-app-engine
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
Unlike this post Uploading a static project to google app engines mine doesn't have any skip files lines to delete.
There is a README.md that mostly follows the Google Dev web page, except that instead of downloading the project from that page it instructs to git clone https://github.com/GoogleCloudPlatform/appengine-python-flask-skeleton.git and that doesn't exactly match the zip file I downloaded.
The requirement.txt file says Run 'pip install -r requirements.txt -t lib/' but Windows 7 says pip is not a recognized command.
Is my app.yaml not correct? Why would it say it doesn't exist?
Simply closing the command prompt window and reopening it made it work. I don't know how or why.
You may be mis-typing appengine-try-python-flask (the real name) as appending-try-python-flask (which is what you show in your question).
If that's not the case, can you please show the effects of dir appengine-try-python-flask and dir appending-try-python-flask from the directory (AKA folder) you're now trying to run dev_appserver.py from?
probably you use py-charm, you need to add to configuration in line 'Working directory' the path of project like: C:\Users\user\Desktop\projects\water
It's repose to work

GAE + Github = can't get Push-to-Deploy to actually work

I'm trying to get Push-to-Deploy to work with GAE through GitHub set-up as the code repo source.
This is now Day 3 and I've run into several bugs like:
Creating a Release pipeline failing for no apparent reason
Getting Error 500 when I finally managed get the source pulled over to GAE
Changes in Github are propagated to GAE (they're visible under Source code -> Browse), but the Release routine isn't run and (understandably so) the app is not being served at the web address.
I tried creating several new projects and I exhibited various versions of the bugs above.
Here's where I'm at now:
I created a brand new project, setup Github as my repo, created a Release Pipeline and did a push afterwards (to Github) just to try and trigger the Deploy routine to no avail. The code tree is visible under Source code -> Browse, along with commit dates and so on, but the Release pipeline isn't run.
App ID is skillful-signer-695 and the platform of choice is php.
Any ideas?
Update:
Nearly 24 hours after I set-up the project and did a test commit to trigger the Release pipeline, it finally got executed! Its result is marked as 'SUCCESS.
Now if I try and hit the project's URL I get a:
Error 500 - The server encountered an error and could not complete your request.
Any help will be greatly appreciated!
Update 2:
I got some more info by looking at the logs:
A problem was encountered with the process that handled this request, causing it to exit. This is likely to cause a new process to be used for the next request to your application. (Error code 204)
Perhaps there's something wrong with my (quite simple) app.yaml?
application: skillful-signer-695
version: 1
runtime: php
api_version: 1
threadsafe: false
handlers:
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true
# Serve php scripts.
- url: /.*
script: index.php
It seems a lot of different people are experiencing the same thing and it has to do with app.yaml, but I can't figure out what I'm doing wrong... The above is pretty much pasted from the example in the docs.
we were finally able to get this working - turns out there were some issues with the codebase for the website, which were leading to the 500 error (that's Code Igniter for you, I guess).
In addition, we had to add some lines to the app.yaml for css and fonts to show up. Here's what we ended up with:
application: skillful-signer-695
version: 1
runtime: php
api_version: 1
threadsafe: false
handlers:
- url: /assets/(.*\.(css|js|ttf))$
static_files: assets/\1
upload: assets/.*\.(css|js|ttf)$
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true
# Serve php scripts.
- url: /.*
script: index.php
Aside from the issues on our end, I believe we ran into several GAE bugs (inconsistent pull times from GitHub, Dashboard issues, incomplete docs, etc.) which are normal for Beta software, but nasty nonetheless. Thanks for the help!
p.s. We ran something else, which might save somebody some time digging around - if you're trying to use sockets (for example to send an email via SMTP from your support form hosted on GAE since the standard PHP mail command doesn't work) you'll find that Sockets are enabled only after you enter your billing info. They don't really charge you anything for light use, but I guess Google considers this a Premium feature.
All the best!
I am having issues with Push 2 Not Deploy feature, because -at least for now- GAE does not resolve git submodules.
If you have submodules or ignoring essential files from git, your application will not work.
For example: I am sending e-mails from GAE and my login_data.py is ignored by git via .gitignore
If you use appcfg.py update --oauth . your login_data.py will be sent. Using push2deploy in a this situation will end up a big error like this:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

Migrating GAE app from python 2.5 to 2.7

I am trying to migrate my app and everything worked fine until I changed in app.yaml
from threadsafe: false to threadsafe: true.
The error I was receiving was:
threadsafe cannot be enabled with CGI handler: a/b/xyz.app
After some googling I found:
Only scripts in the top-level directory work as handlers, so if you have any in subdirectories, they'll need to be moved, and the script reference changed accordingly:
- url: /whatever
# This doesn't work ...
# script: lib/some_library/handler.app
# ... this does work
script: handler.app
Is there any workaround for this(if above research is valid), as I don't want to change my project hirarchy?
You can have your handlers anywhere as long as it's a valid python import path.
My app.yaml is full of entries like
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.application
login: admin
The folders need __init__.py in them to make them work as modules, but you can usually replace any / with .
Alternatively do as Daniel suggest, and note that you'll probably have to mangle the sys.path first to include lib dir and then import handler.
Put a main file in the top-level directory and import all your handlers there, then reference them via that file

Resources