简体   繁体   English

本地调试访问后端数据库的服务

[英]Debugging locally service that accesses backend database

Our cloud-deployed app is composed of (simplified):我们的云部署应用程序由(简化)组成:

  1. A web front-end一个 web 前端
  2. Some back-end services一些后端服务
  3. A database一个数据库

When developing the front-end, I can easily debug by running the front-end locally, and redirecting its back-end calls to the actual services, since their endpoint routes are public.在开发前端时,我可以通过在本地运行前端并将其后端调用重定向到实际服务来轻松调试,因为它们的端点路由是公共的。

However, I also want to debug back-end service code, together with the front-end.但是,我也想调试后端服务代码,和前端一起调试。 I can run back-end services locally, but they can't access the database, since the database doesn't have any publicly-accessible endpoint.我可以在本地运行后端服务,但它们无法访问数据库,因为数据库没有任何可公开访问的端点。

Question: How can I conveniently develop the service code?问:如何方便的开发服务代码? I can think of these options:我可以想到这些选项:

  1. Expose the database publicly, maybe just the dev env's database.公开数据库,也许只是开发环境的数据库。 This doesn't sound like a good practice security-wise, and I haven't found a way to do it in my cloud platform (CloudFoundry).这听起来不像是安全方面的好做法,而且我还没有找到在我的云平台 (CloudFoundry) 中执行此操作的方法。
  2. Test everything using local unit- and component- tests.使用本地单元和组件测试来测试所有内容。 We do this, but can't cover everything, and certainly not the integration with the front-end.我们这样做,但不能面面俱到,当然也不能面面俱到与前端的整合。
  3. Deploy my code changes to a dev environment, and test that way.将我的代码更改部署到开发环境,并以这种方式进行测试。 This is what we do now, but:这就是我们现在所做的,但是:
    • It's a much slower development turn-around that running locally本地运行的开发周期要慢得多
    • I can't connect a debugger to the deployed app, so I must debug using logs, which again is slow我无法将调试器连接到已部署的应用程序,因此我必须使用日志进行调试,这又很慢
    • We have a limited number of dev environments, and this creates contention for them.我们的开发环境数量有限,这会导致对它们的争夺。
  4. Somehow deploy a replica of the database locally as well, using some kind of test data.也可以使用某种测试数据以某种方式在本地部署数据库的副本。

Tech details: For cloud we use CloudFoundry over AWS.技术细节:对于云,我们在 AWS 上使用 CloudFoundry。 My back-end services are written in C# + .NET core 5. Locally, we develop them using Visual Studio 2019 on Windows.我的后端服务写在C# + .NET core 5,本地我们在Windows上用Visual Studio 2019开发。

For now, I managed to expose my database locally using an SSH tunnel.现在,我设法使用 SSH 隧道在本地公开了我的数据库。 Specifically, by running cf ssh [AppName] -L [local_port]:[db_hostname]:[port] , with [db_hostname]:[port] taken from the app's configuration, taken by running cf env [AppName] .具体来说,通过运行cf ssh [AppName] -L [local_port]:[db_hostname]:[port] ,其中[db_hostname]:[port]从应用程序的配置中获取,通过运行cf env [AppName]获取。

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

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