Skip to content

Commit 8be744d

Browse files
authored
Merge pull request #75 from grillazz/69-switch-to-pymongo-for-async
69 switch to pymongo for async
2 parents 4fa7093 + b7aea29 commit 8be744d

File tree

7 files changed

+193
-7
lines changed

7 files changed

+193
-7
lines changed

DockerfileOracleLinux

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM eurolinux/oracle-linux-9:oracle-linux-9-9.4.3-arm64 AS build
2+
3+
RUN dnf install python3.12 python3.12-devel -y
4+
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
6+
7+
ENV UV_LINK_MODE=copy \
8+
UV_COMPILE_BYTECODE=1 \
9+
UV_PYTHON_DOWNLOADS=never \
10+
UV_PYTHON=python3.12 \
11+
UV_PROJECT_ENVIRONMENT=/app
12+
13+
COPY pyproject.toml /_lock/
14+
COPY uv.lock /_lock/
15+
16+
RUN --mount=type=cache,target=/root/.cache
17+
RUN cd /_lock && uv sync \
18+
--locked \
19+
--no-dev \
20+
--no-install-project
21+
22+
# Clean up unnecessary files
23+
RUN dnf clean all
24+
RUN rm -rf /var/cache/dnf /var/lib/dnf/history.* /usr/share/doc /usr/share/man /usr/share/info /usr/share/locale /tmp/* /var/tmp/* /root/.cache
25+
26+
FROM eurolinux/oracle-linux-9:oracle-linux-9-9.4.3-arm64
27+
28+
ENV PATH=/app/bin:$PATH
29+
30+
RUN groupadd -r app
31+
RUN useradd -r -d /app -g app -N app
32+
33+
STOPSIGNAL SIGINT
34+
35+
RUN dnf install python3.12 -y
36+
37+
RUN dnf clean all
38+
RUN rm -rf /var/cache/dnf /var/lib/dnf/history.* /usr/share/doc /usr/share/man /usr/share/info /usr/share/locale /tmp/* /var/tmp/* /root/.cache
39+
40+
41+
COPY --from=build --chown=app:app /app /app
42+
43+
USER app
44+
WORKDIR /app
45+
COPY /greens/ greens/
46+
COPY /tests/ tests/
47+
COPY .env greens/
48+
49+
RUN python -V
50+
RUN python -Im site
51+
RUN python -Ic 'import uvicorn'

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
help: ## Show this help
33
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
44

5-
.PHONY: build
6-
build: ## Build project with compose
7-
docker compose -f compose.yml up
5+
.PHONY: build-app
6+
build-app: ## Build project with compose
7+
docker build . -t fastapi-mongodb-ubuntu-app:latest
8+
9+
.PHONY: build-oracle-linux-app
10+
build-oracle-linux-app: ## Build project with compose on oracle linux
11+
docker build . --file DockerfileOracleLinux -t fastapi-mongodb-oracle-app:latest
812

913
.PHONY: up
1014
up: ## Run project with compose

compose-oracle.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
web:
3+
image: ora:004
4+
env_file:
5+
- .env
6+
command: bash -c "
7+
uvicorn greens.main:app
8+
--host 0.0.0.0 --port 8989
9+
--lifespan=on --use-colors --loop uvloop --http httptools
10+
--reload
11+
"
12+
volumes:
13+
- ./greens:/app/greens
14+
- ./tests:/app/tests
15+
ports:
16+
- "8989:8989"
17+
depends_on:
18+
- mongodb
19+
20+
mongodb:
21+
image: mongo:7.0.8
22+
env_file:
23+
- .env
24+
ports:
25+
- "27017:27017"
26+
environment:
27+
- "MONGO_INITDB_DATABASE=${MONGODB_DATABASE}"
28+
- "MONGO_INITDB_ROOT_USERNAME=${MONGODB_USER}"
29+
- "MONGO_INITDB_ROOT_PASSWORD=${MONGODB_PASSWORD}"
30+
command:
31+
mongod --quiet --logpath /dev/null

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
web:
3-
build: .
3+
image: ora:004
44
env_file:
55
- .env
66
command: bash -c "

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "fastapi-mongodb"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
6-
requires-python = ">=3.13"
6+
requires-python = ">=3.12"
77
dependencies = [
88
"fastapi[standard]>=0.115.8",
99
"httptools>=0.6.4",

tests/test_routers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ async def test_health_check(client: AsyncClient):
1111
assert response.json() == snapshot(
1212
{
1313
"version": "7.0.8",
14-
"databases": ["admin", "config", "local"],
14+
"databases": [
15+
"admin",
16+
"config",
17+
# "farmland",
18+
"local"
19+
],
1520
"collections": {
1621
"admin": ["system.version", "system.users"],
1722
"config": ["system.sessions"],
23+
# "farmland": ["greens"],
1824
"local": ["startup_log"],
1925
},
2026
}

0 commit comments

Comments
 (0)