From 3472c3fd7138f41fca608201f54a7dff3166a0d6 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Fri, 27 Dec 2024 01:38:50 +0300 Subject: [PATCH] Feat: started CI/CD work --- .woodpecker.yml | 0 Dockerfile | 17 +++++++++++++++++ docker-compose.yml | 42 +++++++++++++++++++++++++++++++++++++----- nwxraybot/config.py | 2 +- supervisord.conf | 11 +++++++++++ 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 .woodpecker.yml create mode 100644 Dockerfile create mode 100644 supervisord.conf diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7cdffe5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.13.1-slim + +WORKDIR /app + +COPY poetry.lock pyproject.toml ./ + +RUN pip install poetry + +RUN poetry config virtualenvs.create false +RUN poetry install --no-interaction --no-ansi + +COPY .env . +COPY . . + +ENV POSTGRES_PORT=5432 + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6ba8770..9c4aaf3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,42 @@ services: + bot: + image: aboba:latest + deploy: + replicas: 1 + restart_policy: + condition: on-failure + networks: + - bot_network + depends_on: + db: + condition: service_healthy + db: image: postgres:alpine - restart: always + deploy: + replicas: 1 + restart_policy: + condition: on-failure environment: - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_DB: ${POSTGRES_DB:-postgres} ports: - - ${POSTGRES_PORT}:5432 \ No newline at end of file + - 5432 + healthcheck: + test: ["CMD", "pg_isready"] + interval: 10s + timeout: 5s + retries: 10 + networks: + - bot_network + volumes: + - postgres_data:/var/lib/postgresql/data + + +networks: + bot_network: + driver: overlay + +volumes: + postgres_data: \ No newline at end of file diff --git a/nwxraybot/config.py b/nwxraybot/config.py index a707528..1b8c4ef 100644 --- a/nwxraybot/config.py +++ b/nwxraybot/config.py @@ -9,7 +9,7 @@ class Settings(BaseSettings): postgres_password: SecretStr = Field('password', env="POSTGRES_PASSWORD") postgres_db: str = Field('db', env="POSTGRES_DB") postgres_host: str = Field('localhost', env="POSTGRES_HOST") - postgres_port: int = Field(15432, env="POSTGRES_PORT") + postgres_port: int = Field(5432, env="POSTGRES_PORT") @property def postgres_url(self) -> str: diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..de8c5ea --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,11 @@ +[supervisord] +nodaemon=false + +[program:mybot] +command=python main.py +directory=/app +user=root +autostart=true +autorestart=true +stderr_logfile=/app/bot_err.log +stdout_logfile=/app/bot_out.log \ No newline at end of file