Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
feat/docker compose (#6)
Browse files Browse the repository at this point in the history
* fix: change app behavior for docker host

* feat: create dockerignore

* fix: update requirements

* feat: create postgres dockerfile

* feat: create app dockerfile

* feat: create docker-compose

* fix: add restart always policy

* chore: apply black linter

* fix: remove port exposion

* fix: remove isort checking

* chore: update .dockerignore

Co-authored-by: Krisque <[email protected]>

* fix: update .dockerignore

Co-authored-by: Krisque <[email protected]>

* fix: remove isort from requirements.txt

Co-authored-by: Krisque <[email protected]>

Co-authored-by: Krisque <[email protected]>
  • Loading branch information
vcwild and chrisemke authored Oct 11, 2021
1 parent 83f6ed8 commit ac57a95
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 23 deletions.
153 changes: 153 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Byte-compiled / optimized / DLL files
# Python
**/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
false/
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
.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/

# Pycharm
.idea

# Ignore folders from dev environment
init_scripts/
img/

# Ignire files from dev environment
streamers.csv

*_bak.py
.vscode

.github

# Git
.git
.gitgnore

# Docker
.docker
15 changes: 0 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,3 @@ jobs:
pip install black
- name: Execute the black linter
run: black -l 79 -S src --check

execute_isort_sorter_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install isort
- name: Execute the isort Sorter
run: isort --check src
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:20.04

LABEL app="livedivulgador"

ADD . ./app

RUN apt-get update -y

RUN apt-get install -y libpq-dev python3-pip

RUN pip install -r ./app/requirements.txt

CMD [ "python3", "./app/src/bot/main.py" ]
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.1'

services:
livedivulgador:
restart: always
build:
context: .
dockerfile: Dockerfile
depends_on:
- db
env_file:
- .env

db:
restart: always
env_file:
- .env
environment:
POSTGRES_USER: ${user_db}
POSTGRES_PASSWORD: ${passwd_db}
POSTGRES_DB: streamers
build:
context: ./docker/
dockerfile: postgres.dockerfile
3 changes: 3 additions & 0 deletions docker/postgres.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres

ADD ./dump.sql /docker-entrypoint-initdb.d
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Flask
tweepy
tweepy==3.10
requests
SQLAlchemy
SQLAlchemy-Utils
Expand All @@ -8,4 +8,3 @@ schedule
Pillow
python-dotenv
black
isort
2 changes: 1 addition & 1 deletion src/bot/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
raise ValueError('passwd_db não encontrado')

if host_db is None or host_db == '':
host_db = "localhost"
host_db = "db"

if port_db is None or port_db == '':
port_db = "5432"
Expand Down
12 changes: 8 additions & 4 deletions src/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

from db import insert_on_stream, return_streamer_info
from tt import tweet
from twitch import (get_OAuth, get_stream_title, get_streamer_name,
is_streamer_live)
from twitch import (
get_OAuth,
get_stream_title,
get_streamer_name,
is_streamer_live,
)
from utils import remove_cmds_from_title

# Lista das categorias permitidas
Expand Down Expand Up @@ -99,10 +103,10 @@ def threaded_job(job):

if __name__ == "__main__":

schedule.every(15).seconds.do(threaded_job, main)
schedule.every(60).seconds.do(threaded_job, main)

while True:
schedule.run_pending()

# Performance measure
time.sleep(10)
time.sleep(30)
2 changes: 1 addition & 1 deletion src/bot/tt.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def tweet(

tweet = f"""{EMOJIS["arrow"]} {twitter} está em Live neste momento!{EMOJIS["red_dot"]}
{title.replace("#", " - ")}
Entra aí: https://www.{twitch}
Expand Down

0 comments on commit ac57a95

Please sign in to comment.