From 8d4b3e9f470c70f1319b40571355727e5385f8e3 Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Fri, 14 Aug 2020 20:05:31 -0300 Subject: [PATCH 1/7] fix gitignore --- .gitignore | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 87ae4a7..6c8624c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,208 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/django,python +# Edit at https://www.toptal.com/developers/gitignore?templates=django,python + +### Django ### +*.log +*.pot *.pyc -*.pyo -*sublime* -python_environment/* -environment/* +__pycache__/ +local_settings.py +db.sqlite3 +db.sqlite3-journal +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# End of https://www.toptal.com/developers/gitignore/api/django,python \ No newline at end of file From bb5b56e963af033a2ea233c1646e0baf8bd28468 Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Fri, 14 Aug 2020 20:05:52 -0300 Subject: [PATCH 2/7] add docker --- Dockerfile | 13 +++++++++++++ docker-compose.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de52c12 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3 +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code + +WORKDIR /code + +COPY requirements.txt /code/ +RUN pip install -r requirements.txt + +COPY . /code/ + +ENTRYPOINT [ "python", "manage.py", "runserver" ] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..62b2d3c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,27 @@ +version: '3' + +services: + db: + image: postgres + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + ports: + - "5432:5432" + web: + build: . + environment: + - DB_NAME=postgres + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + volumes: + - .:/code + ports: + - "8000:8000" + depends_on: + - db + links: + - "db" From 48ad9d0d1d00cdbebdd0c8f1ac5d4d9ea8834af3 Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Sat, 15 Aug 2020 20:53:26 -0300 Subject: [PATCH 3/7] fix serve in dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index de52c12..84a076c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN pip install -r requirements.txt COPY . /code/ -ENTRYPOINT [ "python", "manage.py", "runserver" ] \ No newline at end of file +ENTRYPOINT [ "python", "manage.py", "runserver", "0.0.0.0:8000" ] \ No newline at end of file From 55667efa786054758b8f77f6d13ff2ed6807350c Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Sat, 15 Aug 2020 21:20:41 -0300 Subject: [PATCH 4/7] Add instructions in README about docker and docker-compose --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 533a821..d400038 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Python 3x, pip, Django, Postgresql ## How to start +### Python Local Instalation + 1. Install Python 3.x and Pip. Use virtual environment if your host has older python version and it cant be upgraded. 2. Install PostgreSQL or some other Django-friendly database engine. Also you might want to install PgAdmin or any other administrative tool for your database. 3. Go to your charts storage folder and run `pip install -r requirements.txt`. Unix users : you have to have python-dev package to install `psycopg2`. @@ -15,3 +17,10 @@ Python 3x, pip, Django, Postgresql 5. Run `python manage.py migrate`. This will create database schema without any data. 6. Run `python manage.py runserver` to run *TEST* instance of your database. Use some other stuff (i.e., Gunicorn) for your production environment. +### Using Docker + +1. Install `docker` and `docker-compose`. +2. Run `docker-compose up --build` to run TEST instance of your database. Use some other stuff (i.e., Gunicorn) for your production environment. +3. If it is your first run, in another terminal run `docker-compose run web python manage.py migrate` when all the services are already up and running. This will create database schema without any data. + +If you want to use another database host, change the environment options in `docker-compose` of the `web`service and run `docker-compose up web --build` to startup the development environment. From f48d62e8bd716072afa8912468bbc00ae714cd32 Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Sat, 15 Aug 2020 21:29:09 -0300 Subject: [PATCH 5/7] add new line in the end of the file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 84a076c..aa2c654 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN pip install -r requirements.txt COPY . /code/ -ENTRYPOINT [ "python", "manage.py", "runserver", "0.0.0.0:8000" ] \ No newline at end of file +ENTRYPOINT [ "python", "manage.py", "runserver", "0.0.0.0:8000" ] From db09a4c94ccfa5d3207fb901c935a7c12965d5cd Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Sat, 15 Aug 2020 21:30:08 -0300 Subject: [PATCH 6/7] add new line at end of the file --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c8624c..7cd1826 100755 --- a/.gitignore +++ b/.gitignore @@ -205,4 +205,4 @@ dmypy.json # pytype static type analyzer -# End of https://www.toptal.com/developers/gitignore/api/django,python \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/django,python From 5d38a1ebe6a470f63b03d3d310bbbc2331c08a41 Mon Sep 17 00:00:00 2001 From: Marcos Baesse Date: Sat, 15 Aug 2020 21:38:13 -0300 Subject: [PATCH 7/7] Add more description in README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d400038..601300d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ Python 3x, pip, Django, Postgresql ## How to start +We have a description of two different ways of starting a development server: +- With a Python Local Installation +- With a Docker environment + +Be free to choose that which satisfies your necessities. + ### Python Local Instalation 1. Install Python 3.x and Pip. Use virtual environment if your host has older python version and it cant be upgraded.