Skip to content

Commit 96e832d

Browse files
authored
Merge pull request #14 from martian56/13-containerization-with-docker
[FEAT] Add Containerization with Docker
2 parents 7dc6813 + 431afc1 commit 96e832d

5 files changed

Lines changed: 110 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ htmlcov/
7979
*.temp
8080
.cache/
8181

82-
82+
# Architecture
83+
ARCHITECTURE.md

api/.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
venv/
8+
env/
9+
ENV/
10+
.venv
11+
12+
# Testing
13+
.pytest_cache/
14+
.coverage
15+
htmlcov/
16+
*.log
17+
18+
# IDE
19+
.vscode/
20+
.idea/
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Project specific
30+
*.md
31+
.git/
32+
.gitignore
33+
tests/
34+
pytest.ini
35+
pyproject.toml
36+

api/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update && apt-get install -y \
6+
gcc \
7+
postgresql-client \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
COPY requirements.txt .
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Create non-root user
14+
RUN useradd -m -u 1000 appuser
15+
16+
COPY . .
17+
18+
# Set ownership and permissions
19+
RUN chown -R appuser:appuser /app && \
20+
chmod +x /app/docker-entrypoint.sh
21+
22+
# Switch to non-root user
23+
USER appuser
24+
25+
EXPOSE 8000
26+
27+
ENTRYPOINT ["/app/docker-entrypoint.sh"]
28+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
29+

api/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "Running database migrations..."
5+
alembic upgrade head
6+
7+
echo "Starting API server..."
8+
exec "$@"
9+

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
api:
3+
build:
4+
context: ./api
5+
dockerfile: Dockerfile
6+
container_name: chatops-api
7+
ports:
8+
- "8000:8000"
9+
environment:
10+
- DATABASE_URL=postgresql://user:password@db:5432/chatops
11+
- SECRET_KEY=your-secret-key-change-in-production
12+
- 'CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"]'
13+
depends_on:
14+
- db
15+
volumes:
16+
- ./api/.env:/app/.env # Mount .env file if it exists
17+
restart: unless-stopped
18+
19+
db:
20+
image: postgres:16-alpine
21+
container_name: chatops-db
22+
environment:
23+
- POSTGRES_USER=user
24+
- POSTGRES_PASSWORD=password
25+
- POSTGRES_DB=chatops
26+
ports:
27+
- "5432:5432"
28+
volumes:
29+
- postgres_data:/var/lib/postgresql/data
30+
restart: unless-stopped
31+
32+
volumes:
33+
postgres_data:
34+

0 commit comments

Comments
 (0)