-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request response parameters #19
base: main
Are you sure you want to change the base?
Conversation
…igital/eq-cir-converter-service into request-response-parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left some comments for discussion at this early stage 👍
Dockerfile
Outdated
@@ -8,6 +8,8 @@ RUN pip install --no-cache-dir poetry==1.8.4 && \ | |||
poetry config virtualenvs.create false && \ | |||
poetry install --no-root --no-dev | |||
|
|||
COPY . /app | |||
COPY src src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to call the src
folder eq_cir_converter_service
more meaningful that way, and aligns with what we do in eQ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
src/app/routers/schema_router.py
Outdated
target_version: str, | ||
schema: dict, | ||
) -> dict: | ||
"""Convert the CIR schema from one version to another.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again minor but the docstring should probably include the args/return info, worth keeping these up to date from the beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, added the necessary comments
Dockerfile
Outdated
@@ -8,6 +8,8 @@ RUN pip install --no-cache-dir poetry==1.8.4 && \ | |||
poetry config virtualenvs.create false && \ | |||
poetry install --no-root --no-dev | |||
|
|||
COPY . /app | |||
COPY src src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the tests
folder has moved into the src
folder in a later commit in this PR, I think this means we are copying it into the Docker image as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, not related to this PR but we should probably try to use a slim base image for python (similar to Runner). I will raise a tech debt ticket 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, used the slim Python image instead, copied only the app folder, so the tests folder is not copied into the docker image.
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107", | ||
# Disable line length check as it is handled by black | ||
# :TODO: Remove E501 when ruff supports all black rules | ||
"E501", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to keep E501
in to prevent duplicates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the ignore warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be an issue with the linting step at the moment, when I run locally it seems to catch some errors that are not being reported as part of the run in the actions workflow
@berroar Linting is alright in local and github, all issues are solved, could you please check. |
@@ -8,6 +8,6 @@ RUN pip install --no-cache-dir poetry==1.8.4 && \ | |||
poetry config virtualenvs.create false && \ | |||
poetry install --no-root --no-dev | |||
|
|||
COPY . /app | |||
COPY eq_cir_converter_service eq_cir_converter_service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to match the similar way Runner have their Dockerfile, we would keep the repo folder named as app
and just name the working folder to eq_cir_converter_service
at build time so like:
...
WORKDIR /eq_cir_converter_service
COPY pyproject.toml poetry.lock /eq_cir_converter_service/
RUN install the deps
COPY ./app /eq_cir_converter_service/app
...
This way, we can also handle the poetry installation steps separately, before copying the app folder later in the build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point to note is that we have a docker-compose.yml
file which mounts the entire app
folder, which we would need to remove otherwise we would be having 2 separate loads of the app
folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamtoozer Again, what we have now is ideal - we are installing the dependencies and then copying the eq_cir_converter_service
, just renamed the WORKDIR
to /root
so we don't have the app
folder name in two places. Also, the docker-compose
is used only locally to spin up the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the docker-compose might still be adding the repo contents and naming it as app
in the volume mount config, so application code is being copied in 2 places - in root
and in app
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamtoozer As discussed, removed docker-compose.yml completely to avoid further confusion since we have only one docker container, updated the make file commands accordingly.
@@ -1,4 +1,4 @@ | |||
FROM python:3.12.6 | |||
FROM python:3.12.6-slim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering if we can try alpine instead of slim here now, as SDS are using alpine for their base image 🤔
Happy to park and revisit later, but given that we dropped image size in this PR, it might be worthwhile? Might also be worth calling this out in the PR description, or ideally a separate PR, but appreciate that it's still early days for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamtoozer We already reduced the image size to around 200 MB from more than a GB initially, not sure what we are trying to achieve here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I raised a ticket to look into reducing the Docker image size originally in my earlier review #19 (comment), but it was then changed in this PR shortly after, so thought it could maybe be reduced even further as we are doing it in this PR anyway? Ideally, images should be as small as possible for quicker deployments, spinning up locally etc but happy to leave as slim 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the above, wherever possible we should be trying to make sure any images we are using only contain the minimum/only what they need to run as this minimises the number of potential security vulnerabilities, so it not just the speed/size considerations (which are also important).
from typing import Any | ||
|
||
|
||
def get_log_level() -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V minor - We should try and use os.getenv()
where possible
Also, appreciate this is just for logging, but I think the function might need to return int
and handle incorrect env var logging level if getattr
doesn't find a logger match for an incorrectly named LOG_LEVEL
? We can default with something like getattr(logging, log_level, logging.INFO)
or something similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamtoozer This is already taken care in the line log_level = os.environ.get("LOG_LEVEL", "INFO")
, it returns INFO
by default when LOG_LEVEL
is not defined. The Any
return type is correct since it aligns with the return type of getattr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to document log_level (and any other env vars) in the readme, as if it is not set to a valid value the app will fall over. I think the type hinting does need to be updated as in reality only an int can ever be returned here without the app breaking. Also since this can break the app if set incorrectly would be good to have a test for this, when parsing is added/this is handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@berroar Okay, there was a lint error when the return type was changed to int, it is sorted now, refactored getattr
with the default setting of INFO
. Documented LOG_LEVEL
setting in README
, also added unit tests for the logging level configuration.
…igital/eq-cir-converter-service into request-response-parameters
What is the context of this PR?
https://jira.ons.gov.uk/browse/CIMS-37
This PR is to define the request and response parameters for the API endpoint
Request body -
Request query parameters -
Response -
How to review
Run the commands
make docker-build
andmake docker-run
to spin up the local application, launch the FastAPI webpage and test the endpoint with the below sample JSON in the POST request.{"valid_json": "valid_json"}