Skip to content

Commit

Permalink
run falcon in docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
laiwei committed Aug 16, 2018
1 parent def14f4 commit 6870319
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 1,008 deletions.
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.10-alpine3.7
LABEL maintainer [email protected]
USER root

ENV FALCON_DIR=/open-falcon
ENV PROJ_PATH=${GOPATH}/src/github.com/open-falcon/falcon-plus

RUN mkdir -p $FALCON_DIR && \
apk add --no-cache ca-certificates bash git g++ perl make supervisor
COPY . ${PROJ_PATH}

WORKDIR ${PROJ_PATH}
RUN make all \
&& make pack4docker \
&& tar -zxf open-falcon-v*.tar.gz -C ${FALCON_DIR} \
&& rm -rf ${PROJ_PATH}
ADD docker/supervisord.conf /etc/supervisord.conf
RUN mkdir -p $FALCON_DIR/logs

EXPOSE 8433 8080
WORKDIR ${FALCON_DIR}

# Start
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ pack: checkbin
tar -C out -zcf open-falcon-v$(VERSION).tar.gz .
@rm -rf out

pack4docker: checkbin
@if [ -e out ] ; then rm -rf out; fi
@mkdir out
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/bin;)
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/config;)
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/logs;)
@$(foreach var,$(CMD),cp ./config/$(var).json ./out/$(var)/config/cfg.json;)
@$(foreach var,$(CMD),cp ./bin/$(var)/falcon-$(var) ./out/$(var)/bin;)
@cp -r ./modules/agent/public ./out/agent/
@(cd ./out && ln -s ./agent/public/ ./public)
@(cd ./out && mkdir -p ./agent/plugin && ln -s ./agent/plugin/ ./plugin)
@cp -r ./modules/api/data ./out/api/
@mkdir out/graph/data
@bash ./docker/confgen4docker.sh
@cp ./docker/ctrl.sh ./out/ && chmod +x ./out/ctrl.sh
@cp $(TARGET) ./out/$(TARGET)
tar -C out -zcf open-falcon-v$(VERSION).tar.gz .
@rm -rf out

clean:
@rm -rf ./bin
@rm -rf ./out
Expand Down
108 changes: 99 additions & 9 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,106 @@
## Running falcon-plus container
## Running open-falcon container

docker pull openfalcon/falcon-plus:0.2.0
docker run -itd -p 8081:8081 openfalcon/falcon-plus:0.2.0 bash /run.sh hbs
`the latest version in docker hub is v0.2.1`

## Running falcon-plus container with docker-compose
##### 1. Start mysql and init the mysql table before the first running
```
## start mysql in container
docker run -itd \
--name falcon-mysql \
-v /home/work/mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=test123456 \
-p 3306:3306 \
mysql:5.7
docker-compose -f init.yml up -d falcon-plus
## init mysql table before the first running
cd /tmp && \
git clone https://github.com/open-falcon/falcon-plus && \
cd /tmp/falcon-plus/ && \
for x in `ls ./scripts/mysql/db_schema/*.sql`; do
echo init mysql table $x ...;
docker exec -i falcon-mysql mysql -uroot -ptest123456 < $x;
done
## Running mysql and redis container
rm -rf /tmp/falcon-plus/
```

docker-compose -f init.yml up -d mysql redis
##### 2. Start redis in container
```
docker run --name falcon-redis -p6379:6379 -d redis:4-alpine3.8
```

## Stop and Remove containers
##### 3. Start falcon-plus modules in one container

```
## pull images from hub.docker.com/openfalcon
docker pull openfalcon/falcon-plus:v0.2.1
## run falcon-plus container
docker run -itd --name falcon-plus \
--link=falcon-mysql:db.falcon \
--link=falcon-redis:redis.falcon \
-p 8433:8433 \
-p 8080:8080 \
-e MYSQL_PORT=root:test123456@tcp\(db.falcon:3306\) \
-e REDIS_PORT=redis.falcon:6379 \
-v /home/work/open-falcon/data:/open-falcon/data \
-v /home/work/open-falcon/logs:/open-falcon/logs \
openfalcon/falcon-plus:v0.2.1
## start falcon backend modules, such as graph,api,etc.
docker exec falcon-plus sh ctrl.sh start \
graph hbs judge transfer nodata aggregator agent gateway api alarm
## or you can just start/stop/restart specific module as:
docker exec falcon-plus sh ctrl.sh start/stop/restart xxx
## check status of backend modules
docker exec falcon-plus ./open-falcon check
## or you can check logs at /home/work/open-falcon/logs/ in your host
ls -l /home/work/open-falcon/logs/
```

##### 4. Start falcon-dashboard in container
```
docker run -itd --name falcon-dashboard \
-p 8081:8081 \
--link=falcon-mysql:db.falcon \
--link=falcon-plus:api.falcon \
-e API_ADDR=http://api.falcon:8080/api/v1 \
-e PORTAL_DB_HOST=db.falcon \
-e PORTAL_DB_PORT=3306 \
-e PORTAL_DB_USER=root \
-e PORTAL_DB_PASS=test123456 \
-e PORTAL_DB_NAME=falcon_portal \
-e ALARM_DB_HOST=db.falcon \
-e ALARM_DB_PORT=3306 \
-e ALARM_DB_USER=root \
-e ALARM_DB_PASS=test123456 \
-e ALARM_DB_NAME=alarms \
-w /open-falcon/dashboard falcon-dashboard:v0.2.1 \
'./control startfg'
```

----

## Building open-falcon images from source code

##### Building falcon-plus

```
cd /tmp && \
git clone https://github.com/open-falcon/falcon-plus && \
cd /tmp/falcon-plus/ && \
docker build -t falcon-plus:v0.2.1 .
```

##### Building falcon-dashboard
```
cd /tmp && \
git clone https://github.com/open-falcon/dashboard && \
cd /tmp/dashboard/ && \
docker build -t falcon-dashboard:v0.2.1 .
```

docker-compose -f init.yml rm -f
15 changes: 0 additions & 15 deletions docker/common.yml

This file was deleted.

34 changes: 34 additions & 0 deletions docker/confgen4docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

confs=(
'%%AGENT_HTTP%%=0.0.0.0:1988'
'%%AGGREGATOR_HTTP%%=0.0.0.0:6055'
'%%GRAPH_HTTP%%=0.0.0.0:6071'
'%%GRAPH_RPC%%=0.0.0.0:6070'
'%%HBS_HTTP%%=0.0.0.0:6031'
'%%HBS_RPC%%=0.0.0.0:6030'
'%%JUDGE_HTTP%%=0.0.0.0:6081'
'%%JUDGE_RPC%%=0.0.0.0:6080'
'%%NODATA_HTTP%%=0.0.0.0:6090'
'%%TRANSFER_HTTP%%=0.0.0.0:6060'
'%%TRANSFER_RPC%%=0.0.0.0:8433'
'%%PLUS_API_DEFAULT_TOKEN%%=default-token-used-in-server-side'
'%%PLUS_API_HTTP%%=0.0.0.0:8080'
)

configurer() {
for i in "${confs[@]}"
do
search="${i%%=*}"
replace="${i##*=}"

uname=`uname`
if [ "$uname" == "Darwin" ] ; then
# Note the "" and -e after -i, needed in OS X
find ./out/*/config/*.json -type f -exec sed -i .tpl -e "s/${search}/${replace}/g" {} \;
else
find ./out/*/config/*.json -type f -exec sed -i "s/${search}/${replace}/g" {} \;
fi
done
}
configurer
18 changes: 18 additions & 0 deletions docker/ctrl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

DOCKER_DIR=/open-falcon
of_bin=$DOCKER_DIR/open-falcon
DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')

if [ -z $MYSQL_PORT ]; then
MYSQL_PORT=$DOCKER_HOST_IP:3306
fi
find $DOCKER_DIR/*/config/*.json -type f -exec sed -i "s/%%MYSQL%%/$MYSQL_PORT/g" {} \;


if [ -z $REDIS_PORT ]; then
REDIS_PORT=$DOCKER_HOST_IP:6379
fi
find $DOCKER_DIR/*/config/*.json -type f -exec sed -i "s/%%REDIS%%/$REDIS_PORT/g" {} \;

supervisorctl $*
38 changes: 0 additions & 38 deletions docker/init.yml

This file was deleted.

3 changes: 0 additions & 3 deletions docker/mysql.cnf

This file was deleted.

Loading

0 comments on commit 6870319

Please sign in to comment.