Skip to content

Commit

Permalink
Bring back to Django (#16)
Browse files Browse the repository at this point in the history
* Bring back to Django

* Fix github tests

* Ensure shell scripts always have LF line endings

Signed-off-by: Nishant Nayak <[email protected]>

* Made a few more changes to docker files

* Added CONTRIBUTING guidelines

---------

Signed-off-by: Nishant Nayak <[email protected]>
Co-authored-by: Nishant Nayak <[email protected]>
  • Loading branch information
anirudhprabhakaran3 and nishant-nayak authored Aug 25, 2023
1 parent 7d22deb commit 938bd47
Show file tree
Hide file tree
Showing 55 changed files with 104 additions and 16,043 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/django_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: docker compose -f "docker-compose.yml" up -d --build

- name: Run Tests
run: docker compose exec backend python manage.py test
run: docker compose exec corpus python manage.py test

- name: Stop Containers
if: always()
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# End of https://www.toptal.com/developers/gitignore/api/django

# Node Modules
node_modules/
.svelte-kit/
# End of https://www.toptal.com/developers/gitignore/api/django
1 change: 0 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
python 3.11.1
nodejs 18.16.0
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Development Instructions

Versions for all the languages used in the project can be found in the `.tool-versions` file. Support will be provided for all Unix (MacOS, Debian/Ubuntu) based systems. If you choose to develop on Windows, we cannot promise anything xD. We also will not be supporting RHEL-based operating systems.

If you do not have access to a Unix machine, Docker is the recommended way for development.

### Pre Commit Hooks

We maintain code quality using pre-commit hooks (defined in [.pre-commit-config.yaml](.pre-commit-config.yaml)). All developers are requested to install all the pre-commit hooks before making any contributions to the codebase. Read more about pre-commit hooks [here](https://pre-commit.com/).

To install pre-commit hooks, run the following commands:

```shell
# Install the pre-commit framework
pip install pre-commit

# Install the pre-commit hooks
pre-commit install
```

### Docker Development

This is the preferred way for development. All modern editors allow you to open code in Docker containers remotely. If that is not possible, all code is mounted to Docker containers, so you can make changes that can be checked live.

For development, use the development Docker Compose file.

```shell
cp env.example .env

# Make required changes to the .env file

docker compose up --build
```

This Compose file will mount your codebase for dynamic updation.

## Working on the Local System

If you do not want to use Docker, you can do so by setting up the project locally. Ensure that you fetch the proper environment variables before doing so.

```shell
set -a
source .env
```

Apart from this, you will also have to set the `ENVIRONMENT` variable, which can be set to `DEVELOPMENT`.

Corpus depends on PostgreSQL. You might have it setup on your local system, or running it as a Docker container. Please make sure that you edit your environment variables accordingly so that proper configurations are set. You may also change the `ENVIRONMENT` to `DEVELOPMENT` to ensure that you have the Django debugging features available.

The application is a Django app. The recommended approach is to create a Python virtual environment, and setup the project (if you are using `conda`, please refer to that documentation for instructions).

```sh
python -m venv venv
source venv/bin/activate (on Windows: venv\Scripts\activate)
pip install --upgrade pip
pip install -r requirements.txt
```

After installing dependencies, you can setup the Django Project.

```sh
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
```
76 changes: 5 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,80 +32,14 @@ To remove all the previous data as well, you will have to remove the volumes too

For more guidance, refer to the [Docker Compose](https://docs.docker.com/compose/) documentation.

## Development Instructions

Versions for all the languages used in the project can be found in the `.tool-versions` file. Support will be provided for all Unix (MacOS, Debian/Ubuntu) based systems. If you choose to develop on Windows, we cannot promise anything xD. We also will not be supporting RHEL-based operating systems.

If you do not have access to a Unix machine, Docker is the recommended way for development.

### Pre Commit Hooks

We maintain code quality using pre-commit hooks (defined in [.pre-commit-config.yaml](.pre-commit-config.yaml)). All developers are requested to install all the pre-commit hooks before making any contributions to the codebase. Read more about pre-commit hooks [here](https://pre-commit.com/).

To install pre-commit hooks, run the following commands:

```shell
# Install the pre-commit framework
pip install pre-commit

# Install the pre-commit hooks
pre-commit install
```

### Docker Development

This is the preferred way for development. All modern editors allow you to open code in Docker containers remotely. If that is not possible, all code is mounted to Docker containers, so you can make changes that can be checked live.

For development, use the development Docker Compose file.

```shell
cp env.example .env

# Make required changes to the .env file

docker compose -f dev-docker-compose.yml up --build
```

This Compose file will mount your codebase and add automatic reloading to the frontend code.

If you still choose to go ahead and work on development on individual folders, instructions are given below. However, before development, make sure you source the `.env` file so that all necessary environment variables are picked up.

```shell
set -a
source .env
```

### Frontend

To work on the frontend, make sure you have Nodejs installed on your system. Once you have done that, you can install dependencies and run the server.

```sh
npm install
npm run dev
```

Make sure you properly mark any unnecessary and script generated files in `.gitignore` and `.dockerignore` files.

### Backend

The backend is a Django Rest Framework application. The recommended approach is to create a Python virtual environment, and setup the project.

```sh
python -m venv venv
source venv/bin/activate (on Windows: venv\Scripts\activate)
pip install --upgrade pip
pip install -r requirements.txt
```

After installing dependencies, you can setup the Django Project.
## Production Setup
For production setup, use the production docker compose file.

```sh
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
docker compose -f prod-docker-compose.yml up --build
```

Corpus depends on PostgreSQL. You might have it setup on your local system, or running it as a Docker container. Please make sure that you edit your environment variables accordingly so that proper configurations are set. You may also change the `ENVIRONMENT` to `DEVELOPMENT` to ensure that you have the Django debugging features available.
## Contributing
Refer to the [contribution](./CONTRIBUTING.md) guidelines for more information about how to set the project locally for development and contribution.

_--- Made and maintained by the Corpus team, IEEE NITK ---_
7 changes: 0 additions & 7 deletions backend/corpus/base_url.py

This file was deleted.

10 changes: 0 additions & 10 deletions backend/requirements.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions backend/corpus/settings.py → corpus/corpus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
]

MIDDLEWARE = [
Expand All @@ -52,7 +51,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "corpus.base_url"
ROOT_URLCONF = "corpus.urls"

TEMPLATES = [
{
Expand Down
1 change: 0 additions & 1 deletion backend/corpus/urls.py → corpus/corpus/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

urlpatterns = [
path("admin/", admin.site.urls),
path("api-auth/", include("rest_framework.urls")),
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions corpus/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
asgiref==3.7.2
Django==4.2.4
gunicorn==21.2.0
packaging==23.1
psycopg2==2.9.7
sqlparse==0.4.4
File renamed without changes.
48 changes: 13 additions & 35 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,33 @@ services:
adminer:
image: adminer
restart: always
expose:
- ${ADMINER_PORT}
ports:
- "8080:8080"
env_file:
- .env
networks:
- corpus_network

backend:
build: backend
command: /corpus/start.sh
corpus:
build:
context: corpus
dockerfile: dev-Dockerfile
working_dir: /corpus
command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
restart: always
expose:
- ${DJANGO_BACKEND_PORT}
ports:
- "8000:8000"
networks:
- corpus_network
volumes:
- static_files:/corpus/static
- ./corpus:/corpus
depends_on:
postgres:
condition: service_healthy
env_file:
- .env

frontend:
build: frontend
restart: always
command: node build
networks:
- corpus_network
depends_on:
postgres:
condition: service_healthy
expose:
- "3000"

nginx:
build: nginx
restart: always
depends_on:
- backend
- postgres
networks:
- corpus_network
ports:
- "80:80"
volumes:
- static_files:/etc/nginx/staticfiles
env_file:
- .env
environment:
- ENVIRONMENT=DEVELOPMENT

networks:
corpus_network:
Expand Down
1 change: 0 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Django Environment Variables
DJANGO_BACKEND_PORT="8000"
SECRET_KEY="supersafesecretkey"
ENVIRONMENT="PRODUCTION"

# PostgrSQL Environment Variables
POSTGRES_VERSION="alpine3.18"
Expand Down
3 changes: 0 additions & 3 deletions frontend/.dockerignore

This file was deleted.

13 changes: 0 additions & 13 deletions frontend/.eslintignore

This file was deleted.

23 changes: 0 additions & 23 deletions frontend/.eslintrc.cjs

This file was deleted.

10 changes: 0 additions & 10 deletions frontend/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/.npmrc

This file was deleted.

13 changes: 0 additions & 13 deletions frontend/.prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions frontend/.prettierrc

This file was deleted.

Loading

0 comments on commit 938bd47

Please sign in to comment.