Search code examples
google-cloud-datastore

How to configure the GAE Datastore emulator on Windows?


Following the docs I have started the GAE Datastore Emulator from a CMD shell.

I used:

gcloud beta emulators datastore start --data-dir=j:\projects\project\datastore

The output is:

WARNING: Reusing existing data in [j:\projects\project\datastore].
Executing: cmd /c C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd start --host=localhost --port=8081 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown j:\projects\project\datastore
[datastore] Jun 08, 2019 5:24:52 PM com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$9 apply
[datastore] INFO: Provided --allow_remote_shutdown to start command which is no longer necessary.
[datastore] Jun 08, 2019 5:24:52 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub <init>
[datastore] INFO: Local Datastore initialized:
[datastore]     Type: High Replication
[datastore]     Storage: j:\projects\jupiter\datastore\WEB-INF\appengine-generated\local_db.bin
[datastore] Jun 08, 2019 5:24:53 PM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
[datastore] INFO: The backing store, j:\projects\project\datastore\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created.
[datastore] API endpoint: http://localhost:8081
[datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
[datastore]
[datastore]   export DATASTORE_EMULATOR_HOST=localhost:8081
[datastore]
[datastore] Dev App Server is now running.
[datastore]
[datastore] The previous line was printed for backwards compatibility only.
[datastore] If your tests rely on it to confirm emulator startup,
[datastore] please migrate to the emulator health check endpoint (/). Thank you!

Browsing to localhost:8081 returns Ok

In a second CMD shell I try:

gcloud beta emulators datastore env-init --data-dir=j:\projects\project\datastore > set_vars.cmd && set_vars.cmd

(Google docs don't mention --data-dir=j:\projects\project\datastore but without it the tool looks in the wrong place)

But it fails with:

ERROR: (gcloud.beta.emulators.datastore.env-init) Unable to find env.yaml in the data_dir 
[C:\Users\c\AppData\Roaming\gcloud\emulators\datastore]. Please ensure you have started the appropriate emulator.

If I set-up the environment variables manually I get the same results from my CMD shells.


Solution

  • I have tried to reproduced your use case scenario and it worked for me. This is what I have followed:

    1. From Running the Datastore mode Emulator documentation.
    2. Make sure that A Java JRE (version 8 or greater) is installed.
    3. Install the Google Cloud SDK (If already have, update it)
    4. Run the CMD as administrator
    5. Execute $ gcloud components install cloud-datastore-emulator
    6. Exectue $ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
    7. If get You do not currently have this command group installed. Using it requires the installation of components: [beta]
    8. Then execute $ gcloud components install beta
    9. Execute again $ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
    10. Open new CMD again as administrator
    11. Execute $ gcloud beta emulators datastore env-init --data-dir=C:\PATH\TO\datastore > set_vars.cmd && set_vars.cmd
    12. The command executed without any issues. This is the response:
    C:\Windows\system32>set DATASTORE_DATASET=[PROJECT_ID]
    
    C:\Windows\system32>set DATASTORE_EMULATOR_HOST=localhost:8081
    
    C:\Windows\system32>set DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
    
    C:\Windows\system32>set DATASTORE_HOST=http://localhost:8081
    
    C:\Windows\system32>set DATASTORE_PROJECT_ID=[PROJECT_ID]
    
    C:\Windows\system32>
    

    I would suggest to try the process again from different directory. Make sure that:

    • You have admin permissions to access the directory.
    • For testing purposes, try a directory in your desktop.
    • Update the Google Cloud SDK.
    • The directory's path don't have a space in it.
    • Both CMDs should open with administrative privileges.