Skip to content
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

Initial Setup for Secret Notes Project with Docker, Django, and Kubernetes #1

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
22e2774
feat: initialize Django project and create notes app
MohamedFadel01 Oct 7, 2024
8a038e9
chore: update .gitignore to include .vscode and switch database to Po…
MohamedFadel01 Oct 7, 2024
6006acb
feat: add SecretNote model with view tracking and expiration logic
MohamedFadel01 Oct 7, 2024
af6ecd8
feat: add SecretNoteForm to handle note creation with optional expira…
MohamedFadel01 Oct 7, 2024
e33e581
feat: add create_note.html template for creating secret notes
MohamedFadel01 Oct 7, 2024
0480c5f
feat: add note_created.html template for displaying the created note …
MohamedFadel01 Oct 7, 2024
9efc0fe
feat: add note_view.html template to display secret notes
MohamedFadel01 Oct 7, 2024
83ac043
feat: add note_expired.html template for expired or already viewed notes
MohamedFadel01 Oct 7, 2024
8cb53d9
feat: implement create_note view to handle note creation with optiona…
MohamedFadel01 Oct 8, 2024
49e25f8
feat: add view_note view to handle note viewing and expiration checks
MohamedFadel01 Oct 8, 2024
cc3cc81
feat: include notes app URLs in the main project urls.py
MohamedFadel01 Oct 8, 2024
61b585a
feat: add rate limit error template
MohamedFadel01 Oct 8, 2024
2af02fb
feat: add rate limiting to create and view note endpoints
MohamedFadel01 Oct 8, 2024
e3de391
test: add unit tests for SecretNote model methods
MohamedFadel01 Oct 8, 2024
ee7ebc1
test: add unit tests for SecretNoteForm validation
MohamedFadel01 Oct 8, 2024
f5e06ce
fix: correct is_expired method logic and test_invalid_form
MohamedFadel01 Oct 9, 2024
949cdf6
test: add view test for note creation functionality
MohamedFadel01 Oct 9, 2024
2e4fbfc
test: add view test for note viewing
MohamedFadel01 Oct 9, 2024
a89aabe
fix: add CSRF token to the create note form
MohamedFadel01 Oct 9, 2024
452583a
feat: implement custom rate limit error handling middleware
MohamedFadel01 Oct 9, 2024
13ebdc8
feat: add styling and index page and adjusting templates
MohamedFadel01 Oct 9, 2024
2039cc7
feat: add custom 404 error handling middleware and a template for it
MohamedFadel01 Oct 9, 2024
6b1dd79
feat: add user authentication, linked SecretNote to User model and ad…
MohamedFadel01 Oct 9, 2024
007fa93
test: add tests for user authentication, note creation, and note view…
MohamedFadel01 Oct 10, 2024
a93aa2f
test: add integration tests for note creation, viewing, and user flows
MohamedFadel01 Oct 10, 2024
183c533
test: add end-to-end tests
MohamedFadel01 Oct 10, 2024
c1796d8
ci: add GitHub Actions workflow for linting, formatting, and testing
MohamedFadel01 Oct 11, 2024
72ba307
chore(docker): add Dockerization for project deployment
MohamedFadel01 Oct 11, 2024
f43383d
docker: try to reduce image size
MohamedFadel01 Oct 11, 2024
d0d6d38
feat(deployment): enhance dockerization and add Helm chart for secret…
MohamedFadel01 Oct 15, 2024
8c629db
feat: update CI workflow and add test settings
MohamedFadel01 Oct 15, 2024
7233f39
feat: add flake8 configuration and update CI workflow
MohamedFadel01 Oct 15, 2024
af57de1
fix: try to fix github actions errors
MohamedFadel01 Oct 15, 2024
d3a990c
docs: update README with project details, setup, and deployment instr…
MohamedFadel01 Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
exclude =
migrations,
__pycache__,
manage.py,
settings.py,
env
max-line-length = 88
extend-ignore = E203
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [main, development]
pull_request:
branches: [main]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
- name: Run formatting check
run: black --check .

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
env:
DJANGO_SETTINGS_MODULE: secret_notes_project.test_settings
run: |
python manage.py test
python manage.py test notes.integration_tests
python manage.py test notes.e2e_tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ venv/
ENV/
env.bak/
venv.bak/
.vscode

# Spyder project settings
.spyderproject
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.10-alpine

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

RUN apk add --no-cache gcc musl-dev

COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt

COPY . .

RUN python manage.py collectstatic --noinput

COPY wait_for_db.sh /wait_for_db.sh
RUN chmod +x /wait_for_db.sh

CMD sh -c "/wait_for_db.sh && python manage.py migrate && python manage.py collectstatic --noinput && exec gunicorn secret_notes_project.wsgi:application --bind 0.0.0.0:8008"
121 changes: 120 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,120 @@
# SecretNote-MVC-MohamedFadel
# Secret Notes Project

Secret Notes is a Django-based web application that allows users to create and share secure, self-destructing notes. The project is containerized using Docker and can be easily deployed using Docker Compose or Kubernetes.

## Features

- Create secure, encrypted notes
- Set expiration time for notes
- View notes using unique URL keys
- User registration and authentication
- Rate limiting to prevent abuse
- Dockerized application for easy deployment

## Prerequisites

- Docker and Docker Compose
- Kubernetes (optional, for k8s deployment)

## Quick Start

1. Clone the repository:

```
git clone https://github.com/codescalersinternships/SecretNote-MVC-MohamedFadel/tree/development
cd SecretNote-MVC-MohamedFadel
```

2. Start the application using Docker Compose:

```
docker-compose up --build
```

3. Access the application at `http://localhost:8008`

## Project Structure

```
.
├── docker-compose.yaml
├── Dockerfile
├── manage.py
├── notes/ # Main application
├── README.md
├── requirements.txt
├── secret-note/ # Helm chart for Kubernetes deployment
├── secret_notes_project/ # Django project settings
├── staticfiles/
└── wait_for_db.sh
```

## Development

To set up the development environment:

1. Create a virtual environment:

```
python -m venv venv
source venv/bin/activate
```

2. Install dependencies:

```
pip install -r requirements.txt
```

3. Run migrations:

```
python manage.py migrate
```

4. Start the development server:
```
python manage.py runserver
```

## Testing

The project includes various test files:

- `notes/tests.py`: Unit tests
- `notes/integration_tests.py`: Integration tests
- `notes/e2e_tests.py`: End-to-end tests

To run the tests:

```
python manage.py test
```

## Deployment

### Docker Compose

Use the provided `docker-compose.yaml` file to deploy the application:

```
docker-compose up --build
```

### Kubernetes

A Helm chart is provided in the `secret-note` directory for Kubernetes deployment. To deploy using Helm:

1. Install Helm (if not already installed)
2. From the project root, run:
```
helm install secret-notes ./secret-note
```

## Configuration

The main configuration files are:

- `secret_notes_project/settings.py`: Django settings
- `docker-compose.yaml`: Docker Compose configuration
- `secret-note/values.yaml`: Helm chart values for Kubernetes deployment
32 changes: 32 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
services:
secret-note-db:
image: postgres
volumes:
- ./data/secret-note-db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=secretnote
- POSTGRES_USER=secretnote
- POSTGRES_PASSWORD=secretnote
- POSTGRES_HOST=secret-note-db
- POSTGRES_PORT=5432
- DATABASE_URL=postgres://secretnote:secretnote@secret-note-db:5432/secretnote

web:
build: .
command: >
sh -c "until nc -z secret-note-db 5432; do echo waiting for secret-note-db; sleep 1; done &&
python manage.py migrate &&
python manage.py collectstatic --noinput &&
gunicorn secret_notes_project.wsgi:application --bind 0.0.0.0:8008"
volumes:
- .:/app
ports:
- "8008:8008"
environment:
- DATABASE_URL=postgres://secretnote:secretnote@secret-note-db:5432/secretnote
- DEBUG=False
depends_on:
- secret-note-db

volumes:
static_volume:
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "secret_notes_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
Empty file added notes/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions notes/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NotesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "notes"
Loading
Loading