add ci tests in docker compose (#11)

This commit is contained in:
Dmitry Afanasyev 2023-09-26 13:28:34 +03:00 committed by GitHub
parent e8ace80d68
commit 4e97baf525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 26 deletions

View File

@ -37,7 +37,6 @@ jobs:
curl -sSL "https://install.python-poetry.org" | python -
# Adding `poetry` to `$PATH`:
echo "$HOME/.local/bin" >> $GITHUB_PATH
apt-get update && apt-get install --no-install-recommends -y ffmpeg
- name: Set up cache
uses: actions/cache@v3
@ -64,14 +63,10 @@ jobs:
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Run tests
run: |
source .venv/bin/activate
poetry run pytest bot_microservice/ -vv --exitfirst
- name: Coverage report
run: |
poetry run coverage run -m pytest bot_microservice/
poetry run coverage report
cp bot_microservice/serrings/.env.ci.runtests bot_microservice/serrings/.env
docker compose run bot poetry run bash -c "coverage run -m pytest -vv --exitfirst && poetry run coverage report"
- name: Extended checks
run: |
poetry run poetry check

View File

@ -71,7 +71,7 @@ poetry run pytest
### Run tests in docker compose:
```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

View File

@ -40,6 +40,8 @@ class BotApplication:
logger.info("webhook has been deleted")
async def polling(self) -> None:
if self.settings.STAGE == "runtests":
return None
await self.application.initialize()
await self.application.start()
await self.application.updater.start_polling() # type: ignore

View File

@ -13,7 +13,7 @@ DOMAIN="http://localhost"
URL_PREFIX=
# 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
WORKERS_COUNT=1

View File

@ -13,7 +13,7 @@ DOMAIN="http://localhost"
URL_PREFIX=
# 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
WORKERS_COUNT=1

View File

@ -1,10 +1,11 @@
from functools import cached_property
from os import environ
from pathlib import Path
from typing import Any
from constants import API_PREFIX
from dotenv import load_dotenv
from pydantic import HttpUrl
from pydantic import HttpUrl, ValidationInfo, field_validator
from pydantic_settings import BaseSettings
BASE_DIR = Path(__file__).parent.parent
@ -51,6 +52,12 @@ class AppSettings(SentrySettings, BaseSettings):
# Enable uvicorn reloading
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
def api_prefix(self) -> str:
if self.URL_PREFIX:

View File

@ -1,13 +1,16 @@
FROM python:3.11.5 AS compile-image
ARG USER
ARG USER=web
ARG STAGE
ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
DOCKER_CONTAINER=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 install --no-install-recommends -y \
bash \
@ -31,7 +34,7 @@ WORKDIR /app/
RUN if [ "$USER" != "root" ]; then \
mkdir /home/${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
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 poetry config virtualenvs.in-project 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

View File

@ -19,20 +19,15 @@ services:
dockerfile: deploy/Dockerfile
target: bot-service
args:
USER: web
STAGE: ${STAGE}
restart: unless-stopped
environment:
APP_HOST: "0.0.0.0"
APP_PORT: "8000"
WORKERS_COUNT: "1"
env_file:
- bot_microservice/settings/.env
volumes:
- /etc/localtime:/etc/localtime:ro
networks:
chat-gpt-network:
ipv4_address: 200.20.0.10
depends_on:
- caddy
- chat-gpt
expose:
- "8000"
command: bash start-bot.sh
@ -46,7 +41,7 @@ services:
dockerfile: deploy/Dockerfile
target: chat-service
args:
USER: web
STAGE: ${STAGE}
restart: unless-stopped
environment:
APP_HOST: "0.0.0.0"
@ -55,8 +50,6 @@ services:
networks:
chat-gpt-network:
ipv4_address: 200.20.0.11
depends_on:
- caddy
expose:
- "1338"