From 59cd65f77e88ca0773a83d93ea999bc5bde62915 Mon Sep 17 00:00:00 2001 From: 姜鹏辉 Date: Thu, 15 Jul 2021 14:30:51 +0800 Subject: 新增docker运行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- Dockerfile | 12 ++++++++++++ README.md | 1 - docker-compose.yml | 8 ++++++++ install.sh | 44 ++++++++++++++++++++++++++++++-------------- requirements.txt | 2 ++ run.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++---- src/run.py | 4 ++-- 8 files changed, 101 insertions(+), 22 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index c94ed69..3af7e9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.log *.tgz -__pycache__ \ No newline at end of file +__pycache__ +*.tar \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..406d25c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3 + +WORKDIR /usr/src/app + +COPY . . +RUN pip install --no-cache-dir -r requirements.txt + + +#ENTRYPOINT ["python"] +ENTRYPOINT ["tail","-f","/dev/null"] +CMD ["python3"] + diff --git a/README.md b/README.md index e2a5769..8f09a69 100644 --- a/README.md +++ b/README.md @@ -49,5 +49,4 @@ pip install ./whl/requests_toolbelt-0.9.1-py2.py3-none-any.whl ## Todo -- csv文件下载失败 - 结果的行数统计 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..689814d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + poc: + container_name: poc + image: poc_jph:latest + volumes: + - "./:/usr/src/app" + \ No newline at end of file diff --git a/install.sh b/install.sh index 0b6c668..9ad0ae7 100644 --- a/install.sh +++ b/install.sh @@ -1,14 +1,30 @@ -pip install ./whl/clickhouse_driver-0.1.2-cp27-cp27mu-manylinux1_x86_64.whl >> ./log/install.log 2>&1 -if [ "$?" == 0 ] -then - echo "install clickhouse_driver success" -else - echo "install clickhouse_driver error" -fi -pip install ./whl/requests_toolbelt-0.9.1-py2.py3-none-any.whl >> ./log/install.log 2>&1 -if [ "$?" == 0 ] -then - echo "install requests_toolbelt success" -else - echo "install requests_toolbelt error" -fi \ No newline at end of file + +pip_install(){ + pip install ./whl/clickhouse_driver-0.1.2-cp27-cp27mu-manylinux1_x86_64.whl >> ./log/install.log 2>&1 + if [ "$?" == 0 ] + then + echo "install clickhouse_driver success" + else + echo "install clickhouse_driver error" + fi + pip install ./whl/requests_toolbelt-0.9.1-py2.py3-none-any.whl >> ./log/install.log 2>&1 + if [ "$?" == 0 ] + then + echo "install requests_toolbelt success" + else + echo "install requests_toolbelt error" + fi +} +docker_install(){ + #docker import poc.tar poc_jph:latest + docker load < poc.tar + if [ "$?" == 0 ] + then + echo "install success" + else + echo "install error" + fi + #docker run -d -v $(pwd):/usr/src/app --name poc poc_jph:latest +} + +docker_install \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fe3a961 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +clickhouse_driver +requests_toolbelt \ No newline at end of file diff --git a/run.sh b/run.sh index 4cad55b..3b5963f 100644 --- a/run.sh +++ b/run.sh @@ -2,7 +2,7 @@ #!/bin/bash systeminfologfile="./log/systeminfo.log" runtimelogfile="./log/runtime.log" - +#alias python="docker run -it --rm poc_jph python" collect_info(){ echo co echo "--------" >> $systeminfologfile @@ -20,6 +20,7 @@ collect_info(){ } collect_use_info(){ + echo 1 > /proc/sys/vm/drop_caches echo "--------" >> $runtimelogfile echo "MEM USE" >> $runtimelogfile echo "--------" >> $runtimelogfile @@ -31,19 +32,34 @@ collect_use_info(){ } ch_test(){ - echo 1 > /proc/sys/vm/drop_caches collect_use_info echo "running ClickHouse test" python ./src/run.py ch $(pwd) } ol_test(){ - echo 1 > /proc/sys/vm/drop_caches collect_use_info echo "running OpenLookeng test" python ./src/run.py ol $(pwd) } +ch_test_docker(){ + collect_use_info + echo "running ClickHouse test" + docker exec -it poc python ./src/run.py ch /usr/src/app/ + echo 1 + #docker run --rm -v $(pwd):/usr/src/app --name poc poc_jph:latest python ./src/run.py ch /usr/src/app/ + +} + +ol_test_docker(){ + collect_use_info + echo "running OpenLookeng test" + docker exec -it poc python ./src/run.py ol /usr/src/app/ + echo 1 + #docker run --rm -v $(pwd):/usr/src/app --name poc poc_jph:latest ./src/run.py ol /usr/src/app/ +} + clear_log() { rm -rf ./log/* rm -rf ./src/__pycache__ @@ -61,4 +77,29 @@ start() { tar -zcvf log.tgz ./log } -start \ No newline at end of file +docker_start() { + docker-compose up -d + clear_log + collect_info + for i in {1,2,3} + do + ch_test_docker + ol_test_docker + done + tar -zcvf log.tgz ./log + docker-compose down + echo "finish poc test" +} + +docker_export() { + docker save -o ./poc.tar poc_jph:latest +} + +temp_test() { + docker-compose up -d + docker exec -it poc python ./src/run.py ch /usr/src/app/ + docker exec -it poc python ./src/run.py ol /usr/src/app/ + docker-compose down +} +#temp_test +docker_start \ No newline at end of file diff --git a/src/run.py b/src/run.py index ceafb0e..180af09 100644 --- a/src/run.py +++ b/src/run.py @@ -140,8 +140,8 @@ def read_conf(): sql_timeout = config.get("run","time_out") # default 900s 15min - ch_sector = "clickhouse" - ol_sector = "openlookeng" + ch_sector = "clickhouse-local" + ol_sector = "openlookeng-local" chconfig['host'] = config.get(ch_sector,"host") chconfig['port'] = str(config.get(ch_sector,"port")) -- cgit v1.2.3