如何在多个开发环境中使用 GAE 的 dispatch.yaml? [英] How to use GAE's dispatch.yaml with multiple development environments?

查看:20
本文介绍了如何在多个开发环境中使用 GAE 的 dispatch.yaml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解 Google App Engine 的 dispatch.yaml 文件.

I am trying to understand the dispatch.yaml file for Google App Engine.

我们有一个带有前端和后端的普通网络应用程序.我们还有一个开发和生产环境.两种环境在 GAE 上都有两个服务 - frontenddefault,即后端.

We have a vanilla web app with a frontend and a backend. We also have a development and a production environment. Both environments have two services on GAE - frontend and default, which is the backend.

我们有一个带有前端和后端的普通网络应用程序.我们还有一个开发和生产环境.我们在 GAE 上有两个服务——前端和默认,即后端.我们在 GAE 上有两个项目 - staging,这是我们的开发环境,以及 production,这是我们的生产环境.登台环境是从我们的前端和后端的 dev 分支构建的.生产环境由我们在前端和后端的 master 构建.

We have a vanilla web app with a frontend and a backend. We also have a development and a production environment. We have two services on GAE - frontend and default, which is the backend. We have two projects on GAE - staging, which is our dev environment, and production, which is our production environment. The staging environment is built from our dev branch in both our frontend and backend. The production environment is built from our master in both our frontend and backend.

我们希望在暂存和生产环境中使用自定义路由.

We want to use custom routes for both the staging and production environments.

我尝试使用 dispatch_staging.yamldispatch_prod.yaml 来区分文件,但 GAE 无法识别这些文件名.我想我们可以重命名前端服务,但看起来没有办法绕过 default.

I have tried using dispatch_staging.yaml and dispatch_prod.yaml to differentiate the files but GAE won't recognize those file names. I guess we could rename the frontend service but it looks like there is no way getting around default.

如何使用dispatch.yaml来指定正在构建的环境?

How do you use dispatch.yaml to specify the environment being built?

推荐答案

我解决这个问题的方法是对应用程序代码使用不同的 repo 分支.

The way I approached this problem is by using different repo branches for the application code.

  • master 分支版本部署到my_app-dev——开发环境app
  • production 分支版本部署到my_app——生产环境应用
  • the master branch version is deployed to my_app-dev - the development environment app
  • the production branch version is deployed to my_app - the production environment app

这样文件总是被命名为dispatch.yaml.服务名称不会在环境之间改变,但与它们关联的自定义域名会改变 - 这反映在 2 个分支中 dispatch.yaml 文件的内容中:

This way the file is always named dispatch.yaml. The service names don't change between environments, but the custom domain names associated to them do - and that's reflected in the content of the dispatch.yaml file in the 2 branches:

$ git diff production master -- dispatch.yaml
diff --git a/dispatch.yaml b/dispatch.yaml
index 0768a6a..c1326cf 100644
--- a/dispatch.yaml
+++ b/dispatch.yaml
@@ -1,14 +1,14 @@
-application: my_app
+application: my_app-dev
 dispatch:
-  - url: "service1.my_app.com/*"
+  - url: "service1-dev.my_app.com/*"
     module: service1
-  - url: "service1-dot-my_app.appspot.com/*"
+  - url: "service1-dot-my_app-dev.appspot.com/*"
     module: service1
   - url: "*/service1/*"
     module: service1
-  - url: "service2.my_app.com/*"
+  - url: "service2-dev.my_app.com/*"
     module: service2
-  - url: "service2-dot-my_app.appspot.com/*"
+  - url: "service2-dot-my_app-dev.appspot.com/*"
     module: service2

注意:我在应用级别实施不同的环境(与服务级别相反,请参阅在 GAE 项目/应用级别与服务/模块级别实施 CI/CD 环境的优势?).服务级实现不能使用这种方法.

Note: I'm implementing the different environments at the app level (as opposed to the service level, see Advantages of implementing CI/CD environments at GAE project/app level vs service/module level?). A service-level implementation cannot use this approach.

这篇关于如何在多个开发环境中使用 GAE 的 dispatch.yaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆