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 to master #9

Merged
merged 14 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Linters & tests running workflow

name: Decision Making Application

on:

workflow_call:

pull_request:
branches: [ master, dev, ]
push:
branches: [ master, dev, ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "poetry"
cache-dependency-path: poetry.lock
- name: Install dependencies
run: poetry install --with lint,test
- name: Lint with ruff
run: poetry run ruff check
- name: Lint with mypy
run: poetry run mypy .
test:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "poetry"
cache-dependency-path: poetry.lock
- name: Install dependencies
run: poetry install --with test
- name: Test with pytest
run: poetry run pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.idea
.python-version
.DS_Store
.mypy_cache/
.pytest_cache/
.ruff_cache/
__pycache__/

config/local.ini
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim-buster as python-base
FROM python:3.11 as python-base

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -16,26 +16,25 @@ ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
FROM python-base as builder-base

RUN apt-get update \
&& apt-get install -y gcc git
&& apt-get install -y gcc git libpq-dev

WORKDIR $PYSETUP_PATH

COPY ./pyproject.toml .
# due to the installation of the project itself, it should contain all the files
COPY . .

RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir setuptools wheel \
&& pip install --no-cache-dir poetry

RUN poetry install --no-root --only main
RUN poetry install --only main

FROM python-base as production

COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH

RUN apt-get update && apt-get install -y curl

WORKDIR decision-making-app/

COPY . /decision-making-app/

CMD ["python", "-Om", "src.app"]
CMD ["python", "-Om", "dma"]
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[alembic]
# path to migration scripts
script_location = ./src/app/infrastructure/database/migrations
script_location = ./src/dma/infrastructure/database/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down
22 changes: 18 additions & 4 deletions config/local.dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ port = 5000
logging_level = DEBUG

[database]
host = webchat.postgres
host = decision_making_app.postgres
port = 5432
database = webchat
user = admin
password = admin
database = decision_making_app
user = decision_making_app_admin
password = decision_making_app_admin
echo = true

[object_storage]
access_key = decision_making_app_admin
secret_key = decision_making_app_admin
bucket_name = decision_making_app

[message_queue]
host = decision_making_app.rabbitmq
port = 5672
username = decision_making_app_admin
password = decision_making_app_admin
connection_pool_max_size = 3
channel_pool_max_size = 15
default_exchange_name = decision_making_app
140 changes: 130 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ services:
ports:
- "5000:5000"
depends_on:
minio:
condition: service_healthy
postgres:
condition: service_healthy
rabbitmq:
condition: service_healthy
networks:
- decision_making_app.minio.network
- decision_making_app.postgres.network
- decision_making_app.rabbitmq.network
volumes:
- ./config:/decision_making_app/config:ro
environment:
- CONFIG_PATH=${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-Om", "src.app" ]
CONFIG_PATH: ${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-Om", "dma" ]
healthcheck:
test: [ "CMD-SHELL", "curl -fsSL http://localhost:5000/healthcheck/" ]
interval: 10s
Expand All @@ -31,8 +37,8 @@ services:
postgres:
profiles: [ "api", "migration" ]
container_name: decision_making_app.postgres
image: "postgres:15-alpine"
hostname: decision_making_app.postgres
image: "postgres:15-alpine"
restart: unless-stopped
expose:
- "5432"
Expand All @@ -41,13 +47,13 @@ services:
networks:
- decision_making_app.postgres.network
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin}
POSTGRES_USER: ${POSTGRES_USER:-admin}
POSTGRES_DATABASE: ${POSTGRES_DATABASE:-decision_making_app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-decision_making_app_admin}
POSTGRES_USER: ${POSTGRES_USER:-decision_making_app_admin}
POSTGRES_DB: ${POSTGRES_DB:-decision_making_app}
volumes:
- decision_making_app.postgres.data:/var/lib/postgresql/data:rw
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DATABASE} -U $${POSTGRES_USER}" ]
test: [ "CMD-SHELL", "pg_isready -d $$POSTGRES_DB -U $$POSTGRES_USER" ]
interval: 10s
timeout: 60s
retries: 5
Expand All @@ -67,14 +73,128 @@ services:
volumes:
- ./config:/decision_making_app/config:ro
- ./alembic.ini:/decision_making_app/alembic.ini:ro
- ./src/app/infrastructure/database/migrations:/decision_making_app/src/app/infrastructure/database/migrations:ro
- ./src/dma/infrastructure/database/migrations:/decision_making_app/src/dma/infrastructure/database/migrations:ro
environment:
CONFIG_PATH: ${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-Om", "alembic", "upgrade", "head" ]

minio:
profiles: [ "api" ]
container_name: decision_making_app.minio
image: "quay.io/minio/minio"
command: [ "server", "--address", ":9000", "--console-address", ":9001", "/data" ]
ports:
- "9000:9000"
- "9001:9001"
networks:
- decision_making_app.minio.network
volumes:
- decision_making_app.minio.data:/data:rw
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-decision_making_app_admin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-decision_making_app_admin}
healthcheck:
test: [ "CMD", "mc", "ready", "local" ]
interval: 5s
timeout: 5s
retries: 5
# test: [ "CMD-SHELL", "curl -I http://localhost:9000/minio/health/live" ]
# interval: 10s
# timeout: 60s
# retries: 5
# start_period: 10s

rabbitmq:
profiles: [ "api" ]
image: rabbitmq:3.11-management-alpine
container_name: decision_making_app.rabbitmq
hostname: decision_making_app.rabbitmq
restart: unless-stopped
expose:
- "5672" # AMQP port
- "15672" # HTTP management UI dashboard port
ports:
- "127.0.0.1:5672:5672"
- "127.0.0.1:15672:15672"
networks:
- decision_making_app.rabbitmq.network
volumes:
- decision_making_app.rabbitmq.data:/var/lib/rabbitmq/:rw
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER:-decision_making_app_admin}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD:-decision_making_app_admin}
healthcheck:
test: [ "CMD-SHELL", "rabbitmq-diagnostics check_running -q" ]
interval: 10s
timeout: 60s
retries: 5
start_period: 10s

grafana:
profiles: [ "grafana" ]
image: grafana/grafana:9.5.2
container_name: decision_making_app.grafana
hostname: decision_making_app.grafana
restart: unless-stopped
expose:
- "3000"
ports:
- "127.0.0.1:3000:3000"
networks:
- decision_making_app.grafana.network
volumes:
- decision_making_app.grafana.data:/var/lib/grafana:rw
- ./grafana/provisioning:/etc/grafana/provisioning:rw
environment:
- CONFIG_PATH=${CONFIG_PATH:-./config/local.ini}
command: [ "python", "-m", "alembic", "upgrade", "head" ]
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-decision_making_app_admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-decision_making_app_admin}
- GF_USERS_ALLOW_SIGN_UP=false
- VIRTUAL_HOST=decision_making_app.grafana
- NETWORK_ACCESS=internal
- VIRTUAL_PORT=3000

loki:
profiles: [ "grafana" ]
image: grafana/loki:2.8.2
container_name: decision_making_app.loki
hostname: decision_making_app.loki
expose:
- "3100"
volumes:
- ./loki/config.yaml:/etc/loki/config.yaml:ro
- decision_making_app.loki.data:/tmp/:rw
command: -config.file=/etc/loki/config.yaml
restart: unless-stopped
networks:
- decision_making_app.grafana.network

vector:
profiles: [ "grafana" ]
image: timberio/vector:0.29.1-alpine
container_name: decision_making_app.vector
hostname: decision_making_app.vector
depends_on:
loki:
condition: service_started
command: --config /etc/vector/vector.toml
restart: unless-stopped
expose:
- "8383"
networks:
- decision_making_app.grafana.network
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./vector/vector.toml:/etc/vector/vector.toml:ro

volumes:
decision_making_app.minio.data:
decision_making_app.postgres.data:
decision_making_app.rabbitmq.data:
decision_making_app.grafana.data:
decision_making_app.loki.data:

networks:
decision_making_app.minio.network:
decision_making_app.postgres.network:
decision_making_app.rabbitmq.network:
decision_making_app.grafana.network:
14 changes: 14 additions & 0 deletions grafana/provisioning/datasources/loki.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: 1

datasources:
- name: Loki
type: loki
access: proxy
url: http://decision_making_app.loki:3100
basicAuth: false
isDefault: true
editable: true
orgId: 1
version: 1
jsonData:
timeInterval: 15s
37 changes: 37 additions & 0 deletions loki/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096

common:
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
instance_addr: 127.0.0.1
kvstore:
store: inmemory

schema_config:
configs:
- from: 2023-01-01
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

ruler:
alertmanager_url: http://localhost:9093
Loading
Loading