Deployment of static directory contents to google app engine - google-app-engine

I've deployed my first GAE application and I am getting "TemplateDoesNotExist" exception at my main page. It feels like my static directory content is not uploaded to GAE.
Isn't it possible that I update (appcfg.py update myapp/) all my files including the static ones and run it standalone on myappid.appspot.com ?
by the way here you can see the problem:
http://pollbook.appspot.com
PS: my app works perfect locally

Your templates should not be stored in a directory that you refer to as "static" in app.yaml. Static directories are for literally static files that will be served to end users by the CDN without changing. These files cannot be read by the templating engine. It works locally because the dev_appserver does not precisely emulate the production server.
Put your templates in a different directory like /templates or something. You do not need to refer to this directory in your app.yaml.

Related

Are Google App Engine deployed files private by default?

Excuse the naivety here, I'm new to GAE, and haven't been able to find much in the available literature / answers about the deployed filesystem's public status...
My question is quite simple:
Assuming a standard app.yaml config, are the files that get pushed to GAE with gcloud app deploy publicly inaccessible, unless exposed by (in the example of Node.js) an express endpoint?
I want to make sure sensitive data like key files (for reference in code) in our deployed bundle are not exposed, and that the local filesystem of a deployment is only accessible privately by the code itself.
Unless you work with the “static” files & dir directives no data should be made visible to outside users by Google.
Authenticated Admin users (youself) can see all files deployed to the server in the admin console unless you disable “code downloads” (which was available on legacy App Engine but seems to be removed now).

How do you undeploy 'helloworld.go' from App Engine Quickstart, and instead point to a html in bucket?

I'm trying to learn about hosting websites on GCP, and have just finished the App Engine Quickstart, which gave me a working appspot.com domain which runs off helloworld.go.
But now I want to try a pre-made html template (contains .html, .DS_STORE, and css/fonts/images/js folders) that I have tested to be working locally.
Following the "Hosting a Static Website" tutorial, I have uploaded the html template folder into my bucket "... .appspot.com", and enabled the entire bucket to be publicly viewable/readable. Then I disabled and re-enabled the App Engine session to try and get it to reset.
However, the URL still loads the default "Hello, world" plaintext used in the Quickstart.
I may have a pretty fundamental misunderstanding of how web hosting on App Engine works. Could someone please check if what I'm trying to do is reasonable, and if so, how do I actually do it?
EDIT: I have also had success deploying other code samples included with Quickstart, but still haven't figured out how to ignore those and deploy directly from bucket.
I understand that you have a static HTML page in your Google Cloud Storage bucket and you want that app your App Engine application points to that html page.
It is possible to do that, just taking the files from the bucket and then printing the content, but if you just want a static page, the best option could be the following:
Create a bucket and upload ONLY the static template in that bucket, please, don't upload sensitive information there.
click in the three dots at the right to edit the permissions of the bucket.
give the "Storage Object Viewer" role to the member "allUsers"
enter into your bucket and click into the the public link of your index.html
The link will be something like: https://storage.googleapis.com/< YOUR_BUCKET >/index.html
EDIT
As requested by the OP, the link https://storage.googleapis.com/< YOUR_BUCKET >/index.html it's really long and not too friendly, for that reason this is a small tutorial of how to attach a custom domain to your Google Cloud Storage bucket.
Create a domain, you can use Google Domains or if you just want a free domain, you can use something like Freenom and get your domain for free.
Go to Google Search Console and follow the small tutorial, this is just to verify that your domain it is actually yours. It will ask you to upload a file into your domain. To do this it's as simple as
2.1. pointing your domain to the external IP of a Compute Engine Instance
that you own with apache installed and the file in there.
2.2. You can use the pre-made Compute Engine instance with lamp in the
Marketplace.
2.3. Just upload the file provided by Google in
/var/www/html/ inside of your new instance.
2.4. Once your verification is done, delete this Compute Engine instance to
not to waste money.
3.Create a bucket with the same name as your verified domain, that means, if your domain is "larrycai.tk", your bucket should be called "larrycai.tk". If the "2." was made correctly it will let you create that bucket, if not, it will show you an error message saying that you need to verify that you are the owner of that domain.
4.Go again to your domain provider (in my case, freenom) and in the DNS menu add this record:
as you see, you need to add a CNAME record and the target will be c.storage.googleapis.com, if it ask you to set a name, just add your domain "larrycai.tk".
5.(Optional) If you want to redirect your bucket url to a main file (like index.html for example), just run this command:
gsutil web set -m index.html gs://[your_bucket]
Now, with all theses steps, you should be able to see your static web page in your own domain.
There are different ways in deploying a site using Google Cloud Platform. The "Hosting a Static Website" tutorial refers to hosting a static website using Cloud Storage only.
To host a static website using App Engine, you will need to edit the app.yaml file of your application and create request handlers that will point to your static website.
As you are using the go qwikstart tutorial, I'm going to assume that your directory looks something like this:
helloworld
|-- app.yaml
|-- helloworld.go
|-- helloword_test.go
Create a new folder within the helloworld directory, in this example, I'm calling it www
Move your static files to the folder you just created, in my case the www folder
In the app.yaml file, add the following, replacing www with your folder name:
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
Deploy your application using gcloud app deploy.
For more info, Google provided documentation on serving static content for:
Go
Python
PHP
Node.js
Java
.NET
Ruby

Google Clouds Appengine storage

Im new to the Appengine and I can't seem to work out the static file serving. I have read through all the official related docs.
I understand that tagging the directory or files as static in the app.yaml will "host them separated from your source". However I can't find any more info.
After the app engine deployment, I see two GCS buckets. The default bucket "projectname.appspot.com" and a staging bucket "staging.projectname.appspot.com". My project has many static files, which are all served correctly however the default bucket is totally empty. Where are these files actually stored?
I can find very little information on what exactly the staging bucket is and how its used other than its "for temporary files" which are deleted after a week. This staging bucket seems to hold both the source and static files however all the file names are hashed so its not immediately obvious.
My question is where exactly do app engine static files go? Where and how are they stored? My app is a Django based app if its relevant.
The static files aren't saved to your app's buckets, but in Google's infra dedicated for directly serving static content, which isn't accessible to you like your app's buckets.
See also the accepted answer to Does Google App Engine use google CDN to distribute static resources?
Normally you shouldn't need to worry about where the static files are stored - as long as the deployment is successful you can trust Google will serve them for your app.

Do Google App Engine app instances restart when updating an app where only static files changed

Let’s assume I have an app that has some static files and some code. The static files are described in app.yaml as such. I have uploaded my app for the first time.
If I now just change static files and re-upload my app will GAE restart my instances? If no this is what I expected and all I was wondering. If no, is there a way—apart from using a 3rd party CDN for the static files— to upload static content without restarting running instances?
If you're using the SDK uploader it will update the entire content, both static files and code of the module(s) being uploaded and it will restart the instances matching the default version of the respective module(s).
You could, if you want, just change the version of the module - the existing instances will be left alone, serving requests coming to urls formulated specifically for those versions. But all new requests coming to the default version (the latest uploaded) will be served by the new instance(s).

Datastore Location with Google App Engine / Java

How can I customize the location of the datastore file while working with GAE/J.
The option --datastore_path doesn't seem to work with GAE/J.
And if it is possible, what option do I use in the maven-gae-plugin.
I assume you mean while running the dev app server locally. Try the --generated_dir option with <sdk>/bin/dev_appserver.sh:
--generated_dir=dir Set the directory where generated files are created.
The generated files include the local datastore file.

Resources