How to cleanup the development datastore? - google-app-engine

In Google App Engine Go SDK sometimes we can fill the local datastore with a bunch of test data. It's tiring to delete thousands of records 20 at a time using the web interface. Is there a command the erases the local datastore?

Simply provide the --clear_datastore command line parameter when starting:
goapp serve --clear-datastore
Documented at: The Go Development Server: Using the Datastore.
To clear the local datastore for an application, use the --clear_datastore=yes option when you start the web server:
Note that the documentation was "copied" from the Python section, you need to use it as presented above (you get an error if you try to execute goapp serve --clear_datastore=yes).

I don't know about Go, but in Java you can simply delete local_db.bin from WEB-INF/appengine-generated folder. An empty file will be created next time you run the app.

Related

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

Writing to a file in App Engine: How to view that file afterwards?

I managed to get the "Quickstart for Python 3 in the App Engine Standard Environment" example up and running, and I thought I'd try and further my knowledge a little, perhaps by attempting to get a cron job running.
So I updated the python code, adding another endpoint, counter, like this:
#app.route('/counter')
def counter():
with open('counter.txt', 'a') as the_file:
the_file.write('Hello\n')
return 'Counter incremented'
I intend to have the cron job periodically hit /counter. When this endpoint is hit it will open the file and add a line to it. The /counter endpoint works on my local machine. After I deploy this updated code to the Google cloud, if I go to my blahblah.appspot.com/counter url it should update this 'counter.txt' file.
My question is: How do I see that file to know if it is being updated or not? How do I view that file in the cloud? Thanks.
It not possible to write files in the Google App Engine Standard Python3 environment except in the /tmp directory. As stated in the Python3 GAE official documentation:
The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a virtual disk storing data in your App Engine instance's RAM.
I agree with #Josh J answer, you should use Google Cloud Storage instead.
You shouldn't write to the local file system in Google App Engine. It may or may not be visible to your app when it scales.
Google Cloud Storage is the preferred method of file storage.
https://cloud.google.com/appengine/docs/standard/python3/using-cloud-storage
For python 2.7 you can import a module from string instead of file, you can see in this answer:
https://stackoverflow.com/a/7548190/8244338

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.

Clean datastore for GoogleAppEngine

How to clear datastore in GoogleAppEngine.
I want to clear my development data to do a test again, but I can found a way to do that
If you are running from the commandline, use the --clear_datastore flag, e.g.,
dev_appserver.py --clear_datastore=yes app
Otherwise, if you're running it off the included GAE launcher, go into the settings of your app (double click it), and there should be a little checkbox that says "clear datastore on launch" under Launch Settings.
reference:
https://cloud.google.com/appengine/docs/python/tools/devserver#Python_Using_the_Datastore
dev_appserver.py --clear_datastore myapp
assuming by "development data", you mean the data in the dev server.
Simply use Administering Your Datastore (Experimental)
Some Other ways
App Engine: How to "reset" the datastore?
Delete all data for a kind in Google App Engine
Interactive console is also a great way.
For Java, the following information can be seen in Using the Datastore - Clearing the Datastore at the end of the page (as of 2013/05/10):
The development web server uses a local version of the Datastore for testing your application, using local files. The data persists as long as the temporary files exist, and the web server does not reset these files unless you ask it to do so.
The file is named local_db.bin, and it is created in your application's WAR directory, in the WEB-INF/appengine-generated/ directory. To clear the Datastore, delete this file.
So, stop your server, delete the file, and restart it up.
On your local machine you can go to : http://localhost:8080/_ah/admin/datastore

how can I change my app-id in GAE and still access the same permanent datastore?

I am developing an app locally in Google App Engine. I have built a small datastore for development purposes. Rebuilding it after every power cycle on my Mac got tedious so I made it permanent. Now I run my app locally with the following command:
/usr/local/bin/dev_appserver.py "--datastore_path=./permanent.datastore" appengine_prototype
Life is good. I have decided to deploy my app so I can test http post commands from a different machine. When I tried to register my current application id (example), I found that it was unavailable (shocker!). So I registered a different application id and planned to change my local application id to match. However, when I changed the
application: *app-id*
line in my app.yaml file, my app stopped recognizing my permanent datastore.
So, how can I change my application id to the one I registered, maintain the connection to the permanent datastore and then push the whole shebang online? I tried running the app twice locally, first with the permanent datastore referenced in the command and then without, hoping that the default temporary datastore would inherit from the previous permanent datastore. That didn't work. Do I need to start by copying the permanent datastore to the default temporary datastore? How would I do that? Any help would be much appreciated.
Thanks,
Dessie
If your intention is to eventually push your local data to your live environment anyway, then your best bet is to:
use bulkloader.py to backup your local data (while using oldid in your config)
then change your config to your newid
then use bulkloader.py to push your data to your new development server (ran with --datastore_path=./permanent.datastore2 or something)
then use bulkloader.py to push your data to the GAE production server
Details of bulkloader.py can be found in the docs and an example here

Resources