Skip to content
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

dev -> prod #321

Merged
merged 12 commits into from
Jun 14, 2024
6 changes: 4 additions & 2 deletions .github/workflows/publish_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ jobs:
ROOT_DIR: /home/${{ secrets.MASTER_DO_USER }}/testing
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
UPTRACE_DSN: ${{ secrets.UPTRACE_DSN }}
with:
host: ${{ secrets.MASTER_HOST }}
username: ${{ secrets.MASTER_DO_USER }}
passphrase: ${{ secrets.MASTER_DO_SSH_KEY_PASSWORD }}
key: ${{ secrets.MASTER_DO_SSH_KEY }}
port: ${{ secrets.MASTER_PORT }}
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TEST_TOKEN, TELEGRAM_ERROR_CHAT_ID
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TEST_TOKEN, TELEGRAM_ERROR_CHAT_ID, UPTRACE_DSN
script: |
export CONTAINER_ID=$(docker ps -aq --filter name=testing)
export IMAGE_ID=$(docker images -aq --filter reference='docker.pkg.github.com/sysblok/sysblokbot/sysblokbot:testing')
Expand All @@ -135,8 +136,9 @@ jobs:
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
docker run -dit --name sysblokbot-testing \
--env APP_SOURCE="github CI" --restart unless-stopped \
--env APP_SOURCE="testing" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
--env UPTRACE_DSN="${{ env.UPTRACE_DSN }}" \
--env TELEGRAM_TOKEN="${{ env.TELEGRAM_TEST_TOKEN }}" \
-v ${{ env.ROOT_DIR }}/config_override.json:/app/config_override.json \
-v ${{ env.ROOT_DIR }}/config_gs.json:/app/config_gs.json \
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/publish_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ jobs:
ROOT_DIR: /home/${{ secrets.MASTER_DO_USER }}/prod
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_PROD_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
UPTRACE_DSN: ${{ secrets.UPTRACE_DSN }}
with:
host: ${{ secrets.MASTER_HOST }}
username: ${{ secrets.MASTER_DO_USER }}
passphrase: ${{ secrets.MASTER_DO_SSH_KEY_PASSWORD }}
key: ${{ secrets.MASTER_DO_SSH_KEY }}
port: ${{ secrets.MASTER_PORT }}
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TOKEN, TELEGRAM_ERROR_CHAT_ID
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TOKEN, TELEGRAM_ERROR_CHAT_ID, UPTRACE_DSN
script: |
export CONTAINER_ID=$(docker ps -aq --filter name=prod)
export IMAGE_ID=$(docker images -aq --filter reference='docker.pkg.github.com/sysblok/sysblokbot/sysblokbot:prod')
Expand All @@ -138,9 +139,10 @@ jobs:
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
docker run -dit --name sysblokbot-prod \
--env APP_SOURCE="github CI" --restart unless-stopped \
--env APP_SOURCE="prod" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
--env TELEGRAM_TOKEN="${{ env.TELEGRAM_TOKEN }}" \
--env UPTRACE_DSN="${{ env.UPTRACE_DSN }}" \
-v ${{ env.ROOT_DIR }}/config_override.json:/app/config_override.json \
-v ${{ env.ROOT_DIR }}/config_gs.json:/app/config_gs.json \
-v ${{ env.ROOT_DIR }}/sysblokbot.sqlite:/app/sysblokbot.sqlite \
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = apiclient,bs4,conftest,dateutil,deepdiff,facebook,fakes,freezegun,googleapiclient,matplotlib,numpy,oauth2client,pytest,pytest_report,requests,schedule,sentry_sdk,setuptools,sheetfu,sqlalchemy,telegram,telethon,utils,vk_api
known_third_party = apiclient,bs4,conftest,dateutil,deepdiff,facebook,fakes,freezegun,googleapiclient,matplotlib,numpy,oauth2client,pytest,pytest_report,requests,schedule,setuptools,sheetfu,sqlalchemy,telegram,telethon,utils,vk_api
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ COPY . /app

ARG COMMIT_HASH
ARG COMMIT_HASH_SHORT
ARG UPTRACE_DSN
ENV COMMIT_HASH=$COMMIT_HASH
ENV COMMIT_HASH_SHORT=$COMMIT_HASH_SHORT
ENV UPTRACE_DSN=$UPTRACE_DSN


ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
Expand Down
9 changes: 3 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import logging

import requests
import sentry_sdk

from src import consts
from src.bot import SysBlokBot
from src.config_manager import ConfigManager
from src.scheduler import JobScheduler
from src.tg.sender import TelegramSender
from src.utils.log_handler import ErrorBroadcastHandler
from src.utils.uptrace_logger import add_uptrace_logging

locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
logging.basicConfig(format=consts.LOG_FORMAT, level=logging.INFO)
Expand All @@ -34,10 +34,6 @@ def get_bot():
if not config:
raise ValueError("Could not load config, can't go on")

sentry_dsn = config.get("sentry_dsn", None)
if sentry_dsn:
sentry_sdk.init(dsn=sentry_dsn, traces_sample_rate=1.0)

scheduler = JobScheduler()

jobs_config_file_key = ConfigManager().get_jobs_config_file_key()
Expand Down Expand Up @@ -66,6 +62,8 @@ def get_bot():
for handler in logging.getLogger().handlers:
logging.getLogger().removeHandler(handler)
logging.getLogger().addHandler(ErrorBroadcastHandler(tg_sender))
if consts.UPTRACE_DSN:
add_uptrace_logging(consts.UPTRACE_DSN)

# Scheduler must be run after clients initialized
scheduler.run()
Expand All @@ -82,7 +80,6 @@ def get_bot():


def report_critical_error(e: BaseException):
sentry_sdk.capture_exception(e)
requests.post(
url=f"https://api.telegram.org/bot{consts.TELEGRAM_TOKEN}/sendMessage",
json={
Expand Down
17 changes: 13 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cryptography==3.1.1
cycler==0.11.0
decorator==4.4.2
deepdiff==4.3.2
Deprecated==1.2.14
distlib==0.3.6
distro==1.4.0
-e git+https://github.com/mobolic/facebook-sdk.git@ffd9980700be48964d6a6a61144edb1c3ea29cff#egg=facebook_sdk
Expand All @@ -29,13 +30,14 @@ google-api-python-client==1.9.1
google-auth==1.16.0
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.1
googleapis-common-protos==1.51.0
googleapis-common-protos==1.63.0
grpcio==1.63.0
gspread==3.4.2
html5lib==1.0.1
httplib2==0.18.1
identify==2.5.11
idna==2.9
importlib-metadata==1.6.0
importlib-metadata==7.0.0
ipaddr==2.2.0
isort==4.3.21
kiwisolver==1.4.4
Expand All @@ -50,6 +52,14 @@ nodeenv==1.7.0
numpy==1.24.1
oauth2client==4.1.3
oauthlib==3.1.0
opentelemetry-api==1.24.0
opentelemetry-exporter-otlp==1.24.0
opentelemetry-exporter-otlp-proto-common==1.24.0
opentelemetry-exporter-otlp-proto-grpc==1.24.0
opentelemetry-exporter-otlp-proto-http==1.24.0
opentelemetry-proto==1.24.0
opentelemetry-sdk==1.24.0
opentelemetry-semantic-conventions==0.45b0
ordered-set==3.1.1
packaging==20.3
pathspec==0.10.3
Expand All @@ -59,7 +69,7 @@ platformdirs==2.6.2
pluggy==0.13.1
pre-commit==2.21.0
progress==1.5
protobuf==3.12.2
protobuf==4.25.3
py==1.8.1
pyaes==1.6.1
pyasn1==0.4.8
Expand All @@ -81,7 +91,6 @@ retrying==1.3.3
rope==0.17.0
rsa==4.0
-e git+https://github.com/dbader/schedule.git@3eac646a8d2658929587d7454bd2c85696df254e#egg=schedule
sentry-sdk==1.10.1
sheetfu==1.5.3
six==1.14.0
soupsieve==2.3.2.post1
Expand Down
8 changes: 7 additions & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .tg import handlers, sender
from .tg.handlers.utils import admin_only, direct_message_only, manager_only

logging.addLevelName(USAGE_LOG_LEVEL, "USAGE")
logging.addLevelName(USAGE_LOG_LEVEL, "NOTICE")


def usage(self, message, *args, **kws):
Expand Down Expand Up @@ -88,6 +88,12 @@ def init_handlers(self):
self.manager_reply_handler("trello_board_state_job"),
"получить сводку о состоянии доски",
)
self.add_manager_handler(
"get_board_state",
CommandCategories.SUMMARY,
self.manager_reply_handler("board_state_job"),
"получить сводку о состоянии доски (focalboard)",
)
self.add_manager_handler(
"get_editorial_board_stats",
CommandCategories.STATS,
Expand Down
18 changes: 17 additions & 1 deletion src/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
f'https://github.com/sysblok/sysblokbot/commit/{os.environ.get("COMMIT_HASH")}'
)
COMMIT_HASH = os.environ.get("COMMIT_HASH_SHORT")
UPTRACE_DSN = os.environ.get("UPTRACE_DSN")


class AppSource(Enum):
DEFAULT = "manual"
GITHUB = "github CI"
GITHUB = "prod"
GITHUB_DEV = "testing"


APP_SOURCE = os.environ.get("APP_SOURCE", AppSource.DEFAULT.value)
Expand Down Expand Up @@ -86,6 +88,19 @@ class TrelloCardColor(Enum):
UNKNOWN = "unknown"


class BoardCardColor(Enum):
BLACK = "propColorGray"
BROWN = "propColorBrown"
ORANGE = "propColorOrange"
YELLOW = "propColorYellow"
GREEN = "propColorGreen"
BLUE = "propColorBlue"
PURPLE = "propColorPurple"
PINK = "propColorPink"
RED = "propColorRed"
UNKNOWN = "unknown"


class TrelloListAlias(Enum):
TOPIC_SUGGESTION = "trello_list_name__topic_suggestion"
TOPIC_READY = "trello_list_name__topic_ready"
Expand All @@ -97,6 +112,7 @@ class TrelloListAlias(Enum):
TO_CHIEF_EDITOR = "trello_list_name__to_chief_editor"
PROOFREADING = "trello_list_name__proofreading"
DONE = "trello_list_name__typesetting"
PUBLISHED = "trello_list_name__published"
BACK_BURNER = "trello_list_name__back_burner"


Expand Down
4 changes: 4 additions & 0 deletions src/db/db_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TeamMember(Base):
manager = Column(String)
telegram = Column(String)
trello = Column(String)
focalboard = Column(String)
roles = Column(String)

def __repr__(self):
Expand All @@ -125,6 +126,7 @@ def from_dict(cls, data):
member.manager = _get_str_data_item(data, "manager")
member.telegram = _get_str_data_item(data, "telegram")
member.trello = _get_str_data_item(data, "trello")
member.focalboard = _get_str_data_item(data, "focalboard")
return member

def to_dict(self):
Expand All @@ -136,6 +138,7 @@ def to_dict(self):
"manager": self.manager,
"telegram": self.telegram,
"trello": self.trello,
"focalboard": self.focalboard,
"roles": self.roles,
}

Expand All @@ -149,6 +152,7 @@ def from_sheetfu_item(cls, item):
member.manager = item.get_field_value(load("sheets__team__manager"))
member.telegram = item.get_field_value(load("sheets__team__telegram"))
member.trello = item.get_field_value(load("sheets__team__trello"))
member.focalboard = item.get_field_value(load("sheets__focalboard"))
return member


Expand Down
Loading
Loading