Skip to content

Commit bc119b8

Browse files
authored
Merge pull request #86 from GabrielSalla/add-scalable-deploy
Add scalable deploy
2 parents 427e392 + 3f63671 commit bc119b8

File tree

11 files changed

+325
-84
lines changed

11 files changed

+325
-84
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG PYTHON_VERSION=3.12
33
# Base image
44
FROM python:${PYTHON_VERSION}-alpine AS base
55

6+
ARG CONFIGS_FILE
67
ENV VIRTUAL_ENV=/opt/venv \
78
PATH="/opt/venv/bin:$PATH"
89

Makefile

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
1+
# Development
12
build-dev:
2-
docker compose -f docker-compose-dev.yaml build sentinela-dev
3+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml build sentinela-dev
34

45
pull-dev:
5-
docker compose -f docker-compose-dev.yaml pull --quiet postgres motoserver
6+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml pull --quiet postgres motoserver
67

78
migrate-dev:
8-
docker compose -f docker-compose-dev.yaml run --rm --service-ports sentinela-dev alembic upgrade head
9+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm --service-ports sentinela-dev alembic upgrade head
910

1011
run-dev:
11-
docker compose -f docker-compose-dev.yaml up sentinela-dev
12+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml up sentinela-dev
1213

1314
run-shell-dev:
14-
docker compose -f docker-compose-dev.yaml run --rm --service-ports sentinela-dev /bin/sh
15+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm --service-ports sentinela-dev /bin/sh
1516

1617
test-dev:
17-
docker compose -f docker-compose-dev.yaml run --rm sentinela-dev pytest
18+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm sentinela-dev pytest
1819

1920
down-dev:
20-
docker compose -f docker-compose-dev.yaml down
21+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml down
2122

23+
# Local development setup
2224
build-local:
23-
docker compose -f docker-compose-local.yaml build sentinela-local
25+
docker compose --project-directory . -f ./docker/docker-compose-local.yaml build sentinela-local
2426

2527
migrate-local:
26-
docker compose -f docker-compose-local.yaml run --rm --service-ports sentinela-local alembic upgrade head
28+
docker compose --project-directory . -f ./docker/docker-compose-local.yaml run --rm --service-ports sentinela-local alembic upgrade head
2729

2830
run-local:
29-
docker compose -f docker-compose-local.yaml up sentinela-local
31+
docker compose --project-directory . -f ./docker/docker-compose-local.yaml up sentinela-local
3032

3133
down-local:
32-
docker compose -f docker-compose-local.yaml down
34+
docker compose --project-directory . -f ./docker/docker-compose-local.yaml down
3335

36+
# Scalable setup for production-like environment
37+
build-scalable:
38+
docker compose --project-directory . -f ./docker/docker-compose-scalable.yaml build sentinela-controller
39+
40+
migrate-scalable:
41+
docker compose --project-directory . -f ./docker/docker-compose-scalable.yaml run --rm --service-ports sentinela-controller alembic upgrade head
42+
43+
run-scalable:
44+
docker compose --project-directory . -f ./docker/docker-compose-scalable.yaml up sentinela-controller sentinela-executor
45+
46+
down-scalable:
47+
docker compose --project-directory . -f ./docker/docker-compose-scalable.yaml down
48+
49+
# Development utilities
3450
linter:
35-
docker compose -f docker-compose-dev.yaml run --rm --no-deps sentinela-dev ruff check
36-
docker compose -f docker-compose-dev.yaml run --rm --no-deps sentinela-dev ruff format --check --diff
51+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm --no-deps sentinela-dev ruff check
52+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm --no-deps sentinela-dev ruff format --check --diff
3753

3854
mypy:
39-
docker compose -f docker-compose-dev.yaml run --rm --no-deps sentinela-dev mypy --install-types --non-interactive
55+
docker compose --project-directory . -f ./docker/docker-compose-dev.yaml run --rm --no-deps sentinela-dev mypy --install-types --non-interactive

configs/configs-scalable.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# The documentation for this configuration file can be found at "docs/configuration_file.md"
2+
plugins:
3+
- aws
4+
- postgres
5+
- slack
6+
7+
load_sample_monitors: true
8+
sample_monitors_path: sample_monitors
9+
internal_monitors_path: internal_monitors
10+
monitors_load_schedule: "*/5 * * * *"
11+
12+
logging:
13+
mode: friendly
14+
format: "%(asctime)s [%(levelname)s] %(name)s.%(funcName)s.%(lineno)d: %(message)s"
15+
16+
application_database_settings:
17+
pool_size: 10
18+
19+
application_queue:
20+
type: plugin.aws.sqs
21+
name: app
22+
url: http://motoserver:5000/123456789012/app
23+
region: us-east-1
24+
create_queue: true
25+
queue_wait_message_time: 2
26+
queue_visibility_time: 15
27+
28+
http_server:
29+
port: 8000
30+
31+
time_zone: America/Sao_Paulo
32+
33+
controller_process_schedule: "* * * * *"
34+
controller_concurrency: 5
35+
controller_procedures:
36+
monitors_stuck:
37+
schedule: "*/5 * * * *"
38+
params:
39+
time_tolerance: 10
40+
notifications_alert_solved:
41+
schedule: "*/5 * * * *"
42+
43+
executor_concurrency: 5
44+
executor_sleep: 5
45+
executor_monitor_timeout: 60
46+
executor_reaction_timeout: 5
47+
executor_request_timeout: 2
48+
executor_monitor_heartbeat_time: 5
49+
50+
max_issues_creation: 100
51+
52+
database_default_acquire_timeout: 30
53+
database_default_query_timeout: 30
54+
database_close_timeout: 30
55+
database_log_query_metrics: false
56+
57+
databases_pools_configs:
58+
local:
59+
min_size: 0
60+
max_size: 5
61+
timeout: 10
62+
max_inactive_connection_lifetime: 120
63+
server_settings:
64+
application_name: sentinela
65+
66+
log_all_events: false
File renamed without changes.

docker-compose-dev.yaml renamed to docker/docker-compose-dev.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ services:
2222
context: .
2323
dockerfile: Dockerfile
2424
target: sentinela_dev
25+
args:
26+
CONFIGS_FILE: configs/configs.yaml
2527
image: sentinela-dev:latest
2628
ports:
2729
- 8000:8000
2830
environment:
31+
CONFIGS_FILE: configs/configs.yaml
2932
SAMPLE_SLACK_CHANNEL: C07NCL94SDT
3033
SAMPLE_SLACK_MENTION: U07NFGGMB98
3134
SLACK_WEBSOCKET_ENABLED: true

docker-compose-local.yaml renamed to docker/docker-compose-local.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ services:
1111
context: .
1212
dockerfile: Dockerfile
1313
target: sentinela
14+
args:
15+
CONFIGS_FILE: configs/configs.yaml
1416
image: sentinela-local:latest
1517
ports:
1618
- 8000:8000
1719
healthcheck:
18-
test: curl --fail localhost:8000/status || exit 1
20+
test: python tools/health_check.py 8000
1921
interval: 10s
2022
timeout: 1s
2123
retries: 3
2224
start_period: 2s
2325
environment:
26+
CONFIGS_FILE: configs/configs.yaml
2427
SAMPLE_SLACK_CHANNEL: C07NCL94SDT
2528
SAMPLE_SLACK_MENTION: U07NFGGMB98
2629
SLACK_WEBSOCKET_ENABLED: true
2730
SLACK_MAIN_CHANNEL: C07NCL94SDT
2831
SLACK_MAIN_MENTION: U07NFGGMB98
2932
env_file:
3033
- .env.secrets
31-
volumes:
32-
- ./monitors:/app/monitors:Z
33-
- ./internal_monitors:/app/internal_monitors:Z
3434
depends_on:
3535
- postgres
3636
command: python3 src/main.py controller executor
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
services:
2+
postgres:
3+
image: postgres:16.4-alpine
4+
ports:
5+
- 5432:5432
6+
environment:
7+
- POSTGRES_PASSWORD=postgres
8+
9+
motoserver:
10+
image: ghcr.io/getmoto/motoserver:latest
11+
ports:
12+
- 5000:5000
13+
healthcheck:
14+
test: curl --fail localhost:5000 || exit 1
15+
interval: 1s
16+
timeout: 1s
17+
retries: 5
18+
start_period: 1s
19+
20+
sentinela-controller:
21+
build:
22+
context: .
23+
dockerfile: Dockerfile
24+
target: sentinela
25+
args:
26+
CONFIGS_FILE: configs/configs-scalable.yaml
27+
image: sentinela-scalable:latest
28+
ports:
29+
- 8000:8000
30+
healthcheck:
31+
test: python tools/health_check.py 8000
32+
interval: 10s
33+
timeout: 1s
34+
retries: 3
35+
start_period: 2s
36+
environment:
37+
CONFIGS_FILE: configs-scalable.yaml
38+
SAMPLE_SLACK_CHANNEL: C07NCL94SDT
39+
SAMPLE_SLACK_MENTION: U07NFGGMB98
40+
SLACK_WEBSOCKET_ENABLED: true
41+
SLACK_MAIN_CHANNEL: C07NCL94SDT
42+
SLACK_MAIN_MENTION: U07NFGGMB98
43+
env_file:
44+
- .env.secrets
45+
depends_on:
46+
- postgres
47+
- motoserver
48+
command: python3 src/main.py controller
49+
50+
sentinela-executor:
51+
build:
52+
context: .
53+
dockerfile: Dockerfile
54+
target: sentinela
55+
args:
56+
CONFIGS_FILE: configs/configs-scalable.yaml
57+
image: sentinela-scalable:latest
58+
deploy:
59+
mode: replicated
60+
replicas: 2
61+
ports:
62+
- 8001-8100:8000
63+
healthcheck:
64+
test: python tools/health_check.py 8000
65+
interval: 10s
66+
timeout: 1s
67+
retries: 3
68+
start_period: 2s
69+
environment:
70+
CONFIGS_FILE: configs-scalable.yaml
71+
SAMPLE_SLACK_CHANNEL: C07NCL94SDT
72+
SAMPLE_SLACK_MENTION: U07NFGGMB98
73+
SLACK_WEBSOCKET_ENABLED: true
74+
SLACK_MAIN_CHANNEL: C07NCL94SDT
75+
SLACK_MAIN_MENTION: U07NFGGMB98
76+
env_file:
77+
- .env.secrets
78+
depends_on:
79+
- postgres
80+
- motoserver
81+
command: python3 src/main.py executor

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ The basic configs are set through the `configs.yaml` file. This file is read whe
33

44
The monitors path is also defined in the `configs.yaml` file. By default, it's set to the `sample_monitors` folder, but it can be changed to another folder if desired. The `configs.yaml` file also have other configurations that can be adjusted.
55

6+
# Environment variables
67
> [!IMPORTANT]
78
> Check the documentation for the plugins that are being used to see if they have environment variables of their own.
89
9-
# Environment variables
1010
## `CONFIGS_FILE`
1111
The application will try to load the configs file through the path defined in the `CONFIGS_FILE` environment variable. If this variable is not defined, it'll look for the file in the root directory of the application.
1212

0 commit comments

Comments
 (0)