Supposing I have a simple realm app with a trigger, trigger configuration json is bound to a specific database. How can I use a single repo to manage dev/ prod environments seamlessly, so that I only need to do a PR when I’m confident that dev environment is fine? I would totally avoid using UI to deploy changes for prod unless there is a simple setting which could only be done there.
I would have dev project connected to my repository develop branch. Once I’m confident everything’s good, I would do a PR into master for release. Merging the PR would call github actions as you described which will:
checkout code
update all triggers json files database setting with production DATABASE ( they are named differently at the moment)
update realm.json with production APP_ID and APP_NAME
use mongo cli to push updated code
This doesn’t seem like a good option to me, since setting an automated deploy on the production application for master branch would not allow me to do any changes on the realm UI without breaking the master branch I guess, since mongo will overwrite dev code… ( with this approach, master branch will have dev settings, but relying on github actions to do all the required json manipulations )
I’m pretty confused about the best way of doing it. Your blog post it’s focused on the mobile application and I cannot see anything related to triggers which are tied to database / collections. Would you advise me which option would work best conceptually for my use case? Thanks a lot in advance!
This doesn’t seem like a good option to me, since setting an automated deploy on the production application for master branch would not allow me to do any changes on the realm UI without breaking the master branch I guess, since mongo will overwrite dev code… ( with this approach, master branch will have dev settings, but relying on github actions to do all the required json manipulations )
Is there a reason or scenario why you anticipate using both Github Deploy + UI to deploy changes to your app? From what I can tell, your concern is mainly around when you are doing both frequently.
The other thing I’m not sure I understand is why making a change to your UI on the dev app (which is tied to your dev branch), doesn’t appropriately propogate to your prod app, since the same GH action will trigger a deploy to prod, changing the environment.
Attaching the build.yml started from the skeleton that you did. It kinda seems to work, however, adding a trigger with preimages set to enabled, then obviously I need to change trigger configuration for preimage in each json with some scripts… I could do that , but I have some doubts that the same structure will hold for you guys. Looking forward to hearing from you how the environments issue would be solved so that it doesn’t involve human interaction to manually create triggers, which obviously would be error prone.
It seems to me that it’s kind of clunky to execute github actions on main branch push just so that I modify json configs and deploy altered code to production app. If at any point in time I want to add a hotfix from the UI in prod, then UI will overwrite the github content ( which will have dev configurations << github actions don’t alter the actual repository as shown above>> ) , and the main branch will eventually have prod values in configurations…
That means that at the next pull request from dev to master, we ll need to solve conflicts, something like that. I’m just wondering whether there’s a better approach or not into solving this.
Attaching final version of the build script. I already tested this one, and it seems to be working fine with triggers / secrets / config values for environments ( development.json, production.json ). I would be very interested in finding out if this approach is an anti pattern or not at least.
Current approach for our use case:
Developer uses the realm development application which has automated github deployments enabled for repo develop branch
When developers are confident that development version works as expected, we make sure all development.json configs have values for production in production.json
We issue a PR for colleagues to review the code and the underlying changes
On PR merge, the build script is ran which handles differences between database name, realm app name etc, and everything is getting updated.
PS: in this use case, we disabled automated deployments for production, so that all the updates will be flowing through our PRs and repo main branch in a safe manner.
@Kevin_18580 I tried to use environment variables as you suggested, and it worked for app_id and name, but not for the environment. It looks like the environment is kind of self-referencing itself, so how should it know which environment to use?
Just to confirm – App Services does not support environment variables for the Environment field as this would create a cyclical reference. Our recommendation here would be to hardcode the environment in the repo/branch and then update it as a part of the code promotion / CICD process.
what do you do to handle multiple enviroment using the same codebase?
I have two clusters:
development app on atlas linked to my development branch on github
production app on atlas linked to my main branch on github
but what determines the environment of the app is the environment value from the /realm_config.json file
so if the environment value from my realm_config.json is “development” and I merge my development branch to main, the production app will read the env vars from environments/development.json
how to set and forget what env files to use in which app