diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..8ce0778a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Terraform +terraform.tfstate +terraform.tfstate.* +.terraform/ + diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..3a4918018 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,29 @@ +# Stage 1: Build +FROM python:3.11-slim AS builder + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt + +# Stage 2: Run + +FROM python:3.11-slim + +RUN useradd -m appuser + +WORKDIR /app + + +COPY --from=builder /usr/local/lib/python3.11 /usr/local/lib/python3.11 +COPY --from=builder /usr/local/bin /usr/local/bin + +COPY app ./app + +USER appuser + +EXPOSE 8000 + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] + diff --git a/backend/requirements.txt b/backend/requirements.txt index 212f2fc66..aeee8a106 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,3 +2,5 @@ fastapi==0.104.1 uvicorn==0.24.0 pydantic==2.4.2 python-dotenv==1.0.0 +pytest==7.4.3 +httpx==0.25.1 diff --git a/backend/tests/__pycache__/test_main.cpython-310-pytest-7.4.3.pyc b/backend/tests/__pycache__/test_main.cpython-310-pytest-7.4.3.pyc new file mode 100644 index 000000000..a166f6ba2 Binary files /dev/null and b/backend/tests/__pycache__/test_main.cpython-310-pytest-7.4.3.pyc differ diff --git a/backend/tests/test_main.py b/backend/tests/test_main.py new file mode 100644 index 000000000..ee40ffcfd --- /dev/null +++ b/backend/tests/test_main.py @@ -0,0 +1,15 @@ +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + +def test_health_check(): + response = client.get("/api/health") + assert response.status_code == 200 + assert response.json()["status"] == "healthy" + +def test_get_message(): + response = client.get("/api/message") + assert response.status_code == 200 + assert "message" in response.json() +