Skip to content

Commit 01f910f

Browse files
authored
Merge pull request #59 from moevm/deploy_script
deploy_script_host
2 parents b1bd4c6 + 25bcf65 commit 01f910f

File tree

9 files changed

+202
-22
lines changed

9 files changed

+202
-22
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GRAFANA_PORT_DOCKER=3000
2+
GRAFANA_PORT_HOST=3000
3+
LOKI_URL_PUSH=http://localhost:3100/loki/api/v1/push
4+
METRICS_GATEWAY_ADDRESS=localhost
5+
METRICS_GATEWAY_PORT=9091
6+
SERVER_PORT=50051

deploy_service.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
if docker-compose --version >/dev/null 2>&1; then
4+
DOCKER_COMPOSE_CMD="docker-compose"
5+
elif docker compose --version >/dev/null 2>&1; then
6+
DOCKER_COMPOSE_CMD="docker compose"
7+
else
8+
echo "Error: No valid Docker Compose command found" >&2
9+
exit 1
10+
fi
11+
12+
set -e
13+
14+
REPO_DIR="external/grpc_server"
15+
LOG_COMPOSE_FILE="log_and_metric/docker-compose.yml"
16+
MAIN_COMPOSE_FILE="docker-compose.manager.controller.yml"
17+
DEFAULT_REPLICAS=5
18+
19+
function update_submodule() {
20+
if [ ! -d "$REPO_DIR" ]; then
21+
echo "Error: Submodule does not exist"
22+
exit 1
23+
fi
24+
git submodule update --init --recursive
25+
echo "Submodule successfully updated"
26+
}
27+
28+
function start_services() {
29+
local replicas=${1:-$DEFAULT_REPLICAS}
30+
31+
if [ ! -d "$REPO_DIR" ]; then
32+
echo "Error: Submodule does not exist"
33+
exit 1
34+
fi
35+
36+
${DOCKER_COMPOSE_CMD} -f "$LOG_COMPOSE_FILE" up -d --build
37+
REPLICAS=$replicas ${DOCKER_COMPOSE_CMD} -f "$MAIN_COMPOSE_FILE" up -d --build
38+
39+
echo "All services successfully started with $replicas replicas"
40+
}
41+
42+
function stop_services() {
43+
if [ ! -d "$REPO_DIR" ]; then
44+
echo "Error: Submodule does not exist"
45+
exit 1
46+
fi
47+
48+
${DOCKER_COMPOSE_CMD} -f "$MAIN_COMPOSE_FILE" down || true
49+
50+
${DOCKER_COMPOSE_CMD} -f "$LOG_COMPOSE_FILE" down || true
51+
52+
echo "All services successfully stopped"
53+
}
54+
55+
function restart_services() {
56+
local replicas=${1:-$DEFAULT_REPLICAS}
57+
stop_services
58+
start_services $replicas
59+
}
60+
61+
function show_help() {
62+
echo "Usage: $0 [command] [replicas]"
63+
echo ""
64+
echo "Commands:"
65+
echo " update - Update submodule"
66+
echo " start [replicas] - Start services (default: $DEFAULT_REPLICAS replicas)"
67+
echo " stop - Stop services"
68+
echo " restart [replicas] - Restart services (default: $DEFAULT_REPLICAS replicas)"
69+
echo " help - Show help message"
70+
}
71+
72+
case "$1" in
73+
update)
74+
update_submodule
75+
;;
76+
start)
77+
start_services "$2"
78+
;;
79+
stop)
80+
stop_services
81+
;;
82+
restart)
83+
restart_services "$2"
84+
;;
85+
help|--help|-h|"")
86+
show_help
87+
;;
88+
*)
89+
echo "Unknown command: $1"
90+
show_help
91+
exit 1
92+
;;
93+
esac

docker-compose.manager.controller.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: "3.8"
2+
3+
volumes:
4+
controller_run:
5+
driver: local
6+
driver_opts:
7+
type: tmpfs
8+
device: tmpfs
9+
10+
services:
11+
controller:
12+
build:
13+
context: external/grpc_server/controller
14+
dockerfile: Dockerfile.controller
15+
volumes:
16+
- controller_run:/run/controller
17+
restart: always
18+
network_mode: host
19+
user: "1000:1000"
20+
logging:
21+
driver: loki
22+
options:
23+
loki-timeout: 10s
24+
no-file: "true"
25+
loki-url: ${LOKI_URL_PUSH}
26+
loki-pipeline-stages: |
27+
- regex:
28+
expression: '(level|lvl|severity)=(?P<level>\w+)'
29+
- labels:
30+
level: level
31+
replicated_worker:
32+
user: "1000:1000"
33+
build:
34+
context: external/grpc_server
35+
dockerfile: Dockerfile.hash
36+
volumes:
37+
- controller_run:/run/controller
38+
environment:
39+
- METRICS_GATEWAY_ADDRESS=${METRICS_GATEWAY_ADDRESS}
40+
- METRICS_GATEWAY_PORT=${METRICS_GATEWAY_PORT}
41+
network_mode: host
42+
depends_on:
43+
- controller
44+
restart: always
45+
deploy:
46+
mode: replicated
47+
replicas: ${REPLICAS:-3}
48+
logging:
49+
driver: loki
50+
options:
51+
loki-timeout: 10s
52+
no-file: "true"
53+
loki-url: ${LOKI_URL_PUSH}
54+
loki-pipeline-stages: |
55+
- regex:
56+
expression: '(level|lvl|severity)=(?P<level>\w+)'
57+
- labels:
58+
level: level

external/grpc_server

Submodule grpc_server updated 53 files

log_and_metric/configs/prometheus.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
global:
2+
scrape_interval: 1s
3+
4+
scrape_configs:
5+
- job_name: worker-1
6+
honor_labels: true
7+
static_configs:
8+
- targets:
9+
- 'pushgateway:9091'
10+
- job_name: worker-2
11+
honor_labels: true
12+
static_configs:
13+
- targets:
14+
- 'pushgateway:9091'
15+
- job_name: worker-3
16+
honor_labels: true
17+
static_configs:
18+
- targets:
19+
- 'pushgateway:9091'
20+
- job_name: worker-4
21+
honor_labels: true
22+
static_configs:
23+
- targets:
24+
- 'pushgateway:9091'
25+
- job_name: worker-5
26+
honor_labels: true
27+
static_configs:
28+
- targets:
29+
- 'pushgateway:9091'

log_and_metric/docker-compose.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
version: '3'
22

33
services:
4+
pushgateway:
5+
image: prom/pushgateway:latest
6+
ports:
7+
- "9091:9091"
8+
restart: unless-stopped
49
prometheus:
510
image: prom/prometheus:latest
611
container_name: prometheus
12+
restart: unless-stopped
713
volumes:
8-
- ./prometheus.yml:/etc/prometheus/prometheus.yml
14+
- ./configs/prometheus.yml:/etc/prometheus/prometheus.yml
915
command:
1016
- '--config.file=/etc/prometheus/prometheus.yml'
1117
ports:
1218
- "9090:9090"
13-
networks:
14-
- monitoring
19+
depends_on:
20+
- pushgateway
1521

1622
loki:
1723
image: grafana/loki:latest
1824
container_name: loki
25+
user: root
26+
restart: unless-stopped
1927
ports:
2028
- "3100:3100"
2129
command: -config.file=/etc/loki/local-config.yaml
22-
networks:
23-
- monitoring
2430

2531
grafana:
2632
image: grafana/grafana:latest
2733
container_name: grafana
34+
restart: unless-stopped
2835
ports:
2936
- "3000:3000"
3037
volumes:
@@ -37,12 +44,6 @@ services:
3744
depends_on:
3845
- loki
3946
- prometheus
40-
networks:
41-
- monitoring
4247

4348
volumes:
4449
grafana-storage:
45-
46-
networks:
47-
monitoring:
48-
driver: bridge

log_and_metric/grafana/provisioning/datasources/datasources.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ datasources:
88
isDefault: true
99
jsonData:
1010
httpMethod: POST
11-
timeInterval: "15s"
11+
timeInterval: "5s"
1212

1313
- name: Loki
1414
type: loki
1515
url: http://loki:3100
1616
access: proxy
1717
jsonData:
1818
maxLines: 1000
19-
version: 1
19+
version: 1

log_and_metric/prometheus.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)