Skip to content
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

CIMS-4 - Install fastapi and spin up local Hello World application #4

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2c7b35d
installed fastapi and uvicorn
sudeepkunhis Dec 4, 2024
421b261
added hello world method
sudeepkunhis Dec 4, 2024
a37b83a
fixed formatting
sudeepkunhis Dec 4, 2024
d7616a8
installed https dev dependency
sudeepkunhis Dec 4, 2024
2d927a2
set hello world response
sudeepkunhis Dec 4, 2024
878c15b
initial test and run pytest using poetry
sudeepkunhis Dec 4, 2024
5632e3f
initial test framework
sudeepkunhis Dec 4, 2024
d09697a
ignored assert lint error
sudeepkunhis Dec 4, 2024
6207553
return type in main
sudeepkunhis Dec 4, 2024
55183d4
ignore assert rule
sudeepkunhis Dec 4, 2024
f49909b
rearranged directory structure
sudeepkunhis Dec 4, 2024
a7e3613
updated lock file
sudeepkunhis Dec 4, 2024
247435e
added make run
sudeepkunhis Dec 4, 2024
b17b305
set the port value
sudeepkunhis Dec 5, 2024
9667ca7
initial docker framework
sudeepkunhis Dec 5, 2024
2bedf4b
initial docker-compose
sudeepkunhis Dec 5, 2024
1dcad16
test commit
sudeepkunhis Dec 5, 2024
dd99ccf
fixed megalint, set poetry version in docker and no cache
sudeepkunhis Dec 5, 2024
0061fbc
cleanup
sudeepkunhis Dec 5, 2024
2db7829
makefile entries to start and stop docker
sudeepkunhis Dec 5, 2024
1740c7f
make commands to start and stop docker
sudeepkunhis Dec 9, 2024
0488ebb
makefile changes
sudeepkunhis Dec 9, 2024
7848e08
makefile changes
sudeepkunhis Dec 9, 2024
161e07d
simplified docker commands
sudeepkunhis Dec 9, 2024
78935e9
empty CODEOWNERS
sudeepkunhis Dec 9, 2024
dd30344
updated ruff
sudeepkunhis Dec 10, 2024
1dd0f1d
updated packages
sudeepkunhis Dec 10, 2024
4c06726
Merge branch 'main' into install-fastapi
sudeepkunhis Dec 10, 2024
84624dc
test commit
sudeepkunhis Dec 10, 2024
169d8c5
test commit
sudeepkunhis Dec 10, 2024
274d101
comments in the makefile
sudeepkunhis Dec 11, 2024
240ccdc
Add instructions for building the Docker image to README
sudeepkunhis Dec 11, 2024
d8dba8a
Update README with Docker container management instructions and disab…
sudeepkunhis Dec 11, 2024
e9fa4d7
Disable Markdown link check in linter configuration and update README…
sudeepkunhis Dec 11, 2024
d88dcd8
test cloud build
sudeepkunhis Dec 16, 2024
c56df7e
test cloud build - 1
sudeepkunhis Dec 16, 2024
a6cd457
test cloud build and deploy
sudeepkunhis Dec 16, 2024
ed6af95
test cloud build and deploy - 1
sudeepkunhis Dec 16, 2024
66edf1d
test cloud build and deploy - 2
sudeepkunhis Dec 16, 2024
fd540d5
pass lint
sudeepkunhis Dec 16, 2024
260b01c
test cloud build with env var
sudeepkunhis Dec 16, 2024
7fda29a
test cloud build with env var - 1
sudeepkunhis Dec 16, 2024
622cfa5
test cloud build with env var - 2
sudeepkunhis Dec 16, 2024
5113f86
test cloud build with env var - 3
sudeepkunhis Dec 16, 2024
1781eba
test cloud build in dev project
sudeepkunhis Dec 17, 2024
2b30d16
set the port value
sudeepkunhis Dec 17, 2024
f0b624d
check unauthenticated
sudeepkunhis Dec 17, 2024
b1f0be8
test cloud build
sudeepkunhis Dec 18, 2024
c3eb283
test cloud build - 1
sudeepkunhis Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.12.6

WORKDIR /app

COPY pyproject.toml poetry.lock /app/

RUN pip install --no-cache-dir poetry==1.8.4 && poetry install --no-root --no-dev

COPY . /app

CMD ["poetry", "run", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "5010"]
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ lint: ## Run all linters (black/ruff/pylint/mypy).

.PHONY: test
test: ## Run the tests and check coverage.
poetry run pytest -n auto --cov=eq_cir_converter_service --cov-report term-missing --cov-fail-under=100
poetry run pytest -n auto --cov=src --cov-report term-missing --cov-fail-under=100

.PHONY: mypy
mypy: ## Run mypy.
poetry run mypy eq_cir_converter_service
poetry run mypy src

.PHONY: install
install: ## Install the dependencies excluding dev.
Expand All @@ -48,3 +48,23 @@ megalint: ## Run the mega-linter.
-v /var/run/docker.sock:/var/run/docker.sock:rw \
-v $(shell pwd):/tmp/lint:rw \
oxsecurity/megalinter:v7

.PHONY: run
run:
poetry run uvicorn src.main:app --reload --port 5010

.PHONY: docker-build
docker-build:
docker build -t cir-converter-service .

.PHONY: docker-run
docker-run:
docker run -p 5010:5010 cir-converter-service
sudeepkunhis marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: docker-compose-up
docker-compose-up:
docker-compose up -d

.PHONY: docker-stop
docker-stop:
docker stop $(shell docker ps -a -q --filter ancestor=eq-cir-converter-service-web && docker ps -a -q --filter ancestor=cir-converter-service)
sudeepkunhis marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
web:
build: .
ports:
- "5010:5010"
volumes:
- .:/app
76 changes: 0 additions & 76 deletions eq_cir_converter_service/calculator.py

This file was deleted.

537 changes: 440 additions & 97 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package-mode = false

[tool.poetry.dependencies]
python = "^3.10"
fastapi = "^0.115.6"
uvicorn = "^0.32.1"

[tool.poetry.group.dev.dependencies]
# :TODO: Remove pylint when ruff supports all pylint rules
Expand All @@ -20,6 +22,7 @@ pytest-xdist = "^3.6.1"
ruff = "^0.7.1"
pytest-cov = "^5.0.0"
mypy = "^1.13.0"
httpx = "^0.28.0"

[tool.black]
line-length = 120
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fastapi

app = fastapi.FastAPI()


# Simple hello world endpoint
@app.get("/")
def index() -> dict:
return {"message": "Hello World!"}
14 changes: 6 additions & 8 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest
# import pytest

from eq_cir_converter_service.calculator import Calculator


@pytest.fixture()
def calculator():
# Create a new instance of the Calculator class for each test session.
yield Calculator()
# Clean up after the test session is complete.
# @pytest.fixture()
# def calculator():
# # Create a new instance of the Calculator class for each test session.
# yield Calculator()
# # Clean up after the test session is complete.
57 changes: 0 additions & 57 deletions tests/unit/test_calculator.py

This file was deleted.

12 changes: 12 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from fastapi import status
from fastapi.testclient import TestClient

from src.main import app

client = TestClient(app)


def test_read_main():
response = client.get("/")
assert response.status_code == status.HTTP_200_OK
assert response.json() == {"message": "Hello World!"}
Loading