Dockerizing the project
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
venv
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.db
|
||||||
|
.git
|
||||||
|
.env
|
||||||
+2
-1
@@ -3,4 +3,5 @@ __pycache__
|
|||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
venv/
|
venv/
|
||||||
test.txt
|
test.txt
|
||||||
diff.txt
|
diff.txt
|
||||||
|
test.db
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
@@ -30,4 +30,10 @@ python -m pytest --cov=app --cov-report=term-missing
|
|||||||
```bash
|
```bash
|
||||||
cd /opt/kjc/int/URL-shortener
|
cd /opt/kjc/int/URL-shortener
|
||||||
alembic revision --autogenerate -m "create urls table"
|
alembic revision --autogenerate -m "create urls table"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running project in Docker container
|
||||||
|
```bash
|
||||||
|
cd /opt/kjc/int/URL-shortener
|
||||||
|
docker compose up --build
|
||||||
```
|
```
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# app/utils.py
|
|
||||||
|
|
||||||
import string
|
|
||||||
import random
|
|
||||||
|
|
||||||
def generate_short_code(length=6):
|
|
||||||
characters = string.ascii_letters + string.digits
|
|
||||||
return ''.join(random.choice(characters) for _ in range(length))
|
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:16
|
||||||
|
container_name: url_shortener_db
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_DB: url_db
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
container_name: url_shortener_app
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgresql+psycopg2://postgres:postgres@db:5432/url_db
|
||||||
|
BASE_URL: http://localhost:8000
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
command: >
|
||||||
|
sh -c "alembic upgrade head &&
|
||||||
|
uvicorn app.main:app --host 0.0.0.0 --port 8000"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fastapi==0.124.4
|
||||||
|
uvicorn[standard]==0.33.0
|
||||||
|
sqlalchemy==2.0.47
|
||||||
|
psycopg2-binary==2.9.10
|
||||||
|
alembic==1.14.1
|
||||||
|
pydantic-settings==2.8.1
|
||||||
|
|
||||||
|
pytest==8.3.5
|
||||||
|
pytest-cov==5.0.0
|
||||||
Reference in New Issue
Block a user