mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
add ci tests in docker compose (#11)
This commit is contained in:
parent
e8ace80d68
commit
4e97baf525
9
.github/workflows/poetry-test.yml
vendored
9
.github/workflows/poetry-test.yml
vendored
@ -37,7 +37,6 @@ jobs:
|
|||||||
curl -sSL "https://install.python-poetry.org" | python -
|
curl -sSL "https://install.python-poetry.org" | python -
|
||||||
# Adding `poetry` to `$PATH`:
|
# Adding `poetry` to `$PATH`:
|
||||||
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
apt-get update && apt-get install --no-install-recommends -y ffmpeg
|
|
||||||
|
|
||||||
- name: Set up cache
|
- name: Set up cache
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -64,14 +63,10 @@ jobs:
|
|||||||
#----------------------------------------------
|
#----------------------------------------------
|
||||||
# run test suite
|
# run test suite
|
||||||
#----------------------------------------------
|
#----------------------------------------------
|
||||||
- name: Run tests
|
|
||||||
run: |
|
|
||||||
source .venv/bin/activate
|
|
||||||
poetry run pytest bot_microservice/ -vv --exitfirst
|
|
||||||
- name: Coverage report
|
- name: Coverage report
|
||||||
run: |
|
run: |
|
||||||
poetry run coverage run -m pytest bot_microservice/
|
cp bot_microservice/serrings/.env.ci.runtests bot_microservice/serrings/.env
|
||||||
poetry run coverage report
|
docker compose run bot poetry run bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report"
|
||||||
- name: Extended checks
|
- name: Extended checks
|
||||||
run: |
|
run: |
|
||||||
poetry run poetry check
|
poetry run poetry check
|
||||||
|
@ -71,7 +71,7 @@ poetry run pytest
|
|||||||
|
|
||||||
### Run tests in docker compose:
|
### Run tests in docker compose:
|
||||||
```bash
|
```bash
|
||||||
docker compose run bot poetry run pytest bot_microservice/
|
STAGE=runtests docker compose run bot bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
@ -40,6 +40,8 @@ class BotApplication:
|
|||||||
logger.info("webhook has been deleted")
|
logger.info("webhook has been deleted")
|
||||||
|
|
||||||
async def polling(self) -> None:
|
async def polling(self) -> None:
|
||||||
|
if self.settings.STAGE == "runtests":
|
||||||
|
return None
|
||||||
await self.application.initialize()
|
await self.application.initialize()
|
||||||
await self.application.start()
|
await self.application.start()
|
||||||
await self.application.updater.start_polling() # type: ignore
|
await self.application.updater.start_polling() # type: ignore
|
||||||
|
@ -13,7 +13,7 @@ DOMAIN="http://localhost"
|
|||||||
URL_PREFIX=
|
URL_PREFIX=
|
||||||
|
|
||||||
# set to true to start with webhook. Else bot will start on polling method
|
# set to true to start with webhook. Else bot will start on polling method
|
||||||
START_WITH_WEBHOOK="true"
|
START_WITH_WEBHOOK="false"
|
||||||
|
|
||||||
# quantity of workers for uvicorn
|
# quantity of workers for uvicorn
|
||||||
WORKERS_COUNT=1
|
WORKERS_COUNT=1
|
||||||
|
@ -13,7 +13,7 @@ DOMAIN="http://localhost"
|
|||||||
URL_PREFIX=
|
URL_PREFIX=
|
||||||
|
|
||||||
# set to true to start with webhook. Else bot will start on polling method
|
# set to true to start with webhook. Else bot will start on polling method
|
||||||
START_WITH_WEBHOOK="true"
|
START_WITH_WEBHOOK="false"
|
||||||
|
|
||||||
# quantity of workers for uvicorn
|
# quantity of workers for uvicorn
|
||||||
WORKERS_COUNT=1
|
WORKERS_COUNT=1
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from os import environ
|
from os import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from constants import API_PREFIX
|
from constants import API_PREFIX
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pydantic import HttpUrl
|
from pydantic import HttpUrl, ValidationInfo, field_validator
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.parent
|
BASE_DIR = Path(__file__).parent.parent
|
||||||
@ -51,6 +52,12 @@ class AppSettings(SentrySettings, BaseSettings):
|
|||||||
# Enable uvicorn reloading
|
# Enable uvicorn reloading
|
||||||
RELOAD: bool = False
|
RELOAD: bool = False
|
||||||
|
|
||||||
|
@field_validator("START_WITH_WEBHOOK")
|
||||||
|
def star_with_webhook_validator(cls, field_value: Any, info: ValidationInfo) -> Any:
|
||||||
|
if field_value == "false":
|
||||||
|
return False
|
||||||
|
return field_value
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def api_prefix(self) -> str:
|
def api_prefix(self) -> str:
|
||||||
if self.URL_PREFIX:
|
if self.URL_PREFIX:
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
FROM python:3.11.5 AS compile-image
|
FROM python:3.11.5 AS compile-image
|
||||||
|
|
||||||
ARG USER
|
ARG USER=web
|
||||||
|
ARG STAGE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
||||||
DOCKER_CONTAINER=1 \
|
DOCKER_CONTAINER=1 \
|
||||||
POETRY_VERSION=1.6.1
|
POETRY_VERSION=1.6.1
|
||||||
|
|
||||||
RUN printf "================ Start build base service. with USER: ${USER} ===============" \
|
RUN printf "================ Start build base service. with USER: ${USER}, STAGE: ${STAGE} ===============" \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install --no-install-recommends -y \
|
&& apt-get install --no-install-recommends -y \
|
||||||
bash \
|
bash \
|
||||||
@ -31,7 +34,7 @@ WORKDIR /app/
|
|||||||
RUN if [ "$USER" != "root" ]; then \
|
RUN if [ "$USER" != "root" ]; then \
|
||||||
mkdir /home/${USER} \
|
mkdir /home/${USER} \
|
||||||
&& groupadd -r ${USER} && useradd -d /home/${USER} -r -g ${USER} ${USER} \
|
&& groupadd -r ${USER} && useradd -d /home/${USER} -r -g ${USER} ${USER} \
|
||||||
&& chown ${USER}:${USER} -R /home/${USER}; \
|
&& chown ${USER}:${USER} -R /home/${USER} /app; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COPY --chown=${USER}:${USER} ../poetry.lock ../pyproject.toml /app/
|
COPY --chown=${USER}:${USER} ../poetry.lock ../pyproject.toml /app/
|
||||||
@ -39,7 +42,7 @@ COPY --chown=${USER}:${USER} ../poetry.lock ../pyproject.toml /app/
|
|||||||
RUN pip install --upgrade pip && pip install poetry==$POETRY_VERSION
|
RUN pip install --upgrade pip && pip install poetry==$POETRY_VERSION
|
||||||
RUN poetry config virtualenvs.in-project true && \
|
RUN poetry config virtualenvs.in-project true && \
|
||||||
poetry config virtualenvs.create true && \
|
poetry config virtualenvs.create true && \
|
||||||
poetry install $(if [ "$USER" != "root" ]; then echo "--only main"; fi) --no-interaction --no-ansi && \
|
poetry install $(if [ "$STAGE" = "production" ]; then echo "--only main"; fi) --no-interaction --no-ansi && \
|
||||||
rm -rf $POETRY_CACHE_DIR
|
rm -rf $POETRY_CACHE_DIR
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,20 +19,15 @@ services:
|
|||||||
dockerfile: deploy/Dockerfile
|
dockerfile: deploy/Dockerfile
|
||||||
target: bot-service
|
target: bot-service
|
||||||
args:
|
args:
|
||||||
USER: web
|
STAGE: ${STAGE}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
env_file:
|
||||||
APP_HOST: "0.0.0.0"
|
- bot_microservice/settings/.env
|
||||||
APP_PORT: "8000"
|
|
||||||
WORKERS_COUNT: "1"
|
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/localtime:/etc/localtime:ro
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
chat-gpt-network:
|
chat-gpt-network:
|
||||||
ipv4_address: 200.20.0.10
|
ipv4_address: 200.20.0.10
|
||||||
depends_on:
|
|
||||||
- caddy
|
|
||||||
- chat-gpt
|
|
||||||
expose:
|
expose:
|
||||||
- "8000"
|
- "8000"
|
||||||
command: bash start-bot.sh
|
command: bash start-bot.sh
|
||||||
@ -46,7 +41,7 @@ services:
|
|||||||
dockerfile: deploy/Dockerfile
|
dockerfile: deploy/Dockerfile
|
||||||
target: chat-service
|
target: chat-service
|
||||||
args:
|
args:
|
||||||
USER: web
|
STAGE: ${STAGE}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
APP_HOST: "0.0.0.0"
|
APP_HOST: "0.0.0.0"
|
||||||
@ -55,8 +50,6 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
chat-gpt-network:
|
chat-gpt-network:
|
||||||
ipv4_address: 200.20.0.11
|
ipv4_address: 200.20.0.11
|
||||||
depends_on:
|
|
||||||
- caddy
|
|
||||||
expose:
|
expose:
|
||||||
- "1338"
|
- "1338"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user