-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docker-build.yml with telegram_bot_service
- Loading branch information
1 parent
e60119b
commit 9650617
Showing
36 changed files
with
830 additions
and
55 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,3 @@ | ||
TELEGRAM_BOT_TOKEN=your_telegram_bot_token | ||
OPENAI_API_KEY=your_openai_api_key | ||
DATABASE_URL=postgresql://user:password@host:5432/dbname |
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,56 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install pytest pytest-cov | ||
- name: Run tests | ||
run: | | ||
pytest --cov=./ --cov-report=xml | ||
- name: Upload coverage | ||
uses: codecov/codecov-action@v2 | ||
|
||
build: | ||
needs: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build and push Docker images | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: | | ||
gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot:${{ github.sha }} | ||
gcr.io/${{ secrets.GCP_PROJECT_ID }}/translation-service:${{ github.sha }} | ||
gcr.io/${{ secrets.GCP_PROJECT_ID }}/transport-service:${{ github.sha }} | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: google-github-actions/setup-gcloud@v0 | ||
with: | ||
service_account_key: ${{ secrets.GCP_SA_KEY }} | ||
project_id: ${{ secrets.GCP_PROJECT_ID }} | ||
- name: Deploy to GKE | ||
run: | | ||
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} --zone ${{ secrets.GKE_ZONE }} | ||
kubectl apply -f k8s/ |
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,43 @@ | ||
name: Docker Build and Push | ||
|
||
# Когда срабатывает workflow | ||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'telegram_bot_service/**' | ||
- '.github/workflows/docker-build.yml' | ||
|
||
# Возможность запуска workflow вручную | ||
workflow_dispatch: | ||
|
||
# Описание jobs (задач) | ||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Шаг 1: Checkout кода | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# Шаг 2: Настройка Docker Buildx | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
# Шаг 3: Логин в Docker Hub | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# Шаг 4: Сборка и пуш образа | ||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./telegram_bot_service | ||
push: true | ||
tags: | | ||
${{ secrets.DOCKERHUB_USERNAME }}/telegram_bot_service:latest | ||
${{ secrets.DOCKERHUB_USERNAME }}/telegram_bot_service:${{ github.sha }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,37 @@ | ||
[alembic] | ||
script_location = migrations | ||
sqlalchemy.url = driver://user:pass@localhost/dbname | ||
|
||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
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,11 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
import os | ||
|
||
DATABASE_URL = os.getenv( | ||
'DATABASE_URL', | ||
'postgresql://user:password@localhost:5432/smarttranslate' | ||
) | ||
|
||
engine = create_engine(DATABASE_URL) | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) |
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,31 @@ | ||
from logging.config import fileConfig | ||
from sqlalchemy import engine_from_config | ||
from sqlalchemy import pool | ||
from alembic import context | ||
from database.models import Base | ||
from database.config import DATABASE_URL | ||
|
||
config = context.config | ||
fileConfig(config.config_file_name) | ||
target_metadata = Base.metadata | ||
|
||
def run_migrations_online(): | ||
configuration = { | ||
'sqlalchemy.url': DATABASE_URL | ||
} | ||
connectable = engine_from_config( | ||
configuration, | ||
prefix='sqlalchemy.', | ||
poolclass=pool.NullPool, | ||
) | ||
|
||
with connectable.connect() as connection: | ||
context.configure( | ||
connection=connection, | ||
target_metadata=target_metadata | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
run_migrations_online() |
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,36 @@ | ||
from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.sql import func | ||
|
||
Base = declarative_base() | ||
|
||
class User(Base): | ||
__tablename__ = 'users' | ||
|
||
id = Column(Integer, primary_key=True) | ||
telegram_id = Column(Integer, unique=True) | ||
username = Column(String) | ||
created_at = Column(DateTime, server_default=func.now()) | ||
settings = Column(JSON) | ||
|
||
class Translation(Base): | ||
__tablename__ = 'translations' | ||
|
||
id = Column(Integer, primary_key=True) | ||
user_id = Column(Integer, ForeignKey('users.id')) | ||
source_text = Column(String) | ||
translated_text = Column(String) | ||
source_language = Column(String) | ||
target_language = Column(String) | ||
created_at = Column(DateTime, server_default=func.now()) | ||
model_used = Column(String) | ||
|
||
class LogEntry(Base): | ||
__tablename__ = 'logs' | ||
|
||
id = Column(Integer, primary_key=True) | ||
timestamp = Column(DateTime, server_default=func.now()) | ||
service = Column(String) | ||
level = Column(String) | ||
message = Column(String) | ||
metadata = Column(JSON) |
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 |
---|---|---|
@@ -1,34 +1,45 @@ | ||
version: '3' | ||
version: '3.8' | ||
|
||
services: | ||
transport_service: | ||
build: ./transport_service | ||
ports: | ||
- "8001:8000" | ||
telegram_bot_service: | ||
build: ./telegram_bot_service | ||
environment: | ||
- LOG_LEVEL=INFO | ||
networks: | ||
- app_network | ||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN} | ||
- TRANSPORT_SERVICE_URL=http://transport_service:8080 | ||
depends_on: | ||
- transport_service | ||
restart: always | ||
|
||
translation_service: | ||
build: ./translation_service | ||
environment: | ||
- OPENAI_API_KEY=${OPENAI_API_KEY} | ||
networks: | ||
- app_network | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- transport_service | ||
restart: always | ||
|
||
telegram_bot_service: | ||
build: ./telegram_bot_service | ||
transport_service: | ||
build: ./transport_service | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN} | ||
- TRANSPORT_SERVICE_URL=http://transport_service:8000 | ||
networks: | ||
- app_network | ||
- DATABASE_URL=${DATABASE_URL} | ||
restart: always | ||
|
||
prometheus: | ||
image: prom/prometheus | ||
ports: | ||
- "9090:9090" | ||
volumes: | ||
- ./monitoring/prometheus:/etc/prometheus | ||
depends_on: | ||
- transport_service | ||
|
||
networks: | ||
app_network: | ||
driver: bridge | ||
grafana: | ||
image: grafana/grafana | ||
ports: | ||
- "3000:3000" | ||
depends_on: | ||
- prometheus |
Oops, something went wrong.