Skip to content

Commit 5ba2fc0

Browse files
committed
initial
0 parents  commit 5ba2fc0

19 files changed

+877
-0
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
POSTGRES_DB=postgres_db_name
2+
POSTGRES_USER=postgres_db_user
3+
POSTGRES_PASSWORD=postgres_db_password
4+
POSTGRES_PORT=postgres_db_port
5+
6+
ALLOWED_HOSTS='127.0.0.1,localhost'
7+
CORS_ORIGIN_WHITELIST='http://127.0.0.1:3000,http://localhost:3000'
8+
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
9+
10+
SECRET_KEY='secret_key'
11+
DEBUG='True'

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
max-line-length = 158
3+
max-complexity = 10
4+
exclude =
5+
.git,
6+
__pycache__,
7+
.env,
8+
venv,
9+
*/migrations

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.env
2+
/.vscode/
3+
/src/media/
4+
/src/static/
5+
*.mo
6+
*.pyc
7+
htmlcov/
8+
.coverage
9+
.coverage.*
10+
coverage.xml
11+
*.cover

.isort.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
multi_line_output=3
3+
force_grid_wrap = 3
4+
include_trailing_comma=True
5+
line_length=158

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
always_run: false
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- id: flake8
10+
exclude: (migrations)

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.10.8-alpine
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
RUN addgroup -S python && adduser -S python -G python
6+
RUN pip install -U pipenv
7+
USER python
8+
WORKDIR /home/python
9+
COPY --chown=python:python Pipfile Pipfile.lock ./
10+
RUN pipenv install --system --deploy
11+
COPY --chown=python:python /src .
12+
COPY --chown=python:python /gunicorn/gunicorn.py .
13+
ENV PATH="/home/python/.local/bin:${PATH}"
14+
EXPOSE 8000
15+
CMD ["gunicorn", "signal_documentation.wsgi:application", "-c", "gunicorn.py"]

Pipfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
django = "*"
8+
django-filter = "*"
9+
psycopg2-binary = "*"
10+
django-extensions = "*"
11+
pillow = "*"
12+
pre-commit = "*"
13+
sentry-sdk = "*"
14+
python-dotenv = "*"
15+
django-health-check = "*"
16+
django-cors-headers = "*"
17+
django-debug-toolbar = "*"
18+
gunicorn = "*"
19+
20+
[dev-packages]
21+
flake8 = "*"
22+
isort = "*"
23+
pep8 = "*"
24+
25+
[requires]
26+
python_version = "3.10"

Pipfile.lock

Lines changed: 431 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Signal Documentation
2+
Single Source of Documentation System
3+
4+
## Core libs and DB
5+
1. [Django](https://www.djangoproject.com/)
6+
2. [Django-filter](https://django-filter.readthedocs.io/en/stable/index.html)
7+
3. [PostgreSQL](https://www.postgresql.org/)
8+
9+
10+
All requirements you can find in `Pipfile`
11+
12+
## Getting started
13+
14+
### Setup Env Vars
15+
16+
create `.env` file and add variables like in `.env.example`
17+
18+
### To run locally
19+
20+
Install `python:3.10`, `pip3`, `pipenv`
21+
22+
Using [pipenv](https://github.com/pypa/pipenv) run `pipenv shell` and `pipenv install` to create virtual environment and install dependencies
23+
24+
```sh
25+
$ pipenv shell
26+
$ pipenv install
27+
```
28+
29+
Go to `src` directory and run
30+
31+
```sh
32+
$ python manage.py migrate
33+
$ python manage.py test
34+
$ python manage.py runserver
35+
```
36+
37+
### To run via docker
38+
39+
Install `Docker` and `docker-compose`
40+
41+
Run
42+
```sh
43+
$ docker-compose build
44+
$ docker-compose up
45+
46+
```
47+
48+
Open `http://localhost:8000` to view it in the browser
49+
50+
## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
51+
`http://localhost:8000/admin`

docker-compose.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3.8'
2+
3+
services:
4+
5+
db:
6+
image: postgres:latest
7+
container_name: signal_documentation-db
8+
restart: always
9+
env_file:
10+
- ./.env
11+
environment:
12+
POSTGRES_DB: ${POSTGRES_DB}
13+
POSTGRES_USER: ${POSTGRES_USER}
14+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
15+
POSTGRES_HOST: ${POSTGRES_HOST}
16+
volumes:
17+
- postgres:/var/lib/postgresql/data
18+
ports:
19+
- "5432:5432"
20+
21+
webapp:
22+
build: .
23+
env_file:
24+
- ./.env
25+
container_name: signal_documentation-web
26+
command: sh -c "python /usr/src/signal_documentation/src/manage.py migrate --noinput &&
27+
python /usr/src/signal_documentation/src/manage.py collectstatic --noinput &&
28+
python /usr/src/signal_documentation/src/manage.py runserver 0.0.0.0:8000"
29+
volumes:
30+
- .:/usr/src/signal_documentation
31+
ports:
32+
- "8000:8000"
33+
depends_on:
34+
- db
35+
36+
volumes:
37+
postgres:
38+
webapp:

gunicorn/gunicorn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import multiprocessing
2+
3+
bind = "0.0.0.0:8000"
4+
workers = multiprocessing.cpu_count() * 2 + 1

nginx/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:1.23
2+
3+
COPY default.conf.template /etc/nginx/templates/default.conf.template

nginx/default.conf.template

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
location / {
6+
proxy_set_header Host $http_host;
7+
proxy_set_header X-Real-IP $remote_addr;
8+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9+
proxy_set_header X-Forwarded-Proto $scheme;
10+
proxy_pass http://${APP_HOST}:8000;
11+
}
12+
13+
location /usr/src/signal_documentation {
14+
alias /static/;
15+
}
16+
}

src/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'signal_documentation.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

src/signal_documentation/__init__.py

Whitespace-only changes.

src/signal_documentation/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for signal_documentation project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'signal_documentation.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)