Skip to content

Commit 8272d1b

Browse files
shaneinglaiwei
andauthored
chore: add docker compose (open-falcon#867)
* chore: add docker compose * chore: correct the replace function in ctrl.sh * use golang1.15 and alpine 3.13 in base image Co-authored-by: Vic Lai <[email protected]>
1 parent 42f06b9 commit 8272d1b

File tree

8 files changed

+247
-20
lines changed

8 files changed

+247
-20
lines changed

Dockerfile.module

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build container;
2+
FROM openfalcon/makegcc-golang:1.15-alpine
3+
LABEL maintainer [email protected]
4+
USER root
5+
6+
ENV FALCON_DIR=/open-falcon PROJ_PATH=${GOPATH}/src/github.com/open-falcon/falcon-plus
7+
8+
RUN mkdir -p $FALCON_DIR && \
9+
apk add --no-cache ca-certificates git
10+
11+
COPY . ${PROJ_PATH}
12+
13+
WORKDIR ${PROJ_PATH}
14+
15+
ARG MODULE
16+
17+
RUN make $MODULE \
18+
&& make pack4docker CMD=$MODULE \
19+
&& tar -zxf open-falcon-v*.tar.gz -C ${FALCON_DIR} \
20+
&& rm -rf ${PROJ_PATH}
21+
22+
# Final container;
23+
FROM alpine:3.13
24+
LABEL maintainer [email protected]
25+
USER root
26+
27+
ENV FALCON_DIR=/open-falcon
28+
29+
RUN mkdir -p $FALCON_DIR/logs && \
30+
apk update && \
31+
apk add --no-cache ca-certificates bash git iproute2
32+
33+
COPY --from=0 ${FALCON_DIR} ${FALCON_DIR}
34+
35+
EXPOSE 8433 8080
36+
WORKDIR ${FALCON_DIR}

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ pack4docker: checkbin
7878
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/logs;)
7979
@$(foreach var,$(CMD),cp ./config/$(var).json ./out/$(var)/config/cfg.json;)
8080
@$(foreach var,$(CMD),cp ./bin/$(var)/falcon-$(var) ./out/$(var)/bin;)
81-
@cp -r ./modules/agent/public ./out/agent/
82-
@(cd ./out && ln -s ./agent/public/ ./public)
83-
@(cd ./out && mkdir -p ./agent/plugin && ln -s ./agent/plugin/ ./plugin)
84-
@cp -r ./modules/api/data ./out/api/
85-
@mkdir out/graph/data
86-
@bash ./docker/confgen4docker.sh
81+
@if expr "$(CMD)" : "agent" > /dev/null; then \
82+
(cp -r ./modules/agent/public ./out/agent/); \
83+
(cd ./out && ln -s ./agent/public/ ./public); \
84+
(cd ./out && mkdir -p ./agent/plugin && ln -s ./agent/plugin/ ./plugin); \
85+
fi
86+
@if expr "$(CMD)" : "api" > /dev/null; then \
87+
cp -r ./modules/api/data ./out/api/; \
88+
fi
89+
@if expr "$(CMD)" : "graph" > /dev/null; then \
90+
mkdir out/graph/data; \
91+
fi
8792
@cp ./docker/ctrl.sh ./out/ && chmod +x ./out/ctrl.sh
8893
@cp $(TARGET) ./out/$(TARGET)
8994
tar -C out -zcf open-falcon-v$(VERSION).tar.gz .

config/agent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"debug": true,
3-
"hostname": "",
3+
"hostname": "%%AGENT_HOSTNAME%%",
44
"ip": "",
55
"plugin": {
66
"enabled": false,

config/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"graphs": {
1212
"cluster": {
13-
"graph-00": "127.0.0.1:6070"
13+
"graph-00": "%%GRAPH_RPC%%"
1414
},
1515
"max_conns": 100,
1616
"max_idle": 100,

config/confgen.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ confs=(
1616
'%%MYSQL%%=root:@tcp(127.0.0.1:3306)'
1717
'%%PLUS_API_DEFAULT_TOKEN%%=default-token-used-in-server-side'
1818
'%%PLUS_API_HTTP%%=0.0.0.0:8080'
19+
'%%AGENT_HOSTNAME%%='
1920
)
2021

2122
configurer() {

docker-compose.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
version: '3.5'
2+
3+
services:
4+
mysql:
5+
container_name: falcon-mysql
6+
image: mysql:5.7
7+
environment:
8+
MYSQL_ROOT_PASSWORD: root
9+
volumes:
10+
- ./scripts/mysql/db_schema:/docker-entrypoint-initdb.d/
11+
- mysql-data:/var/lib/mysql
12+
13+
redis:
14+
container_name: falcon-redis
15+
image: redis:4-alpine3.8
16+
17+
hbs: &falcon
18+
container_name: falcon-hbs
19+
build:
20+
context: ./
21+
args:
22+
MODULE: hbs
23+
dockerfile: Dockerfile.module
24+
image: openfalcon/falcon-hbs:dev
25+
environment:
26+
MYSQL_PORT: root:root@tcp\(falcon-mysql:3306\)
27+
REDIS_PORT: falcon-redis:6379
28+
AGGREGATOR_HTTP: falcon-aggregator:6055
29+
GRAPH_HTTP: falcon-graph:6071
30+
GRAPH_RPC: falcon-graph:6070
31+
HBS_HTTP: falcon-hbs:6031
32+
HBS_RPC: falcon-hbs:6030
33+
JUDGE_HTTP: falcon-judge:6081
34+
JUDGE_RPC: falcon-judge:6080
35+
NODATA_HTTP: falcon-nodata:6090
36+
TRANSFER_HTTP: falcon-transfer:6060
37+
TRANSFER_RPC: falcon-transfer:8433
38+
PLUS_API_HTTP: falcon-api:8080
39+
AGENT_HOSTNAME: docker-agent
40+
depends_on:
41+
- mysql
42+
- redis
43+
command: "sh ctrl.sh run hbs"
44+
45+
agent:
46+
<<: *falcon
47+
build:
48+
context: ./
49+
args:
50+
MODULE: agent
51+
dockerfile: Dockerfile.module
52+
image: openfalcon/falcon-agent:dev
53+
container_name: falcon-agent
54+
depends_on:
55+
- hbs
56+
- transfer
57+
command: "sh ctrl.sh run agent"
58+
59+
aggregator:
60+
<<: *falcon
61+
build:
62+
context: ./
63+
args:
64+
MODULE: aggregator
65+
dockerfile: Dockerfile.module
66+
image: openfalcon/falcon-aggregator:dev
67+
container_name: falcon-aggregator
68+
command: "sh ctrl.sh run aggregator"
69+
70+
nodata:
71+
<<: *falcon
72+
build:
73+
context: ./
74+
args:
75+
MODULE: nodata
76+
dockerfile: Dockerfile.module
77+
image: openfalcon/falcon-nodata:dev
78+
container_name: falcon-nodata
79+
command: "sh ctrl.sh run nodata"
80+
81+
api:
82+
<<: *falcon
83+
build:
84+
context: ./
85+
args:
86+
MODULE: api
87+
dockerfile: Dockerfile.module
88+
image: openfalcon/falcon-api:dev
89+
container_name: falcon-api
90+
command: "sh ctrl.sh run api"
91+
ports:
92+
- 8080:8080
93+
94+
alarm:
95+
<<: *falcon
96+
build:
97+
context: ./
98+
args:
99+
MODULE: alarm
100+
dockerfile: Dockerfile.module
101+
image: openfalcon/falcon-alarm:dev
102+
container_name: falcon-alarm
103+
command: "sh ctrl.sh run alarm"
104+
105+
transfer:
106+
<<: *falcon
107+
build:
108+
context: ./
109+
args:
110+
MODULE: transfer
111+
dockerfile: Dockerfile.module
112+
image: openfalcon/falcon-transfer:dev
113+
container_name: falcon-transfer
114+
depends_on:
115+
- graph
116+
command: "sh ctrl.sh run transfer"
117+
118+
judge:
119+
<<: *falcon
120+
build:
121+
context: ./
122+
args:
123+
MODULE: judge
124+
dockerfile: Dockerfile.module
125+
image: openfalcon/falcon-judge:dev
126+
container_name: falcon-judge
127+
command: "sh ctrl.sh run judge"
128+
129+
graph:
130+
<<: *falcon
131+
build:
132+
context: ./
133+
args:
134+
MODULE: graph
135+
dockerfile: Dockerfile.module
136+
image: openfalcon/falcon-graph:dev
137+
container_name: falcon-graph
138+
volumes:
139+
- graph-data:/open-falcon/data
140+
command: "sh ctrl.sh run graph"
141+
142+
dashboard:
143+
container_name: falcon-dashboard
144+
image: openfalcon/falcon-dashboard:v0.2.1
145+
entrypoint: ./control startfg
146+
environment:
147+
API_ADDR: http://falcon-api:8080/api/v1
148+
PORTAL_DB_HOST: mysql
149+
PORTAL_DB_PORT: 3306
150+
PORTAL_DB_USER: root
151+
PORTAL_DB_PASS: root
152+
PORTAL_DB_NAME: falcon_portal
153+
ALARM_DB_HOST: mysql
154+
ALARM_DB_PORT: 3306
155+
ALARM_DB_USER: root
156+
ALARM_DB_PASS: root
157+
ALARM_DB_NAME: alarms
158+
working_dir: /open-falcon/dashboard
159+
ports:
160+
- 8081:8081
161+
162+
volumes:
163+
mysql-data:
164+
graph-data:

docker/confgen4docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ confs=(
1414
'%%TRANSFER_RPC%%=0.0.0.0:8433'
1515
'%%PLUS_API_DEFAULT_TOKEN%%=default-token-used-in-server-side'
1616
'%%PLUS_API_HTTP%%=0.0.0.0:8080'
17+
'%%AGENT_HOSTNAME%%='
1718
)
1819

1920
configurer() {

docker/ctrl.sh

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,40 @@ DOCKER_DIR=/open-falcon
44
of_bin=$DOCKER_DIR/open-falcon
55
DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')
66

7-
#use the correct mysql instance
8-
if [ -z $MYSQL_PORT ]; then
9-
MYSQL_PORT=$DOCKER_HOST_IP:3306
10-
fi
11-
find $DOCKER_DIR/*/config/*.json -type f -exec sed -i "s/%%MYSQL%%/$MYSQL_PORT/g" {} \;
7+
# Search $1 and replace with $2 or $3(defualt)
8+
replace() {
9+
replacement=$2
10+
if [ -z "$replacement" ]; then
11+
replacement=$3
12+
fi
13+
find $DOCKER_DIR/*/config/*.json -type f -exec sed -i "s/$1/$replacement/g" {} \;
14+
}
1215

13-
14-
#use the correct redis instance
15-
if [ -z $REDIS_PORT ]; then
16-
REDIS_PORT=$DOCKER_HOST_IP:6379
17-
fi
18-
find $DOCKER_DIR/*/config/*.json -type f -exec sed -i "s/%%REDIS%%/$REDIS_PORT/g" {} \;
16+
replace "%%MYSQL%%" "$MYSQL_PORT" "$DOCKER_HOST_IP:3306"
17+
replace "%%REDIS%%" "$REDIS_PORT" "$DOCKER_HOST_IP:6379"
18+
replace "%%AGGREGATOR_HTTP%%" "$AGGREGATOR_HTTP" "0.0.0.0:6055"
19+
replace "%%GRAPH_HTTP%%" "$GRAPH_HTTP" "0.0.0.0:6071"
20+
replace "%%GRAPH_RPC%%" "$GRAPH_RPC" "0.0.0.0:6070"
21+
replace "%%HBS_HTTP%%" "$HBS_HTTP" "0.0.0.0:6031"
22+
replace "%%HBS_RPC%%" "$HBS_RPC" "0.0.0.0:6030"
23+
replace "%%JUDGE_HTTP%%" "$JUDGE_HTTP" "0.0.0.0:6081"
24+
replace "%%JUDGE_RPC%%" "$JUDGE_RPC" "0.0.0.0:6080"
25+
replace "%%NODATA_HTTP%%" "$NODATA_HTTP" "0.0.0.0:6090"
26+
replace "%%TRANSFER_HTTP%%" "$TRANSFER_HTTP" "0.0.0.0:6060"
27+
replace "%%TRANSFER_RPC%%" "$TRANSFER_RPC" "0.0.0.0:8433"
28+
replace "%%PLUS_API_HTTP%%" "$PLUS_API_HTTP" "0.0.0.0:8080"
29+
replace "%%AGENT_HOSTNAME%%" "$AGENT_HOSTNAME" ""
1930

2031
#use absolute path of metric_list_file in docker
2132
TAB=$'\t'; sed -i "s|.*metric_list_file.*|${TAB}\"metric_list_file\": \"$DOCKER_DIR/api/data/metric\",|g" $DOCKER_DIR/api/config/*.json;
2233

23-
supervisorctl $*
34+
action=$1
35+
module_name=$2
36+
case $action in
37+
run)
38+
$DOCKER_DIR/"$module_name"/bin/falcon-"$module_name" -c /open-falcon/"$module_name"/config/cfg.json
39+
;;
40+
*)
41+
supervisorctl $*
42+
;;
43+
esac

0 commit comments

Comments
 (0)