I have an app written in angular4, I am running on production and sandbox,
I create an image and then deploy on kubernetes
I have some environment variables differnt to sandbox and production , currently I build two differnt images one for sandbox and one for production:
environments under src/envirnments
:
environment.prod.ts
export const environment = {
production: true,
server_url: 'https://api.example.com/app/',
};
environment.sandbox.ts
export const environment = {
production: false,
server_url: 'https://api-sandbox.example.com/app/',
};
building image:
production : ng build --prod
sandbox:
ng build--prod --env=sandbox
now, how can I use external environment varibales instead?
somthing like applicatoion.getEnvirnment('server_url')
, like this I dont need to create an image for each environment?
this is my deployment.yaml
:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: angular-web-app
namespace: production
spec:
replicas: 1
revisionHistoryLimit: 1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: angular-web-app
spec:
containers:
- name: angular-web-app
image: us.gcr.io/my-com/angular-web-app:06.01.2018
ports:
- containerPort: 80
env:
- name: SERVER_URL
value: https://api.example.com
here is my dockerfile:
FROM nginx
COPY dist /usr/share/nginx/html
EXPOSE 80
EXPOSE 443
building the image:
ng build --prod --env=sandbox
docker build --rm -t ${REGISTRY}/${CONTAINER}:${TAG} .
I added the environment variable to the deployment and I want the app to take the value from there