Created
April 11, 2022 01:20
-
-
Save ptrxyz/176db8821993a46ff263183f1399c95a to your computer and use it in GitHub Desktop.
Docker workshop 2
This file contains hidden or 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 python3 | |
from flask import Flask | |
import os | |
app = Flask(__name__) | |
class EnvNotSetError(Exception): | |
def __repr__(self): | |
return "EnvNotSetException was raised." | |
pass | |
def getMessage(): | |
configfile = os.getenv("APPCONFIG") | |
if not configfile: | |
raise EnvNotSetError() | |
with open(configfile, "r") as f: | |
lines=[x[8:].strip() for x in f.readlines() if x.startswith("Message=")] | |
return lines[0] | |
@app.route("/") | |
def index(): | |
try: | |
message = getMessage() | |
except FileNotFoundError: | |
message = "CONFIGURATION FILE NOT FOUND! THIS IS NOT OK!" | |
except IndexError: | |
message = "CONFIGURATION FILE FOUND BUT NO MESSAGE! THIS IS NOT OK!" | |
except EnvNotSetError: | |
message = "ENVIRONMENT VARIABLE NOT SET! THIS IS NOT OK!" | |
except Exception as ex: | |
message = f"BIG ERROR: {ex}" | |
return f"Hello! I have a Message for you. It reads:\n\n{message}" | |
app.run(host="0.0.0.0", port=3000, debug=True) |
This file contains hidden or 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
Message=Hello from the other side! |
This file contains hidden or 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
version: "3.9" | |
services: | |
app: | |
build: . | |
ports: | |
- "3000:3000" |
This file contains hidden or 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
FROM ubuntu | |
RUN apt update -y && apt install -y python3 python3-pip && pip install flask | |
ENV APPCONFIG=/app/config.msg | |
ADD config.msg /app/config.msg | |
ADD app2.py /app/app.py | |
WORKDIR /app | |
CMD python3 app.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment