blue-yonder/azure-cost-mon

Run the application with env variables instead of configuration file

rikribbers opened this issue · 2 comments

I run applications like these in a docker container. For this I don't want a dependancy to a file with hardcoded variables. It would be nice if there is an option to read the configuration from the environment.

e.g. I would like to see a docker-compose.yml like this

version: '3'

services:
azure-billing-exporter:
    image: blue-yonder/azure-cost-mon
    ports:
    - 8000:8000
    environment:
      PROMETHEUS_METRIC_NAME: "azure_costs_eur"
      ENROLLMENT_NUMBER: "31415"
      BILLING_API_ACCESS_KEY: "3408795poitwiqeotu934t5pqweiut"

My workaround is to use the following Dockerfile

FROM python       

ADD https://github.com/blue-yonder/azure-cost-mon/archive/v0.4.1.tar.gz /tmp

WORKDIR /tmp
RUN tar -zxvf /tmp/v0.4.1.tar.gz \
  &&  mv /tmp/azure-cost-mon-0.4.1 /azure_cost_mon

WORKDIR /azure_cost_mon
RUN pip install -r requirements.txt \
  && pip install azure-costs-exporter gunicorn

ADD startup.py /azure_cost_mon/startup.py
EXPOSE 8000
ENTRYPOINT ["python","/azure_cost_mon/startup.py"]

And the following startup.py

import os

metricName=os.environ['PROMETHEUS_METRIC_NAME']
enrollmentNumber = os.environ['ENROLLMENT_NUMBER']
apiAccessKey= os.environ['BILLING_API_ACCESS_KEY']

file = open('/azure_cost_mon/application.cfg','w') 
file.write('ENROLLMENT_NUMBER=\''+enrollmentNumber+ '\'\n') 
file.write('BILLING_API_ACCESS_KEY=\''+apiAccessKey+ '\'\n') 
file.write('PROMETHEUS_METRIC_NAME=\''+metricName+ '\'\n') 
file.close()

os.system("gunicorn --log-level=info azure_costs_exporter:app -b :8000")

Hello, is this working ? Is this already handle in the solution ?

Last time I checked was 2 years ago.. back then it was working; you might want to re-check it.