Skip to content

Redis callbacks are added and demonstrated using webhook container #15

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
144 changes: 134 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,135 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# VS code extension
.vscode/

# 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/

# 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
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
env
venv
__pycache__

*.pyc
*.sqlite
*.coverage
.DS_Store
env.sh
migrations
.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/

# pre-commit
packagename.egg-info/
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
profile = black
line_length = 88
multi_line_output = 3
include_trailing_comma = True
known_third_party = base,flask,flask_bootstrap,flask_testing,pandas,pydantic,redis,requests,rq
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
- id: check-case-conflict
- id: check-added-large-files
exclude: ^pre-commit
- id: check-merge-conflict
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [
"--max-line-length=89",
"--max-complexity=18",
"--config=setup.cfg",
"--ignore=T001,T003"
]
exclude: __init__.py|manage.py|config.py|env.py
additional_dependencies: [
flake8-print, pep8-naming, flake8-alfred, flake8-bugbear, flake8-todo, pydocstyle, Pygments,
# flake8-builtins,flake8-comprehensions, flake8-pytest-style, flake8-docstrings, flake8-eradicate, flake8-unused-arguments,
]
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.0
3.10.2
58 changes: 52 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
# base image
FROM python:3.8.0-alpine
FROM ubuntu:20.04

# set working directory
# Set location
ENV TZ=Asia/Kolkata \
DEBIAN_FRONTEND=noninteractive

# Update and install python, pip
RUN apt-get update -y
RUN apt-get install tzdata
RUN apt-get install -y python3-pip python3-dev build-essential curl
RUN apt-get update -y
RUN apt upgrade -y
RUN apt-get install -y wkhtmltopdf

RUN apt-get update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/*
RUN add-apt-repository -y ppa:alex-p/tesseract-ocr
RUN apt-get update
RUN apt-get -y install tesseract-ocr
# pytesseract using pip forgot to install binaries.
# Ref: https://stackoverflow.com/questions/50655738/how-do-i-resolve-a-tesseractnotfounderror
# Ref: https://docs.ropensci.org/tesseract/
RUN apt-get install -y libtesseract-dev libleptonica-dev tesseract-ocr-eng
RUN cd /usr/share/tesseract-ocr/4.00/tessdata/
RUN apt install wget
RUN wget https://github.com/tesseract-ocr/tessdata/blob/main/eng.traineddata
RUN cd /usr/share/tesseract-ocr/4.00/tessdata/
RUN wget https://github.com/tesseract-ocr/tessdata/blob/main/osd.traineddata

CMD /bin/bash

# LABEL about the custom image
LABEL maintainer="[email protected]"
LABEL version="0.1"
LABEL description="This is custom Docker Image."

# Set working directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# add requirements (to leverage Docker cache)
# Install some requirements (not a part of this project)
RUN pip3 install pip --upgrade
RUN pip3 install pillow==8.3.2
RUN pip3 install pytesseract==0.3.8
RUN pip3 install spacy==3.2.4
RUN python3 -m spacy download en_core_web_sm

# Add requirements (to leverage Docker cache)
ADD ./requirements.txt /usr/src/app/requirements.txt

# install requirements
RUN pip install -r requirements.txt
# Install depedencies
RUN pip3 install -r requirements.txt

# copy project

# Copy project
COPY . /usr/src/app

EXPOSE 5000
CMD ["python3", "-u", "manage.py", "run", "-h", "0.0.0.0"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Michael Herman
Copyright (c) 2022 Michael Herman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Flask Redis Queue
# Demo flask redis dockerized templates

Example of how to handle background processes with Flask, Redis Queue, and Docker

Expand All @@ -7,7 +7,77 @@ Example of how to handle background processes with Flask, Redis Queue, and Docke
Spin up the containers:

```sh
$ docker-compose up -d --build
$ docker-compose up --build -V --scale worker=4
```

Spin up the containers in background:

```sh
$ docker-compose up -d --build -V --scale worker=4
```


Stop all containers and workers:

```sh
$ docker-compose down -v
```

Open your browser to http://localhost:5004

Open redis dashboard in http://localhost:9181/

Show logs from worker containers:
```sh
docker-compose logs --tail=0 -f master
docker-compose logs --tail=0 -f worker
```

You can view a list of all the allocated volumes in your system with
```sh
docker volume ls
```

If you prefer a more automatic cleanup, the following command will remove any unused images or volumes, and any stopped containers that are still in the system.
```sh
docker system prune --volumes
```

## Some important docker commands:
Below command will remove the following:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
```sh
docker system prune
```
Below command will remove the following:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache
```sh
docker system prune --all --force
```
Below command will remove all docker images:
```sh
docker rmi --force $(docker images --all --quiet)
```

# Contribution

## Pre-commit
Following command will help to remove trailing-whitespace, check case conflict, check added large files,
check merge conflict by using isort, black and flake8 automation tools.
```sh
python3 pre-commit-2.15.0.pyz run -a
```

## Delete __pycache__ files
```sh
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
```

## Upgrade
This architecture has been upgraded in [this](https://github.com/vhiwase/react_native-python_flask-sql-nignx-with-authentication-boilerplate) repo.
Loading