diff --git a/Dockerfile b/Dockerfile index 032df37..b265a13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,26 @@ FROM python:3.11-alpine AS base +# set this arg to true, if you want +# to build the app with a speciffic +# port (8080) exposed. +ARG WEB_SERVER=false +ENV WEB_SERVER=$WEB_SERVER + WORKDIR /app COPY . . RUN pip install --no-cache-dir -r requirements.txt -CMD ["python3", "main.py"] +RUN if [ "$WEB_SERVER" = "false" ]; then \ + rm docker-entrypoint.py; \ + else \ + pip3 install flask; \ + fi + +CMD if [ "$WEB_SERVER" = "false" ]; then \ + exec python3 main.py; \ + else \ + exec python3 docker-entrypoint.py; \ + fi diff --git a/docker-entrypoint.py b/docker-entrypoint.py new file mode 100644 index 0000000..7d9413e --- /dev/null +++ b/docker-entrypoint.py @@ -0,0 +1,15 @@ +from flask import Flask, jsonify +import threading + +app = Flask(__name__) + +@app.route('/', methods=['GET']) +def index(): + return jsonify({"status": "ok"}), 200 + +if __name__ == '__main__': + t = threading.Thread(target=lambda: app.run(host='0.0.0.0', port=8080)) + t.start() + + import main +