Render.yaml - two connected web services best practices?

Hi all,

I am trying to setup our infrastructure as a code (render.yaml) and I am not sure which approach to use. I will describe my situation and two solutions I can think of. Both of them have their drawbacks and I am not sure what is the correct way to do it. Maybe there’s another approach. I would be really grateful if somebody could help me with this. :slight_smile:

Services

  1. Phoenix web app (app-1)
  2. Next.JS web app (app-2)

Both apps are in separate repositories. Both apps need to know host (<THIS_PART>.onrender.com) of the other app. If there’s a PR on one of the apps, there should be a preview environment created for both services listed above and that seems to be the complicated part.


Approach 1

Each app will have separate render.yaml file in it’s repository with a content like this (simplified intentionaly):

previewsEnabled: true

services:
  - name: app-1
    envVars:
      - key: APP_2_HOST
        fromService:
          name: app-2
          type: web
          property: host

  - name: app-2
    repo: <repo_of_the_app_2>
    envVars:
      - key: APP_1_HOST
        fromService:
          name: app-2
          type: web
          property: host

Approach 2

There will be separate repository for one global render.yaml file, that will contain all the infrastructure as code. The render.yaml will look like the one above with repo attribute specified for each app, since the repo with the render.yaml file will contain only that file.

previewsEnabled: true

services:
  - name: app-1
    repo: <repo_of_the_app_1>
    envVars:
      - key: APP_2_HOST
        fromService:
          name: app-2
          type: web
          property: host

  - name: app-2
    repo: <repo_of_the_app_2>
    envVars:
      - key: APP_1_HOST
        fromService:
          name: app-2
          type: web
          property: host

Both approaches means, that if I will need to change the buildCommand for example, I will have to make changes in two repositories and that can get a bit out of sync. I am aware, that there’s possible solution with monorepo, but that brings another issues and I don’t want to go this route.

If anybody has some ideas about this, that would be great.

Thanks a lot.

I ended up with Approach 1. I have both services specified in both repositories.

Apparently approach 2 is not possible. Deployment won’t be triggered automatically when doing git commit. I would have to make a change on the yaml file repo and that’s not a sensible solution.

Anyway, I’ll keep an eye on the possibility of a more ergonomic solution.

1 Like