Skip to content

Commit

Permalink
Merge pull request #4 from Mirofff:feature/docker-wrapping
Browse files Browse the repository at this point in the history
feat: update docker-compose and dockerfile to wrap application + refactoring
  • Loading branch information
Mirofff authored Jul 28, 2024
2 parents 55ef0b1 + bfb1663 commit 78b57b4
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 28 deletions.
14 changes: 14 additions & 0 deletions .docker/app.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.12-slim-bullseye

WORKDIR /app

COPY requirements.txt requirements.txt

RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt

COPY src/ src/
COPY packages/ packages/
COPY settings.py settings.py
COPY function_app.py function_app.py

CMD ["uvicorn", "--host", "0.0.0.0", "--port", "80", "function_app:app"]
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ repos:
rev: v0.5.5
hooks:
- id: ruff
args: [--fix]
args: ["--fix", "--select", "I"]
- id: ruff-format
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"module": "uvicorn",
"args": [
"function_app:fastapi_app",
"function_app:app",
"--reload"
],
"justMyCode": false,
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,28 @@ services:
- "dynamodb:/home/dynamodblocal/data"
working_dir: /home/dynamodblocal

dynamodb-admin:
image: aaronshaf/dynamodb-admin
ports:
- "8001:8001"
environment:
- DYNAMO_ENDPOINT=http://local-dynamodb:8000
depends_on:
- local-dynamodb

app:
build:
context: .
dockerfile: .docker/app.dockerfile
ports:
- "8000:80"
environment:
- DB_ENDPOINT=http://local-dynamodb:8000
- DB_ACCESS_KEY=testing
- DB_SECRET_KEY=testing
- DB_TABLE=testing
- SIGNING_KEY=testing
- VERSION=0.1.1

volumes:
dynamodb:
8 changes: 3 additions & 5 deletions function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

logger = logging.getLogger()

logger.info("FASTAPI APPLICATION CREATION...")
app = app_rest.new_fastapi_app(semver.Version.parse(config.VERSION))

fastapi_app = app_rest.new_fastapi_app(semver.Version.parse(config.VERSION))
logger.info("FUNCTION INVOKE START")

logger.info("PASS ASGI APP TO FUNCTION")

handle = dispatcher.Dispatcher(fastapi_app)
handle = dispatcher.Dispatcher(app)

logger.info("FUNCTION INVOKE IS END!")
2 changes: 1 addition & 1 deletion packages/common/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Theres no base64 to python function - it's unsafe
"""

import typing as t
import base64
import json
import typing as t


def python_to_base64(obj: t.Any) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/database/dynamo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from boto3.dynamodb import conditions as boto_conditions
from types_aiobotocore_dynamodb import service_resource as aiodyno_service_types, type_defs as aiodyno_defs

from src.database.dynamo import connection as dyno_connection, serializers as dyno_serializers, common as dynamo_common
from src.database.dynamo import common as dynamo_common, connection as dyno_connection, serializers as dyno_serializers
from src.types import abstract as abstract_types, dynamo as dynamo_types

_T = t.TypeVar("_T", bound=abstract_types.AbstractDomainModel)
Expand Down
6 changes: 2 additions & 4 deletions src/database/dynamo/task.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import typing as t
import uuid

from types_aiobotocore_dynamodb import service_resource as aiodyno_types
from types_aiobotocore_dynamodb import type_defs as aiodyno_defs
from types_aiobotocore_dynamodb import service_resource as aiodyno_types, type_defs as aiodyno_defs

from src.database.dynamo import common as dynamo_common
from src.models import task as task_models
from src.models import user as user_models
from src.models import task as task_models, user as user_models


def _key(task_id: uuid.UUID, user_id: uuid.UUID) -> t.Mapping[str, aiodyno_defs.TableAttributeValueTypeDef]:
Expand Down
3 changes: 2 additions & 1 deletion src/entrypoints/rest/dtos/_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pydantic
import abc

import pydantic


class FromAttributesBaseModel(abc.ABC, pydantic.BaseModel):
model_config = pydantic.ConfigDict(from_attributes=True, arbitrary_types_allowed=True)
5 changes: 3 additions & 2 deletions src/entrypoints/rest/dtos/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import typing as t
import datetime
import fastapi
import enum
import typing as t

import fastapi

from ._base import FromAttributesBaseModel

Expand Down
1 change: 1 addition & 0 deletions src/entrypoints/rest/dtos/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing as t

import pydantic

from packages import common as common_packages
from src.types import dynamo as dynamo_types

Expand Down
6 changes: 3 additions & 3 deletions src/entrypoints/rest/routers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
! TODO: Logging
"""

import uuid
import typing as t
import uuid

import fastapi

from packages import common as common_package
from src.database.dynamo import common as dynamo_common
from src.entrypoints.rest.depends import auth as auth_depends, repositories as repositories_depends
from src.entrypoints.rest.dtos import common as common_dtos, tasks as tasks_dtos
from src.database.dynamo import common as dynamo_common
from src.handlers import task as task_handlers
from src.models import task as task_models
from packages import common as common_package

router = fastapi.APIRouter(prefix="/tasks", tags=["Tasks"])

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
! TODO: Logging
"""

from src.models import auth as auth_models, user as user_models
from src.database.dynamo import user as user_dynamo, connection as dynamo_connection
from src.database.dynamo import connection as dynamo_connection, user as user_dynamo
from src.exceptions import auth as auth_exceptions
from src.models import auth as auth_models, user as user_models


def generate_access_refresh(user: user_models.User) -> tuple[auth_models.AccessToken, auth_models.RefreshToken]:
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
! TODO: Logging
"""

import uuid
import typing as t
import uuid

from boto3.dynamodb import conditions as boto_conditions

from src.database.dynamo import common as dynamo_common, connection as dynamo_connection
from src.exceptions import common as common_exceptions
from src.models import task as task_models, user as user_models
from src.types import dynamo as dyno_types
from src.exceptions import common as common_exceptions


def _task_key(user: user_models.User, task_id: uuid.UUID = uuid.uuid4()) -> dyno_types.DynoItem:
Expand Down
3 changes: 1 addition & 2 deletions src/handlers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
! TODO: Logging
"""

from src.database.dynamo import connection as dynamo_connection
from src.database.dynamo import user as user_dynamo
from src.database.dynamo import connection as dynamo_connection, user as user_dynamo
from src.exceptions import user as user_exceptions
from src.models import user as user_models

Expand Down
3 changes: 2 additions & 1 deletion src/models/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import uuid

from src.types import abstract as abstract_types
import argon2

from src.types import abstract as abstract_types


class User(abstract_types.AbstractDomainModel):
__slots__ = {"id_", "email", "first_name", "last_name"}
Expand Down
3 changes: 2 additions & 1 deletion src/types/abstract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing as t
import abc
import typing as t

import attr


Expand Down
3 changes: 2 additions & 1 deletion src/types/dynamo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from types_aiobotocore_dynamodb import type_defs as aiodyno_defs
import typing as t

from types_aiobotocore_dynamodb import type_defs as aiodyno_defs

DynoItem = t.Mapping[str, aiodyno_defs.TableAttributeValueTypeDef]

0 comments on commit 78b57b4

Please sign in to comment.