Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Run the application with env variables instead of configuration file #15

Open
rikribbers opened this issue May 28, 2018 · 2 comments
Open

Comments

@rikribbers
Copy link

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")
@ghost
Copy link

ghost commented Mar 31, 2021

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

@rikribbers
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant