From 066ced8678f8913f54b27b8f4bb7ec593027c0fe Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Thu, 12 Aug 2021 12:32:44 -0400 Subject: [PATCH 1/4] hello world, vagrantrc qol --- .docker-compose/Dockerfile | 9 ++++++++- .vagrantrc | 4 +--- Dockerfile | 9 ++++++++- docker-compose.override.yml | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index 04773a8..ab1a60b 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -9,5 +9,12 @@ RUN cd Cbc-2.9.8 && \ ./configure && \ make && \ make install +RUN python -m pip install -U Flask -CMD tail -f /dev/null +# Bundle app source +COPY . /app + +WORKDIR /app/app + +# CMD tail -f /dev/null +CMD export FLASK_APP=main && flask run -p 80 --host=0.0.0.0 diff --git a/.vagrantrc b/.vagrantrc index 5e70c72..ddc7b4d 100644 --- a/.vagrantrc +++ b/.vagrantrc @@ -39,10 +39,8 @@ measure-solver-logs() { compose "logs measure-solver" } -measure-solver-server() { -} - restart-measure-solver() { + compose "restart measure-solver" } rails() { diff --git a/Dockerfile b/Dockerfile index 04773a8..ab1a60b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,12 @@ RUN cd Cbc-2.9.8 && \ ./configure && \ make && \ make install +RUN python -m pip install -U Flask -CMD tail -f /dev/null +# Bundle app source +COPY . /app + +WORKDIR /app/app + +# CMD tail -f /dev/null +CMD export FLASK_APP=main && flask run -p 80 --host=0.0.0.0 diff --git a/docker-compose.override.yml b/docker-compose.override.yml index e69de29..b25559e 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -0,0 +1,2 @@ +override_file_placeholder: + image: busybox From 4567653170ed6ce11efdb78fe2173f3700055e3e Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Thu, 12 Aug 2021 12:36:58 -0400 Subject: [PATCH 2/4] main py and gitignore --- .gitignore | 27 +++++++++++++++++++++++++++ app/main.py | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 app/main.py diff --git a/.gitignore b/.gitignore index e69de29..529b0f1 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,27 @@ + +.DS_Store +.env +.flaskenv +*.pyc +*.pyo +env/ +venv/ +.venv/ +env* +dist/ +build/ +*.egg +*.egg-info/ +_mailinglist +.tox/ +.cache/ +.pytest_cache/ +.idea/ +docs/_build/ +.vscode + +# Coverage reports +htmlcov/ +.coverage +.coverage.* +*,cover diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..27821ee --- /dev/null +++ b/app/main.py @@ -0,0 +1,7 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route("/") +def hello_world(): + return "

Hello, World?

" From 0dcb8459a6af3658734f1441a1e02eb48c43963b Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Thu, 12 Aug 2021 15:13:05 -0400 Subject: [PATCH 3/4] convert to fast api --- .docker-compose/Dockerfile | 4 ++-- Dockerfile | 5 +++-- app/main.py | 25 ++++++++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.docker-compose/Dockerfile b/.docker-compose/Dockerfile index ab1a60b..81dcdbc 100644 --- a/.docker-compose/Dockerfile +++ b/.docker-compose/Dockerfile @@ -9,7 +9,7 @@ RUN cd Cbc-2.9.8 && \ ./configure && \ make && \ make install -RUN python -m pip install -U Flask +RUN python -m pip install fastapi[all] # Bundle app source COPY . /app @@ -17,4 +17,4 @@ COPY . /app WORKDIR /app/app # CMD tail -f /dev/null -CMD export FLASK_APP=main && flask run -p 80 --host=0.0.0.0 +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/Dockerfile b/Dockerfile index ab1a60b..b681afb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ RUN cd Cbc-2.9.8 && \ ./configure && \ make && \ make install -RUN python -m pip install -U Flask +RUN python -m pip install fastapi[all] + # Bundle app source COPY . /app @@ -17,4 +18,4 @@ COPY . /app WORKDIR /app/app # CMD tail -f /dev/null -CMD export FLASK_APP=main && flask run -p 80 --host=0.0.0.0 +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/app/main.py b/app/main.py index 27821ee..7465ad8 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,22 @@ -from flask import Flask +from fastapi import FastAPI, __version__ -app = Flask(__name__) +app = FastAPI() -@app.route("/") -def hello_world(): - return "

Hello, World?

" +@app.get("/") +async def root(): + return {"message": "Welcome to Measures LOFT solver service. v0.1"} + +@app.get("/health") +async def health(): + content = { + "maintainer": "Meazure Horizon Team", + "git_repo": "https://github.com/yardstick/measure-solver", + "server": "OK", + "fastapi version": __version__, + "app version": "0.1.0" + } + return content + +@app.get('/ready') +async def ready(): + return 'OK' # just means we're on air From e4efbe4c2ddf3506814862982c3df07ddc92d69b Mon Sep 17 00:00:00 2001 From: Josh Burman Date: Tue, 17 Aug 2021 12:33:58 -0400 Subject: [PATCH 4/4] add check affix to endpoints --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7465ad8..18fcd45 100644 --- a/app/main.py +++ b/app/main.py @@ -6,7 +6,7 @@ app = FastAPI() async def root(): return {"message": "Welcome to Measures LOFT solver service. v0.1"} -@app.get("/health") +@app.get("/healthcheck") async def health(): content = { "maintainer": "Meazure Horizon Team", @@ -17,6 +17,6 @@ async def health(): } return content -@app.get('/ready') +@app.get('/readycheck') async def ready(): return 'OK' # just means we're on air