Skip to content

Commit

Permalink
CIMS-4 - Install fastapi and spin up local Hello World application (#4)
Browse files Browse the repository at this point in the history
* installed fastapi and uvicorn

* added hello world method

* fixed formatting

* installed https dev dependency

* set hello world response

* initial test and run pytest using poetry

* initial test framework

* ignored assert lint error

* return type in main

* ignore assert rule

* rearranged directory structure

* updated lock file

* added make run

* set the port value

* initial docker framework

* initial docker-compose

* test commit

Signed-off-by: sudeep <[email protected]>

* fixed megalint, set poetry version in docker and no cache

Signed-off-by: sudeep <[email protected]>

* cleanup

* makefile entries to start and stop docker

* make commands to start and stop docker

* makefile changes

* makefile changes

* simplified docker commands

* empty CODEOWNERS

* updated ruff

* updated packages

* test commit

* test commit

* comments in the makefile

* Add instructions for building the Docker image to README

* Update README with Docker container management instructions and disable Markdown link check in linter

* Disable Markdown link check in linter configuration and update README to prevent link check for the local application URL

* test cloud build

* test cloud build - 1

* test cloud build and deploy

* test cloud build and deploy - 1

* test cloud build and deploy - 2

* pass lint

* test cloud build with env var

* test cloud build with env var - 1

* test cloud build with env var - 2

* test cloud build with env var - 3

* test cloud build in dev project

* set the port value

* check unauthenticated

* test cloud build

* test cloud build - 1

---------

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
sudeepkunhis authored Dec 30, 2024
1 parent 0ec59d3 commit 904980b
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 214 deletions.
File renamed without changes.
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"]
20 changes: 18 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,19 @@ 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: ## Start the local application.
poetry run uvicorn src.main:app --reload --port 5010

.PHONY: docker-build
docker-build: ## Build the docker image.
docker build -t cir-converter-service .

.PHONY: docker-compose-up
docker-compose-up: ## Start the docker container using docker-compose.
docker-compose up -d

.PHONY: docker-compose-down
docker-compose-down: ## Stop the docker container using docker-compose.
docker-compose down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ This repository is for the CIR Converter service Python FastAPI application
- [Development](#development)
- [Run Tests with Coverage](#run-tests-with-coverage)
- [Linting and Formatting](#linting-and-formatting)
- [Build the docker image](#build-the-docker-image)
- [Start the docker container](#start-the-docker-container)
- [View the local application](#view-the-local-application)
- [Stop the docker container](#stop-the-docker-container)
- [Contributing](#contributing)
- [License](#license)
<!-- markdown-link-check-enable -->
Expand Down Expand Up @@ -137,6 +141,30 @@ To start the linter and automatically rectify fixable issues, run:
make megalint
```

### Build the docker image

```bash
make docker-build
```

### Start the docker container

```bash
make docker-compose-up
```

### View the local application

<!-- markdown-link-check-disable-next-line -->
- Navigate to [http://localhost:5010/docs](http://localhost:5010/docs) to view the FastAPI application
- View the API endpoints available and test to see the response

### Stop the docker container

```bash
make docker-compose-down
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
Expand Down
31 changes: 31 additions & 0 deletions cloudbuild-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
steps:
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args: ["build", "-f", "Dockerfile", "-t", "europe-west2-docker.pkg.dev/${PROJECT_ID}/docker-images/cir-converter-service:$SHORT_SHA", "."]

# Push the container image to Google Artifact Registry
- name: "gcr.io/cloud-builders/docker"
args: ["push", "europe-west2-docker.pkg.dev/${PROJECT_ID}/docker-images/cir-converter-service:$SHORT_SHA"]

# Deploy the container to Google Cloud Run
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "Run container"
entrypoint: gcloud
args:
[
"run",
"deploy",
"cir-converter-service",
"--image",
"europe-west2-docker.pkg.dev/${PROJECT_ID}/docker-images/cir-converter-service:$SHORT_SHA",
"--port",
"5010",
"--region",
"europe-west2",
"--platform",
"managed",
"--allow-unauthenticated",
]

options:
logging: CLOUD_LOGGING_ONLY
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.

Loading

0 comments on commit 904980b

Please sign in to comment.