Get source of Google App Engine published version - google-app-engine

Can I download my App Engine source code from Google?

Update: Google appengine now allows you to download the code
Documentation here.
(Duplicating answer from the duplicate thread)

You can't - App Engine is not a source control system. There are handlers available that will let you download your source code directly, if you set them in app.yaml when you uploaded your app. They can't include files marked static, however, since they are uploaded to a separate location.

Probably not. However, you can create a wrapper script around appcfg.py which will archive your source code and upload it along with everything else, then make that archive available on a protected part of the site.
An example of that is here.

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).

Make epub programmatically in app engine?

I'm developing a web service in App Engine standard environment with Java (servlets).
The idea is that it get info. from Cloud SQL and generate a EPUB programmatically with Siegmann' epub library: http://www.siegmann.nl/epublib
But i'm not sure that how can add things like images or html files (i first will convert the info. from Cloud SQL to HTML), sicen the writer of epub needs a path to a files.
can i download first all resources that need in local directory of app engine and references them?
Or what can i do?
Thank you in advance and sorry for my English.
Option 1:
You can use the /tmp directory of your App Engine instance to store temporary files. See this link.
Bear in mind that files stored in the /tmp folder will only be accessible within the instance that wrote them.
Option 2:
After a quick look to Siegmann' epub library, I have seen that resources can be provided as Byte arrays and the writer fills an OutputStream.
With this in mind, you could use Cloud Storage and it's Java Client Library to download and store the files.
In this Java sample from the docs, you can see that an object is up laded without the need of it being stored in file-system, just passing it as Byte array.
And to download files from Cloud Storage into the memory of your App Engine App, you could use storage.get(BlobId.of(bucketName, objectName)).getContent() to get the object's byte array

Downloading App Engine source code

So it seems from a few SO questions I've seen that this is a problem among other users. Recently one of our head dev's left and I inherited a lot of his projects. One of which, is a website that what seems like lives on an app engine from google cloud platforms. From the App Engine documentation, to download source code you use the appcfg.py download_app command. Which I did, however the only results I get back from that call is:
Fetching file list...
Fetching files...
And then it just ends. No error message or any kind of message at all, and of course, it did not download the source code into the output dir I specified.
Scratching my head and looking at various SO posts, someone mentioned something about going into the google cloud vm directly and doing the same command, and to my surprise finding the same exact behavior that I did in my local terminal.
This made me realize it must be something else at play. I took a look at my versions tab in the App Engine dashboard on GCP. I see my instance running, it correctly says Serving and if I click the link it brings me to the website which loads fine. However, under Size it says 0 B which made me think perhaps this is why the download_app isn't downloading anything, because the version is 0 B?
What I'm trying to figure out is why it says 0 B for the version, when clearly the site runs fine and how I can get the source code for this. Here's a screenshot for reference
And screenshot of my terminal (local). Obviously I omitted the -A and -V flags, but they are correctly set and if I purposely make them incorrect I do indeed get an error message.
EDIT
Just so everyone is aware, I also made sure my user had the correct permissions. Owner, App Engine Owner... and some others. I don't think that's the problem.
When you deploy an App Engine Flexible application, the source code is uploaded to Cloud Storage on your project in a bucket named staging.<project-id>.appspot.com. You can navigate in this bucket and download the source code for a specific version as a .tar file.
Alternatively, you can find the exact Cloud Storage URL for your source code by going to Dev Console > Container Registry > Build History and select the build for your version. You'll find the link to your source code under Build Information.
One thing to note however is that the staging... bucket is created by default with a Lifecycle rule that deletes files older than 15 days automatically. You can delete this rule if you want so that all versions' source code is kept indefinitely.
In your case I believe that may not have helped since files may have been deleted already but it's worth knowing you can get the source code from there (source code isn't pushed to Source Repository by default, your developer had to configure it manually).
Posting this since none of the listed methods on the web didn't take me to the code (by June 2021)
Note: appcfg.py is deprecated by Google
You could try accessing your source code through;
Google Cloud Platform > Debugger > choosing the version of the
Application from combo at top.
This will list the files of that version on the left pane. There is no way to download code automatically but you can copy-paste the code.
Advice: Push your code to a Git repository to avoid this hassle next time.
Hope you will find this helpful.
In the developer console you can select the respective project and check:
on the Services page - which services, AKA modules - as they used to be (and still are) called in various places, you app has deployed
on the Versions page - which versions for each of the services are deployed
This information is what appcfg.py download_app expects. See also:
the various appcfg.py options using its --help flag
How do I download a specific service's source code off of AppEngine?
You can also access the deployed source code live (if everything else fails it could still be a last resort method to get the code, but tedious), see my answer to Google Cloud DataStore automatic indexing
Update:
I just now noticed in your screenshot that it's a flexible environment app. The appcfg.py docs are in the standard environment section, I suspect it's not applicable to the flexible environment, for which what's deployed is actually a docker image built during the deployment operation. From Deploying your application:
Deploy your app to App Engine using the gcloud app deploy
command. This command automatically builds a container image by using
the Container Builder service and then deploys that image to the
App Engine flexible environment. The container will include any local
modifications that you've made to the runtime image.
It might be possible to access the code on the actual GCE instance running the app, by connecting to the running instance and starting a shell in your app container, see Connecting to the instance

How to add multiple pages in Google App Engine?

I'm a beginner on GAE and I was wondering if it was possible to add another page to it so the home page would be
"example.appspot.com"
and the second would be
"example.appspot.com/test"
I've already tried looking for something that helps but the answers aren't what I'm looking for.
Of course it is possible to add more pages. The configuration for defining the URL matchers depends on the language runtime that you are using.
For Java:
The deployment descriptor is a file named web.xml. It resides in the
app's WAR under the WEB-INF/ directory.
https://developers.google.com/appengine/docs/java/config/webxml
For Python:
A Python app specifies runtime configuration, including versions and
URLs, in a file named app.yaml
https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_About_app_yaml

possible to eliminate JDO/JPA-related JARs from GAE project if using Twig/Objectify/etc?

In my Google App Engine project, I'm currently using Twig for accessing the Datastore (but I suspect my question would be relevant for other 3rd party libs like SimpleDS, Objectify, etc.).
I was thinking that I should be able to delete some or all of the following JARs from my WEB-INF/lib folder:
datanucleus-appengine-[...].jar
datanucleus-core-[...].jar
datanucleus-jpa-[...].jar
geronimo-jpa_[...].jar
geronimo-jta_[...].jar
jdo2-api-[...].jar
But when I do, I get errors from Eclipse complaining that "The App Engine SDK JAR is missing in the WEB-INF/lib directory".
Is it really necessary to retain all these (unused) JARs?
If you're using the Google Plugin for Eclipse you can delete these JARs and then open the Properties for your Google Web Application project and open the Google > App Engine and then uncheck the Use datanucleus JDO/JPA to access the datastore. In fact, unchecking this box actually deletes these JARs for you.
I don't think you can delete them from the project (as you have said, eclipse starts to complain), but I've heard you don't have to upload them to your app, as long as you upload from the command line. This has the advantage that at startup your app won't have to load them up.
There are some details of uploading to app engine via the command line here and confirmation that you can do this here
If you manage to do this I would appreciate it it if you post links to the instructions you followed or post what you needed to do, as I have this on my todo list as well, but only got as far as seeing if it was possible. Thanks!

Resources