-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_docker_compose.sh
More file actions
72 lines (63 loc) · 1.64 KB
/
3_docker_compose.sh
File metadata and controls
72 lines (63 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# 定义输出文件名
output="docker-compose.yaml"
# 开始写入docker-compose文件的基本信息
cat > $output <<EOF
version: '3'
name: cess-storage
services:
EOF
# 读取每个db和其下的disk
jq -r '.dbs | to_entries[] | .key as $db | .value[] | "\($db)/\(.)"' config.json | while read path; do
disk=$(basename $path)
bucket_number=$(echo $disk | grep -o -E '[0-9]+')
container_name="bucket_$bucket_number"
db_folder=$(dirname $path | tr -d './')
# 写入每个bucket的配置到docker-compose.yaml
cat >> $output <<EOF
$container_name:
image: 'cesslab/cess-bucket:testnet'
network_mode: host
restart: always
volumes:
- '/mnt/$path/bucket:/opt/bucket'
- '/mnt/$path/storage/:/opt/bucket-disk'
command:
- run
- '-c'
- /opt/bucket/config.yaml
logging:
driver: json-file
options:
max-size: 500m
container_name: $container_name
EOF
done
# # 添加watchtower服务至docker-compose.yaml
# cat >> $output <<EOF
# watchtower:
# image: containrrr/watchtower
# container_name: watchtower
# network_mode: host
# restart: always
# volumes:
# - '/var/run/docker.sock:/var/run/docker.sock'
# command:
# - '--cleanup'
# - '--interval'
# - '300'
# - '--enable-lifecycle-hooks'
# - chain
# - bucket
# logging:
# driver: json-file
# options:
# max-size: 100m
# max-file: '7'
# EOF
echo "docker-compose.yaml has been generated."
# # 删除watchtower容器,避免compose出错
# docker stop watchtower
# docker rm watchtower
# 启动compose
docker compose up -d