Last active
February 26, 2017 22:29
-
-
Save samba2/d8290f63716777421bb4c76a09677301 to your computer and use it in GitHub Desktop.
Poor Man's Microservice Configuration Using Environment Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -ae # auto export env vars + stop script on error | |
trap 'kill $PID' TERM | |
source $1 | |
gunicorn demoservice:app & # put your microservice start command here | |
PID=$! | |
wait $PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=8080 | |
LOGLEVEL=info | |
DESCRIPTION=\ | |
"This is | |
a multi line | |
description." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
port = os.getenv("PORT") | |
loglevel = os.getenv("LOGLEVEL") | |
description = os.getenv("DESCRIPTION") | |
return f"loglevel: {loglevel}, port: {port}, description: {description}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment