简体   繁体   English

appengine 使用数据存储设置本地主机以进行测试

[英]appengine set up local host with datastore for testing

I have tried to follow googles documentation on how to set up local development using a database ( https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server#Python_Using_the_Datastore ).我试图遵循关于如何使用数据库设置本地开发的 googles 文档( https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server#Python_Using_the_Datastore )。 However, i do not have the experience level to follow along.但是,我没有可以遵循的经验水平。 I am not even sure if that was the right guide.我什至不确定这是否是正确的指南。 The application is a Django project that uses python 2.7.该应用程序是一个使用 python 2.7 的 Django 项目。 To run the local host, i usually type dev_appserver.py --host 127.0.0.1 .要运行本地主机,我通常输入dev_appserver.py --host 127.0.0.1 .

My questions are:我的问题是:

  1. how do i download the data store database on google cloud.我如何在谷歌云上下载数据存储数据库。 I do not want to download the entire database, just enough data to populate local host so i can do tests我不想下载整个数据库,只需要足够的数据来填充本地主机,这样我就可以进行测试

  2. once the database is download, what do i need to do to connect it to the localhost?下载数据库后,我需要做什么才能将其连接到本地主机? Do i have to change a parameter somewhere?我必须在某处更改参数吗?

  3. do i need to download the datastore?我需要下载数据存储吗? Can i just make a duplicate on the cloud and then connect to that datastore?我可以在云上复制一份然后连接到那个数据存储吗?

  4. When i run localhost, should it not already be connected to the datastore?当我运行 localhost 时,它不应该已经连接到数据存储吗? Since the site works when it is running on the cloud.由于该站点在云上运行时可以正常工作。 Where can i find the connection URI?在哪里可以找到连接 URI?

Thanks for the help谢谢您的帮助

The development server is meant to simulate the whole App Engine Environment, if you examine the output of the dev_appserver.py command you'll see something like Starting Cloud Datastore emulator at: http://localhost:PORT . 开发服务器旨在模拟整个 App Engine 环境,如果您检查dev_appserver.py命令的输出,您将看到类似“ Starting Cloud Datastore emulator at: http://localhost:PORT Your code will interact with that bundled Datastore automatically, pushing and retrieving data according to the code you wrote.您的代码将自动与捆绑的 Datastore 交互,根据您编写的代码推送和检索数据。 Your data will be saved on a file in local storage and will persist across different runs of the development server unless it's explicitly deleted.您的数据将保存在本地存储中的文件中,并且除非被明确删除,否则将在开发服务器的不同运行中持续存在。

This option doesn't provide facilities to import data from your existing Cloud Datastore instance although it's a ready to go solution if your testing procedures can afford populating the local database with mock data through the use of a custom created script that does so programmatically.此选项不提供从现有 Cloud Datastore 实例导入数据的工具,但如果您的测试过程能够负担得起通过使用以编程方式执行的自定义创建的脚本来使用模拟数据填充本地数据库,则它是一个现成的解决方案。 If you decide for this approach just write the data creation script and execute it before running the tests.如果您决定采用这种方法,只需编写数据创建脚本并在运行测试之前执行它。

Now, there is another option to simulate local Datastore using the Cloud SDK that comes with handy features for your purposes.现在,还有另一个选项可以使用 Cloud SDK 模拟本地数据存储区,该 Cloud SDK 为您提供了方便的功能。 You can find the available information for it under Running the Datastore Emulator documentation page.您可以在运行数据存储模拟器文档页面下找到它的可用信息。 This emulator has support to import entities downloaded from your production Cloud Datastore as well as for exporting them into files.此模拟器支持导入从生产 Cloud Datastore 下载的实体以及将它们导出到文件中。

Back to your questions:回到你的问题:

  1. Export data from the Cloud instance into a GCS bucket following this , then download the data from the bucket to your filesystem following this , finally import the data into the emulator with the command shown here .从下面的云实例为GCS桶中导出数据 ,然后从桶到您的文件系统下下载数据,最后将数据导入与显示的命令模拟器这里
  2. To use the emulator you need to first run gcloud beta emulators datastore start in a Cloud Shell and then in a separate tab run dev_appserver.py --support_datastore_emulator=true --datastore_emulator_port=8081 app.yaml .要使用模拟器,您需要先在 Cloud Shell 中运行gcloud beta emulators datastore start ,然后在单独的选项卡中运行dev_appserver.py --support_datastore_emulator=true --datastore_emulator_port=8081 app.yaml
  3. The development server uses one of the two aforementioned emulators, in both cases it is not connected to your Cloud Datastore.开发服务器使用上述两个模拟器之一,在这两种情况下,它都没有连接到您的 Cloud Datastore。 You might create another project aimed for development purposes with a copy of your database and deploy your application there so you don't use the emulator at all.您可以使用数据库副本创建另一个用于开发目的的项目,并将应用程序部署在那里,这样您就根本不使用模拟器。
  4. Requests at datastore are made trough the endpoint https://datastore.googleapis.com/v1/projects/project-id although this is not related to how the emulators manage the connections in your local server.数据存储区的请求是通过端点https://datastore.googleapis.com/v1/projects/project-id发出的,尽管这与模拟器如何管理本地服务器中的连接无关。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM