如何在 Windows 上配置 GAE 数据存储模拟器?
How to configure the GAE Datastore emulator on Windows?
在 docs 之后,我从 CMD shell 启动了 GAE 数据存储模拟器。
我用过:
gcloud beta emulators datastore start --data-dir=j:\projects\project\datastore
输出为:
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 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!
正在浏览 localhost:8081
returns Ok
在第二个 CMD shell 我尝试:
gcloud beta emulators datastore env-init --data-dir=j:\projects\project\datastore > set_vars.cmd && set_vars.cmd
(Google 文档没有提到 --data-dir=j:\projects\project\datastore
但没有它,工具看起来在错误的地方)
但它失败了:
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.
如果我手动设置环境变量,我会从我的 CMD shells 得到相同的结果。
我已经尝试重现您的用例场景并且对我有用。这是我所关注的:
- 来自 Running the Datastore mode Emulator 文档。
- 确保安装了 A Java JRE(版本 8 或更高版本)。
- 安装 Google Cloud SDK(如果已有,请更新)
- 运行管理员身份的CMD
- 执行
$ gcloud components install cloud-datastore-emulator
- 执行
$ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
- 如果得到
You do not currently have this command group installed. Using it requires the installation of components: [beta]
- 然后执行
$ gcloud components install beta
- 再次执行
$ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
- 以管理员身份再次打开新的CMD
- 执行
$ gcloud beta emulators datastore env-init --data-dir=C:\PATH\TO\datastore > set_vars.cmd && set_vars.cmd
- 命令执行没有任何问题。这是回复:
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>
我建议从不同目录重试该过程。确保:
- 您有访问该目录的管理员权限。
- 出于测试目的,请尝试桌面上的目录。
- 更新 Google Cloud SDK。
- 目录路径中没有 space。
- 两个 CMD 都应该以管理权限打开。
更新于 2019 年 9 月 7 日以下评论。
如果您坚持使用 Google App Engine (GAE) Standard Python 2.7,并且必须 运行 GDS 的本地版本,这是我的方法(认为不是直接回答问题,但仍然可能与)有关。
我 运行 dev_appengine 使用数据存储参数。在 windows 上,.bat 文件可能如下所示:
set PY="c:\/python27\/python.exe"
set GAE="C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py"
set GCSEMU="C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd"
%PY% %GAE% --skip_sdk_update_check=True --datastore_emulator_cmd=%GCSEMU% --port 8080 --host oe.loc .
商店位置也有参数。
在 docs 之后,我从 CMD shell 启动了 GAE 数据存储模拟器。
我用过:
gcloud beta emulators datastore start --data-dir=j:\projects\project\datastore
输出为:
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 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!
正在浏览 localhost:8081
returns Ok
在第二个 CMD shell 我尝试:
gcloud beta emulators datastore env-init --data-dir=j:\projects\project\datastore > set_vars.cmd && set_vars.cmd
(Google 文档没有提到 --data-dir=j:\projects\project\datastore
但没有它,工具看起来在错误的地方)
但它失败了:
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.
如果我手动设置环境变量,我会从我的 CMD shells 得到相同的结果。
我已经尝试重现您的用例场景并且对我有用。这是我所关注的:
- 来自 Running the Datastore mode Emulator 文档。
- 确保安装了 A Java JRE(版本 8 或更高版本)。
- 安装 Google Cloud SDK(如果已有,请更新)
- 运行管理员身份的CMD
- 执行
$ gcloud components install cloud-datastore-emulator
- 执行
$ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
- 如果得到
You do not currently have this command group installed. Using it requires the installation of components: [beta]
- 然后执行
$ gcloud components install beta
- 再次执行
$ gcloud beta emulators datastore start --data-dir=C:\PATH\TO\datastore
- 以管理员身份再次打开新的CMD
- 执行
$ gcloud beta emulators datastore env-init --data-dir=C:\PATH\TO\datastore > set_vars.cmd && set_vars.cmd
- 命令执行没有任何问题。这是回复:
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>
我建议从不同目录重试该过程。确保:
- 您有访问该目录的管理员权限。
- 出于测试目的,请尝试桌面上的目录。
- 更新 Google Cloud SDK。
- 目录路径中没有 space。
- 两个 CMD 都应该以管理权限打开。
更新于 2019 年 9 月 7 日以下评论。
如果您坚持使用 Google App Engine (GAE) Standard Python 2.7,并且必须 运行 GDS 的本地版本,这是我的方法(认为不是直接回答问题,但仍然可能与)有关。 我 运行 dev_appengine 使用数据存储参数。在 windows 上,.bat 文件可能如下所示:
set PY="c:\/python27\/python.exe"
set GAE="C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\dev_appserver.py"
set GCSEMU="C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd"
%PY% %GAE% --skip_sdk_update_check=True --datastore_emulator_cmd=%GCSEMU% --port 8080 --host oe.loc .
商店位置也有参数。