-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5ccec2
Showing
41 changed files
with
3,110 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
# Docker Environment Variables | ||
PYTHON_VERSION=3.9 | ||
SERVICE_PORT=8000 | ||
WORKERS_COUNT=1 | ||
REDIS_VERSION=latest | ||
POSTGRES_VERSION=latest | ||
MINIO_VERSION=latest | ||
MINIO_SERVER_PORT=9001 | ||
|
||
# Project Environment Variables | ||
POSTGRES_USER=postgres | ||
POSTGRES_PASSWORD=postgres | ||
POSTGRES_DB=step | ||
POSTGRES_PORT=5432 | ||
POSTGRES_SERVER=127.0.0.1 | ||
REDIS_HOST=127.0.0.1 | ||
REDIS_PORT=6379 | ||
REDIS_DB=0 | ||
S3_HOST="http://127.0.0.1" | ||
S3_PORT=9000 | ||
S3_ACCESS_KEY_ID=root | ||
S3_ACCESS_KEY=rootpassword | ||
S3_BUCKET=test | ||
RQ_QUEUE=default | ||
LOG_LEVEL=DEBUG | ||
LOG_PATH=/var/log/webapp |
This file contains 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,8 @@ | ||
name: Ruff | ||
on: [push, pull_request] | ||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: chartboost/ruff-action@v1 |
This file contains 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,163 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
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/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .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 | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__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/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ | ||
data | ||
.ruff_cache | ||
logs |
This file contains 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,22 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.4.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.1.4 | ||
hooks: | ||
- id: ruff | ||
args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format | ||
|
||
- repo: https://github.com/python-poetry/poetry | ||
rev: '1.7.0' | ||
hooks: | ||
- id: poetry-check |
This file contains 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Sunyata OU | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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,24 @@ | ||
sync-new-env: | ||
@while IFS='=' read -r key value; do \ | ||
if [ -n "$$key" ]; then \ | ||
if ! grep -q "^$$key=" .env; then \ | ||
echo "$$key=$$value" >> .env; \ | ||
fi; \ | ||
fi; \ | ||
done < .env-copy | ||
|
||
alembic-autogenerate: | ||
@read -p "Enter migration message: " message; \ | ||
alembic revision --autogenerate -m "$$message" | ||
|
||
alembic-upgrade: | ||
alembic upgrade head | ||
|
||
init: | ||
@make sync-new-env | ||
@poetry install | ||
@docker-compose build | ||
@docker-compose up -d | ||
@sleep 5 | ||
@make alembic-upgrade | ||
@docker-compose exec minio sh -c "mc mb minio/$$(grep S3_BUCKET .env | cut -d '=' -f2)" |
This file contains 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,100 @@ | ||
# Web-Service-Python | ||
|
||
## Description | ||
This a simple python web service that uses the Fastapi framework to create a RESTful API as well as a webserver. This is meant to be used as a template for future projects.The project includes a fully dockerised environment with a docker-compose file to run the project. The project also includes postgresql database and a redis database. There is RQ worker support for asyncronous tasks. The included Minio server is used for file storage. The frontend is through the Jinja2 templating engine. It also includes Nginx and certbot for SSL support. | ||
|
||
## Installation | ||
|
||
### Docker | ||
1. Install Docker and Docker-compose | ||
2.Copy the .env-copy file to .env and fill in the variables | ||
2. Build the docker compose file | ||
```bash | ||
docker-compose build | ||
``` | ||
3. Run the docker compose file | ||
```bash | ||
docker-compose up | ||
``` | ||
4. The webserver should be running on localhost on the port defined in the .env file | ||
5. Create a bucket in the minio server with the name defined in the .env file | ||
6. The project uses alemic to manage the database. To create the database run the following command | ||
```bash | ||
alemic upgrade head | ||
``` | ||
|
||
## Development | ||
The project uses poetry to manage the python dependencies. | ||
|
||
### Prerequisites | ||
|
||
- `Poetry` (version equal to `1.7.0`) [Installation Guide](https://python-poetry.org/docs/#installation) | ||
- `Python 3.10` | ||
- `Docker` (Optional) | ||
- `docker-compose` (Optional) | ||
|
||
### Install dependencies | ||
|
||
- `poetry install` | ||
- This will download all dependencies and install `prometheus` tool. | ||
- To check if installation was successful, try `prometheus version`. You should see output as `0.1.0` | ||
|
||
### Add new packages | ||
|
||
- `poetry add package-name=version-number` | ||
- Dev dependencies can be added using `--group dev` flag. | ||
|
||
### Remove package | ||
|
||
- `poetry remove package-name` | ||
|
||
### Locking dependencies | ||
|
||
- `poetry lock` | ||
- This will update `poetry.lock` file with latest versions of all dependencies. | ||
- This should be done before committing changes to `pyproject.toml` file. | ||
|
||
### Update dependencies | ||
|
||
- `poetry update` | ||
- This will update all dependencies to latest version. | ||
- This will also update `poetry.lock` file. | ||
- `poetry update package-name` | ||
- This will update `package-name` to latest version. | ||
- This will also update `poetry.lock` file. | ||
- `poetry add <package-name@latest> --group dev` | ||
- This will update `package-name` for `dev` group as there is no straight forward way yot update dev dependencies to latest version. | ||
- Remember to pin dependency in this case. | ||
- This will also update `poetry.lock` file. | ||
|
||
### Setting up pre-commit | ||
|
||
This is used for running lint rules before committing changes to the repo. `pre-commit` command should be installed as | ||
part of installing dependencies. To check if it is working properly, run `pre-commit --version`, you should see `3.5.0` | ||
or newer version. | ||
|
||
- To install git commit hooks, run `pre-commit install`. And you're done. | ||
- For more information, refer [here](https://pre-commit.com/) | ||
|
||
### Using alembic | ||
To create a new migration run the following command | ||
```bash | ||
alembic revision --autogenerate -m "migration message" | ||
``` | ||
To apply the migration run the following command | ||
```bash | ||
alembic upgrade head | ||
``` | ||
To downgrade the migration run the following command | ||
```bash | ||
alembic downgrade -1 | ||
``` | ||
|
||
### Setting up nginx and certbot | ||
|
||
1. Modify configuration in `nginx/app.conf`, `init_cert.sh` with the appropriate config/credentials. | ||
|
||
2. Run the init script(Ensure that you have made the appropriate dns mapping for the server at your domain provider): | ||
```bash | ||
./init_cert.sh | ||
``` |
Oops, something went wrong.