-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT] Add Containerization with Docker #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0778bb4
[FEAT] Add Containerization with Docker
martian56 5deb3ee
[FIX] Fix pydantic issue in docker compose
nadir2609 8767ddb
[FIX] Add docker-entrypoint.sh for db migrations
martian56 431afc1
[FIX] Fix security issue by running the application as non-root user
martian56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,4 +79,5 @@ htmlcov/ | |
| *.temp | ||
| .cache/ | ||
|
|
||
|
|
||
| # Architecture | ||
| ARCHITECTURE.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| venv/ | ||
| env/ | ||
| ENV/ | ||
| .venv | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| *.log | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Project specific | ||
| *.md | ||
| .git/ | ||
| .gitignore | ||
| tests/ | ||
| pytest.ini | ||
| pyproject.toml | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| FROM python:3.12-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN apt-get update && apt-get install -y \ | ||
| gcc \ | ||
| postgresql-client \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| # Create non-root user | ||
| RUN useradd -m -u 1000 appuser | ||
|
|
||
| COPY . . | ||
|
|
||
|
martian56 marked this conversation as resolved.
|
||
| # Set ownership and permissions | ||
| RUN chown -R appuser:appuser /app && \ | ||
| chmod +x /app/docker-entrypoint.sh | ||
|
|
||
| # Switch to non-root user | ||
| USER appuser | ||
|
|
||
| EXPOSE 8000 | ||
|
|
||
|
martian56 marked this conversation as resolved.
|
||
| ENTRYPOINT ["/app/docker-entrypoint.sh"] | ||
| CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] | ||
|
martian56 marked this conversation as resolved.
|
||
|
|
||
|
martian56 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| echo "Running database migrations..." | ||
| alembic upgrade head | ||
|
|
||
| echo "Starting API server..." | ||
| exec "$@" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| services: | ||
| api: | ||
| build: | ||
| context: ./api | ||
| dockerfile: Dockerfile | ||
| container_name: chatops-api | ||
| ports: | ||
| - "8000:8000" | ||
| environment: | ||
| - DATABASE_URL=postgresql://user:password@db:5432/chatops | ||
| - SECRET_KEY=your-secret-key-change-in-production | ||
|
martian56 marked this conversation as resolved.
|
||
| - 'CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"]' | ||
| depends_on: | ||
| - db | ||
|
martian56 marked this conversation as resolved.
|
||
| volumes: | ||
| - ./api/.env:/app/.env # Mount .env file if it exists | ||
| restart: unless-stopped | ||
|
|
||
| db: | ||
| image: postgres:16-alpine | ||
| container_name: chatops-db | ||
| environment: | ||
| - POSTGRES_USER=user | ||
| - POSTGRES_PASSWORD=password | ||
|
martian56 marked this conversation as resolved.
|
||
| - POSTGRES_DB=chatops | ||
| ports: | ||
| - "5432:5432" | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
| restart: unless-stopped | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.