1

My question is similar to this one regarding how to set up different React environment variables/app settings during deployments to different environments in Azure Devops.

These are (hopefully) my requirements

  • Single build pipeline triggered by different branches that creates a React app artifact
  • ARM template in a release pipeline that creates/updates an environment (e.g. test, prod)
  • React App is deployed in the same release pipeline
  • React application has the correct app settings for that newly created environment (e.g. API_URL for 'test')

I would like to do all this without hard coding any apps settings in my build .yaml or as build pipeline variables. The reason is if my environment hasn't yet been created by the release pipeline, how would I know what settings to inject when building the react app in the preceding build pipeline?

Is Azure App Configuration a good fit for this?

I figured I could do something like...

  • Create the Azure App Configuration
  • Setup a React app to use the App Configuration javascript client library to retrieve app settings
  • Inject the App Configuration connection string and environment type (e.g. test) during the build of the react app. (The environment type will be used as an app configuration label)
  • Use the Azure CLI to push new settings to the App Configuration during the creation/update of the ARM template in the release pipeline based on the label for that environment.
  • Once deployed the running app should have access to all the app settings for that environment/label.

Does this sound possible? A good idea?

I feel like this should work in theory. It doesn't matter whether the ARM template for example creates API_URL = https://test.azurewebsites.net or https://prod.azurewebsites.net, because the connection string and label of 'test' or 'prod' was passed into the react app during build, it will always have the correct values at runtime. A few downsides are the App Configuration connection string will need to be exposed as a build pipeline variable, it will need to have been created first, and I would need to implement logic in my react app to switch between loading app settings locally and from the client library

Many thanks,

Konzy262
  • 2,747
  • 6
  • 42
  • 71

1 Answers1

0

An artifact (the build output) should be independent from your stage. You should always use the same artifact for any stage.

The most common way is to provide a server side-response with the client app configuration as json. Load the json on react init and inject your configuration. There is no other way to have.

Both, the client app and the config server app can run in the same app container. You can achive this behavior both with Azure App Service and Azure Static Sites.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Benjamin Abt
  • 1,730
  • 18
  • 33
  • Where would the json app configuration be stored? – Konzy262 Aug 28 '20 at 12:47
  • You configure all your stuff in the Configuration section of your Web App or Static Site inside the Azure Portal. You have to code a server side functionality to generate a json out of your Web App Environment Settings. There is no other way. You can only access Environment Settings of your Web App / Static Side via Server Side code. – Benjamin Abt Aug 28 '20 at 13:07
  • Not necessarily. Your app could reach out to an endpoint that returns config settings. Also manually configuring site settings after a deployment does not encompass the idea of infrastructure as code. – Konzy262 Aug 28 '20 at 13:17
  • The way I described IS actually like you said: you have to create an endpoint that returns the config. I did not say to manipulate the artifact. – Benjamin Abt Aug 28 '20 at 13:23