From 9995430f6849abc4e42fc20a9549ac28c969c6bb Mon Sep 17 00:00:00 2001 From: Khenziii Date: Mon, 27 May 2024 00:37:19 +0200 Subject: [PATCH] feat(ci/cd): add ARG to build with web server --- Dockerfile | 18 +++++++++++++++++- docker-entrypoint.py | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 docker-entrypoint.py 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 +