Skip to content

Commit 9bac503

Browse files
committed
Basic skeleton
1 parent 2b3c42f commit 9bac503

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# dotenv files
2+
.env
3+
.env.local
4+
5+
# Mac
6+
.DS_Store
7+
8+
# editor and IDE files
9+
.vscode/

services/question-service/.gitkeep

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ======================
2+
# 1. Base Image
3+
# ======================
4+
FROM python:3.12-slim AS base
5+
6+
# Set working directory
7+
WORKDIR /app
8+
9+
# Prevent Python from writing .pyc files and enable buffered output
10+
ENV PYTHONDONTWRITEBYTECODE=1 \
11+
PYTHONUNBUFFERED=1
12+
13+
# Install system dependencies ()
14+
# RUN apt-get update && apt-get install -y --no-install-recommends \
15+
# build-essential gcc curl \
16+
# && rm -rf /var/lib/apt/lists/*
17+
18+
# ======================
19+
# 2. Dependencies Stage
20+
# ======================
21+
FROM base AS deps
22+
23+
# Install Python dependencies separately to leverage Docker cache
24+
COPY requirements.txt .
25+
RUN pip install --no-cache-dir --upgrade pip \
26+
&& pip install --no-cache-dir -r requirements.txt
27+
28+
# ======================
29+
# 3. Runtime Stage
30+
# ======================
31+
FROM base AS runtime
32+
33+
# Create a non-root user
34+
RUN useradd -m fastapiuser
35+
36+
# Copy installed deps from deps stage
37+
COPY --from=deps /usr/local/lib/python3.12 /usr/local/lib/python3.12
38+
COPY --from=deps /usr/local/bin /usr/local/bin
39+
40+
# Copy application code
41+
COPY . .
42+
43+
# Set ownership
44+
RUN chown -R fastapiuser:fastapiuser /app
45+
USER fastapiuser
46+
47+
# Expose FastAPI default port
48+
EXPOSE 8000
49+
50+
# Run the application with uvicorn
51+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Union
2+
3+
from fastapi import FastAPI
4+
5+
app = FastAPI()
6+
7+
@app.get("/")
8+
async def read_root():
9+
return {"Hello": "World"}
10+
11+
@app.get("/items/{item_id}")
12+
async def read_item(item_id: int, q: Union[str, None] = None):
13+
return {"item_id": item_id, "q": q}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE difficulties (
2+
name VARCHAR(50) PRIMARY KEY
3+
);
4+
5+
CREATE TABLE topics (
6+
name VARCHAR(50) PRIMARY KEY
7+
);
8+
9+
CREATE TABLE questions (
10+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
11+
name VARCHAR(255) NOT NULL,
12+
description TEXT NOT NULL,
13+
difficulty VARCHAR(50) REFERENCES difficulties(name),
14+
topic VARCHAR(50) REFERENCES topics(name),
15+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
16+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
17+
);
18+
19+
CREATE TABLE question_images (
20+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
21+
question_id UUID REFERENCES questions(id) ON DELETE CASCADE,
22+
s3_key TEXT NOT NULL
23+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastapi[standard]
2+
psycopg[binary]

0 commit comments

Comments
 (0)