diff --git a/bin/chunjun-docker.sh b/bin/chunjun-docker.sh new file mode 100644 index 0000000000..b30d410853 --- /dev/null +++ b/bin/chunjun-docker.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +export CHUNJUN_HOME="$(cd "`dirname "$0"`"/..; pwd)" +echo "CHUNJUN_HOME is $CHUNJUN_HOME" + +# exit if CHUNJUN_HOME is not set or not a directory +if [ -z $CHUNJUN_HOME ] || [ ! -d $CHUNJUN_HOME ];then + echo "failed to build docker image because CHUNJUN_HOME is not set" + exit 1 +fi +cd $CHUNJUN_HOME/docker-build +echo "start building a docker image named chunjun-master" +tar -czvf chunjun-dist.tar.gz -C $CHUNJUN_HOME . +docker build -t chunjun-master . diff --git a/chunjun-docker/docker-build/Dockerfile b/chunjun-docker/docker-build/Dockerfile new file mode 100644 index 0000000000..056a29ddaf --- /dev/null +++ b/chunjun-docker/docker-build/Dockerfile @@ -0,0 +1,6 @@ +FROM apache/flink:1.12.7-scala_2.12-java8 +COPY chunjun-dist.tar.gz /opt/flink/lib/ +RUN mkdir /opt/flink/lib/chunjun-dist | tar -zxvf /opt/flink/lib/chunjun-dist.tar.gz -C /opt/flink/lib/chunjun-dist +ENV CHUNJUN_HOME /opt/flink/lib/chunjun-dist +COPY docker-entrypoint.sh / +RUN chmod 777 /docker-entrypoint.sh diff --git a/chunjun-docker/docker-build/docker-entrypoint.sh b/chunjun-docker/docker-build/docker-entrypoint.sh new file mode 100644 index 0000000000..91e7653aa3 --- /dev/null +++ b/chunjun-docker/docker-build/docker-entrypoint.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +FILE="/opt/flink/lib/chunjun-dist/chunjun-examples/json/stream/stream.json" +JOBTYPE="sync" +MODE="standalone" +files=$(ls /opt/flink/job) +for file in $files; do + FILE="/opt/flink/job/$file" + echo "$FILE" + if [[ $FILE == *.sql ]]; + then JOBTYPE="sql" + fi +done + +while getopts ":m:" opt +do + case $opt in + m) + MODE=$OPTARG;; + ?) + echo "getopts param error" + esac +done + +echo "mode is $MODE" +echo "job file is $FILE" +echo "job type is $JOBTYPE" +if [[ $MODE == standalone ]] + then bash /opt/flink/bin/start-cluster.sh +fi + +/opt/flink/lib/chunjun-dist/bin/start-chunjun -mode $MODE -jobType $JOBTYPE -chunjunDistDir /opt/flink/lib/chunjun-dist -job $FILE -flinkConfDir $FLINK_HOME/conf +if [[ $MODE == local ]]; + then exit +fi +while true; do + echo "default web monitor URL is localhost:8081, using the real port if you defined in standalone mode." + sleep 90 +done + diff --git a/chunjun-docker/pom.xml b/chunjun-docker/pom.xml index af63f328e5..03d2e99c9f 100644 --- a/chunjun-docker/pom.xml +++ b/chunjun-docker/pom.xml @@ -12,5 +12,32 @@ chunjun-docker ChunJun : Docker + + + + maven-antrun-plugin + + + copy-resources + + package + + run + + + + + + + + + + + + + + + + diff --git "a/docs_zh/\345\277\253\351\200\237\345\274\200\345\247\213.md" "b/docs_zh/\345\277\253\351\200\237\345\274\200\345\247\213.md" index fc939a1239..d89dfa3872 100644 --- "a/docs_zh/\345\277\253\351\200\237\345\274\200\345\247\213.md" +++ "b/docs_zh/\345\277\253\351\200\237\345\274\200\345\247\213.md" @@ -203,3 +203,26 @@ sh ./bin/chunjun-yarn-perjob.sh -job chunjun-examples/json/stream/stream.json [参考视频](https://www.bilibili.com/video/BV1oU4y1D7e7?spm_id_from=333.999.0.0) + +# docker 构建 +执行如下命令,执行完成后在本地生成一个名为 chunjun-master的镜像(注意:需要预先完成maven打包) +```shell +sh ./bin/chunjun-docker.sh +``` +预先提供了一个公共镜像 dtopensource/chunjun-master +## 如何使用 +### 直接启动 +默认使用chunjun-examples/json/stream/stream.json这个任务,standalone模式 +docker run -p 8081:8081 dtopensource/chunjun-master +### 指定文件 +假设在你机器上的文件是/chunjun/chunjun-examples/json/stream/stream.json,docker内挂载的目录必须是/opt/flink/job +任务类型根据文件名自动推断:例如stream.json是sync任务,stream.sql是sql任务 +docker run -p 8081:8081 -v /chunjun/chunjun-examples/json/stream/stream.json:/opt/flink/job/stream.json dtopensource/chunjun-master +### 指定模式 +通过-m参数指定模式,可选项local、standalone,默认为standalone模式 +在standalone模式下,可以通过web查看任务,默认地址是localhost:8081,注意此时docker 容器不会主动退出,另开终端通过docker stop 退出。 +docker run -p 8081:8081 dtopensource/chunjun-master -m local +### 其他说明 +如果数据源中有外部机器,需要传入host信息 +docker run -p 8081:8081 --add-host=www.test.com:192.168.100.100 dtopensource/chunjun-master +