0

I'm trying to build a good CI/CD solution with an angular client and rest api. I want to have a "build once, deploy many" setup of my angular client. Mostly angular-cli is wonderfull for this, but what I cant find a good solution for is storing the api url somewhere that I can manipulate during deploy.

The scenarios I have tried:

1) Storing the url in environment.env.ts files. The problem with this approach is that the environment.ts file is built into the artifacts of the "ng build" step, so I cannot alter the url during deploy. I could store all source as artifacts of the build step, and then do "ng build"/bundle during deploy, but this makes for a very slow deploy step, and I wouldn't really be deploying the same artifacts to several environments.

2) Storing the url in a separate assets/settings.json file. The problem with this is that getting the settings.json requires an async http.get call, and I cant find a good way to ensure that I have received the url before I can call the rest api.

Anyone have a good solution to either of these problems? Or a better approach altogether?

2

1 Answer 1

1

As idea you can place the env settings already into the env files. On build choose correct env over command parameters from your ci/cd setup.

ng build --env=prod

See detail insight here: Link

As alternative you can create a second git repo to hold env configuration files and replace them before the build starts on ci/cd process.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know if I understand you right, but I don't want the url to be bundled with the --env=prod, because my build server will have to change it if I deploy the artifacts to whatever environment.
Normal you know the target env on dev of the web app. So you can configure the different env setting on the enviroments. So you could rebuild the code for every target env before transmit to target system. So your normal build will only build and run tests, but will create an artifact with source code for the rebuild later. If you want change the env after build that would be tricky, as example you need to parse and replace main.bundle.js enviroment javascript code directly. I do not recommend this, because outside of standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.