Skip to content

Instantly share code, notes, and snippets.

@samba2
Last active February 26, 2017 22:29
Show Gist options
  • Save samba2/d8290f63716777421bb4c76a09677301 to your computer and use it in GitHub Desktop.
Save samba2/d8290f63716777421bb4c76a09677301 to your computer and use it in GitHub Desktop.
Poor Man's Microservice Configuration Using Environment Variables
#!/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
PORT=8080
LOGLEVEL=info
DESCRIPTION=\
"This is
a multi line
description."
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