How to download source code from google app engine 2021 (appcfg.py tool doesn't work any more) [duplicate] - google-app-engine

This question already has answers here:
How do I download the source code of a google app engine project?
(12 answers)
Closed 1 year ago.
What are the alternatives to download source code from app engine instead of using appcfg.py?

Yes, you are correct, downloading source code using appcfg.py is deprecated. The alternative way is by downloading in Cloud Storage bucket named staging.project-id.appspot.com but the name of the files are encrypted. For you to easy track the files use the following gcloud command:
To view all versions and services in App Engine:
gcloud app versions list
Select the version ID and service name from the output then execute it in the gcloud command below:
gcloud app versions describe VERSIONID -s SERVICENAME
From the output, look for:
deployment:
files:
filesample.txt:
sha1Sum: encryptedname
sourceUrl: https://storage.googleapis.com/staging.project-id.appspot.com/encryptedname
To download click the output of sourceUrl.
There's also a Feature Request for downloading source code for app engine, you can star the public issue tracker feature requests to ensure that you will receive the updates about it. But please note that there is no guarantee that this feature will be implemented.

I did compile a few options to fetch App Engine's code in this repo, but to sum it up:
If you use App Engine Standard:
Try to look in Stackdriver Debugger
The staging bucket contains the files used on deployment time, you can get them from there (although it's not a good idea if there are many files deployed).
In case of App Engine Flex:
SSH into any of the VMs and then download the files directly from there
Fetch the image from GCR that was created when deploying so you can download the files from there

Related

Google cloud debugger not displaying source code

I'm using Google App Engine and I've followed the instruction to setup Google Debugger as show here:
https://cloud.google.com/debugger/docs/setup/nodejs
My project is written in Node.js and I'm starting the service with this line:
require('#google-cloud/debug-agent').start({serviceContext: {enableCanary: true}});
I've also generated the source-context file.
When I go to the debugger console (https://console.cloud.google.com/debug) I see the green tick about the debug agent running but nothing is displayed on the left side, under "Deployed files".
Any ideas?
What you're seeing is intended behavior. Deployments to App Engine Standard will show the source code as the source files are included on deployment and not using a Docker container while deployments to App Engine Flex are using a Docker container, which currently need not to include the source files, hence why you need a source context information which is generated from a Git Repository. For more information about differences of standard and flex, please see Choose an App Engine environment.
For App Engine Flex app source code to appear on Cloud Debugger, it must be located on a remote code hosting provider. Make sure that you follow the Selecting source code automatically properly. Your main source code (js, yaml, and source-context.json) should be in the root directory of the repository as shown below.
App-directory/
main.py
app.yaml
source-context.json
I've successfully deployed sample application using Github showing the source codes on the left side as shown below.
Some important notes:
When using "Cloud Source Repositories" or "GitHub" or any of the other remote code hosting options, one must take some care:
Changes to the source file must be committed to version control before running gcloud debug source gen-repo-info-file.
gcloud debug source gen-repo-info must be run before deploying the App.
Commits must have been pushed to Cloud Source Repository/GitHub/etc before running Cloud Debugger.
Access must have been granted to the repo to the Cloud Debugger application.
Always redeploy application when there are changes to the repository or source code.

Google API PHP CLIENT > 10000 files, can't upload to APP ENGINE service [duplicate]

This question already has an answer here:
Google PHP API too many files
(1 answer)
Closed 3 years ago.
i've download the google api php client from
https://github.com/googleapis/google-api-php-client/releases
I need to push the project + this code on an app engine versione, problem is that i got an error when gcloud: ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: This deployment has too many files. New versions are limited to 10000 files for this app.
I've ignored all files from project, but only the google api php client directory has 10.646 files.
I can't undestand which file are required for me(i need just API to switch on/off a VM on compute engine)
You may delete folders from services you don't intend to use in the following top folder :
google-api-php-client-2.4.0\vendor\google\apiclient-services\src\Google\Service
You should have no more than some hundred of files after that.

Bucket files still saved locally when using dev_appserver and --support_datastore_emulator=false

I'm running a local instance of a PHP app-engine project, I have got some buckets setup in GCP specifically for the local dev version, however instead of the data that I write to the bucket appearing online, they are being saved locally into the dev_appserver Datastore. I can see the files in the local admin interface (localhost:8000) under Datastore.
This is an issue as the application I'm developing has a companion app which needs to also access the bucket files.
The
--support_datastore_emulator=[true|false]
flag is documented under
dev_appserver.py -h
But it doesn't seem to have any effect when using =false.
So my question is: How do I stop the dev_appserver from using the local Datastore and make it use the 'real' buckets on the web?
Try setting the --default_gcs_bucket_name flag documented here to establish the default GCS bucket to use:
dev_appserver.py app.yaml --default_gcs_bucket_name gs://BUCKET-NAME

Google Cloud App Engine - Edit 1 file

I am new at Google Cloud and I would like to know if there is a way to edit only one file inside of an App Engine application.
This is my problem:
I am migrating from a normal hosting to google cloud and I am having some problems with my PHP code, I am using the same version like locally but I am getting some error in the cloud, so I need to change 1 or 2 files, update them and test the app, so is there any way to change that file directly on the server? To deploy i am using this command:
gcloud app deploy
But it takes about 10 minutes to deploy so is too slow my testing. Any suggestions?
Thanks.
Leandro
For the standard environment the answer is no, you need to deploy a new version of the app to modify a file. So the advice would be - make the most of testing your app locally. See somehow related Google AppEngine - updating my webapp after deploy
For the flexible environment (possibly your case as you mentioned 10 min deployment time, typical for the flexible env) there might be stuff to try, but tedious, see Google AppEngine - updating my webapp after deploy
There is a way to edit directly into the instance.
ssh into your instance and then start shell on your running docker as guided in this url. https://cloud.google.com/appengine/docs/flexible/python/debugging-an-instance
After login you can see your php source files.
Basically you will not have any editor. So do
$> apt update
$> apt install nano
$> nano index.php // edit your files
you can see something like
There is no way to change 1-2 files on the server so that it would update the app. Deployment is the process of updating the live app. If you want some changes to be made to the app that is already deployed, you will have to redeploy - there is no way around it. This is why it is recommended to test the app locally before (re)deploying so that you are sure everything is working fine.
If locally everything works fine and issues start happening only when the app is deployed, this should be investigated further and I would advise you to open a new question and provide as much details as possible regarding the problems, including full stack trace of the error, related code parts, your app.yaml contents as well.

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

Resources