I'm trying to provide a .well-known folder under my Google App Engine Application I'm using the standard environment and the python27 runtime.
with a web-app-origin-association.json file to try the Progressive Web Apps as URL Handlers
origin trial from chrome.
I've added the following code to my app.yaml file under handlers:
# .well-known Ordner
- url: /.well-known/(.*)
static_files: well-known/\1
upload: well-known/.*
The folder in my project is named well-known without a dot cause I've read that there are problems when using a folder Name with a dot at the start of the foldername.
But the url https://example.com/.well-known/web-app-origin-associate.json isn't available instead it works without the dot:
What do I have to change in order to make it work under https://example.com/.well-known/web-app-origin-association.json?
You can use the workaround documented at "Make skip_files rule explicit and tweak to allow .well-known/* to upload":
^(.*/)?\.(?!well-known(?:/|$)).*$
You many want to migrate to Python 3 as described in the guide:
Starting on January 1, 2020, the Python community will no longer
update, fix bugs, or patch security issues for Python 2.7. We
recommend that you update apps that are still running in the Python 2
runtime of the App Engine standard environment to the Python 3 runtime
as soon as possible.
The best way i found out about is to just do it like that:
- url: /\.well-known
static_dir: .well-known
secure: always
and use the python39 runtime.
Related
We have a web application (frontend) using React created from Create React App. The app is running on Google Cloud Platform App Engine Standard. Our web application is code splitted. Each page is then loaded on user navigation.
It's working really well. The issue we have is for example user A is on the app home page. We deploy a fix that change the chunk file name. The user A then try to access another page and then got the error Loading chunk * failed. The url to get the file is now returning a 404 because the file has been replaced by some new chunk files.
It's a frequent problem as I can see during my research but I didn't find a solution that apply for Google App Engine.
Here's an article that explain the problem / solution: https://mitchgavan.com/code-splitting-react-safely/
I would like to use the solution "Solution 1: Keep old files on your server after a deployment" but I can't see how to do this using GCP ...
Here's the app.yaml file
service: frontend
runtime: nodejs14
env: standard
instance_class: F1
handlers:
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$
- url: /.*
static_files: build/index.html
upload: build/index.html
We have the following dispatch file (* for masked url)
dispatch:
- url: "*"
service: frontend
- url: "www.*"
service: frontend
Haven't tried this before but see if it makes sense/works.
We have a blog article about downloading your source code from GAE. It contains an explanation of where your source is stored when you deploy (a staging bucket), how long it stays there and how you can modify how long it stays before Google automatically deletes it.
When you deploy to GAE, gcloud only deploys files that have changed (it doesn't deploy those that haven't). Since you now have 'new' files because new hashes were generated, the older files no longer exist on your local machine. I do not know if Google will automatically delete those files from the staging location in bullet 1 above.
My proposal here is that you follow the steps in the blog article (from bullet 1) and alter (change) how long the files are retained in your staging bucket. Another option is to check the retention policy tab and see if you can change the rule so the files don't get deleted. If you're able to alter how long the files remain or the retention policy, it just might solve your problem. Let me know if this works
I know you can declare env_variables in your app.yaml as described in the app.yaml documentation. However, is it possible to include environment variables from your local environment into app.yaml when deploying.
As an example of what I'm trying to accomplish
# in app.yaml
runtime: python27
api_version:1
threadsafe: true
service: {{ $AN_ENVIRONMENT_VARIABLE }}
Yes, you can use includes: to specify an array of files to be included. And in the included file, you can specify env_variables: just like you do in app.yaml.
Example: app.yaml:
runtime: go
api_version: go1
env_variables:
FIST_VAR: myFirstVar
includes:
- credentials.yaml
credentials.yaml:
env_variables:
SECOND_VAR: mySecondVar
No, no such templating support exists for the app.yaml configuration files.
Side note: the app.yaml file is not only used to extract deployment instructions information, it's also used to configure the operation of the respective service on GAE. Making the service name configurable in such manner doesn't make a lot of sense unless the services being deployed are identical in every aspect (other than their name) - highly unlikely.
One possible approach for environment-specific deployment would be to have different version control branches for the app code, one for each environment, each having the desired app.yaml content.
Another one would be to wrap the deployment command in a script and perform the enviroment substitutions inside that script.
As for passing credentials info to the app a clean, straight-forward solution is not yet available. But approaches exist:
GAE: best practices for storing secret keys?
How to set environment variables/app secrets in Google App Engine
Google app engine: Best practice for hiding Rails secret keys?
How to handle sensitive configuration information when deploying app-engine applications?
from what I understand, the app.yaml file in a Google App Engine project, can serve a file as a 'home' page. When I navigate to my domain, however, it always gives me a 404. My app.yaml is in the war directory. This is what my app.yaml looks like:
application: therealtest
version: 10
runtime: python
api_version: 1
handlers:
- url: /
static_files: site/index-static.html
upload: site/index-static\.html
What I am expecting it to do is to display the page index-static.html when I go to the domain of the site, but it does not. Is this not the correct way to do this? Thank you.
Is the site directory inside your war directory? It should be, given that is where you said your app.yaml file is.
FWIW, putting your web app in a war directory implies to me that you're thinking in Java terms, but your app.yaml snippet tells us you're using Python. In Java, WAR stands for Web Archive, which is a zip file with a certain required directories and files.
goolge engine app with default url - http://6.version.myapp.appspot.com/ works, but http://6.version.myapp.appspot.com/test gives me a :
404 Not Found.
The resource could not be found.
my app.yaml file is as follows :
application: myapp
version: 6
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /test
script: pythonfile.py
- url: /.*
script: pythonfile.
testing locally works fine : localhost:8080 and localhost:8080/test - both work fine.
Above the number 6 just happens to be a version no. So I am guessing for any other number the problem will happen. If I make the 6th version the default and access the url without version no, it works fine with and without the '/test' extension on the default url.
"6.version.yourapp.appspot.com" is not accessing version "6" of your app, it's accessing the version called "version". Thanks to wildcard subdomains, if that version doesn't exist, the request goes to your primary version.
I suspect you're thinking of the old version naming scheme, under which version 6 would be "6.latest.yourapp.appspot.com"; now it's simply "6.yourapp.appspot.com".
Are you sure your handler should look like that if you've got python 2.7? I think it should be eg handler.app instead of handler.py and if you follow the guestbook example from the SdK it probably does exactly what you are trying to do. You can also read Nick Johnson's blog post from blog.notdot.net how to upgrade to python 27 the official way - I don't think you put the script names in your app.yaml, I think it's supposed to look like
pythonfile.app
or
pythonfile.application
I hope this helps.
404 Not Found is from errors in app.yaml file, not your python coding. Look into the 'logs' of your appengine console and you'd find more information relating to this error. A good place to start is with GAE's Python 2.7 introduction page since it is too long to list here.
Changes aren't numerous though it can easily break your app if u miss a step (as it did to mine).
I have created an app in Google App Engine and it's working pretty well in a conventional browser. The main script is called example.py (because I have been hacking off an example and I never changed it). It calls a html file and passes in variables as you would expect.
Now I want to develop a new version that's more suitable for mobile devices. To do this, I wrote a new python script called example_mobile.py. It's similar to example.py except that it calls a different html file with a different stylesheet. Inelegant I know but I thought it would be easy to implement through the app.yaml file.
Here is my app.yaml file:
application: (my application id string)
version: 1
runtime: python
api_version: 1
handlers:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
- url: /stylesheets
static_dir: stylesheets
- url: /javascript
static_dir: javascript
- url: /images
static_dir: images
- url: /mobile/.*
script: example_mobile.py
- url: /.*
script: example.py
www.(my domain name).com pulls up the output from example.py no problem. I was hoping that www.(my domain name).com/mobile would pull up the output from example_mobile.py but it didn't work. Also tried www.mobile.(my domain name).com but no luck. Tried leaving off the /.* at the end of /mobile but that didn't help either. I switched example_mobile.py and example.py to check that it wasn't the python and I got the expected result so there's definitely something wrong with how I'm formatting and using the app.yaml file. Can't seem to find a similar use case in the GAE docs so any help would be much appreciated.
Thanks,
Dessie
To trigger the /mobile/.* route you should visit www.(my domain name).com/mobile/
One simple suggestion is to have a single example.py matched by /.* leaving the routing part to the WSGIApplication class.
application = webapp.WSGIApplication(
[('/mobile', example.MobileHandler),
( '/', example.MainHandler)],
debug=True)
One rule of thumb here is that on app.yaml you should have different routes for different applications or different components.
Is mobile a different application/components or just the same application with a different theme and some lighter features?