flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [1/2] flink git commit: [FLINK-5635] [docker] Improvements for Docker on Flink experience
Date Wed, 15 Mar 2017 13:13:37 GMT
Repository: flink
Updated Branches:
  refs/heads/master 31ab4b247 -> a3627f201


[FLINK-5635] [docker] Improvements for Docker on Flink experience

Modifying Dockerfile to build from local flink-dist as well as release URLs.
Logging to stdout.
Adding scripts to deploy seamlessly on Docker Swarm.
Updating Docker Compose scripts to work correctly.
Parameterizing things so these Docker scripts are more generally useful.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/227478bc
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/227478bc
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/227478bc

Branch: refs/heads/master
Commit: 227478bc713aa399b00a0285b86a8778dc5d8b05
Parents: 31ab4b2
Author: Jamie Grier <jamie.grier@gmail.com>
Authored: Fri Jan 20 16:12:17 2017 -0800
Committer: Ufuk Celebi <uce@apache.org>
Committed: Wed Mar 15 14:12:48 2017 +0100

----------------------------------------------------------------------
 flink-contrib/docker-flink/Dockerfile           | 24 +++---
 flink-contrib/docker-flink/build.sh             | 80 +++++++++++++++++++-
 .../docker-flink/create-docker-swarm-service.sh | 54 +++++++++++++
 flink-contrib/docker-flink/docker-compose.yml   | 15 ++--
 flink-contrib/docker-flink/log4j.properties     | 47 ++++++++++++
 .../docker-flink/remove-docker-swarm-service.sh | 43 +++++++++++
 6 files changed, 242 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/Dockerfile
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/Dockerfile b/flink-contrib/docker-flink/Dockerfile
index 133df34..943adcb 100644
--- a/flink-contrib/docker-flink/Dockerfile
+++ b/flink-contrib/docker-flink/Dockerfile
@@ -21,11 +21,6 @@ FROM java:8-jre-alpine
 # Install requirements
 RUN apk add --no-cache bash snappy
 
-# Configure Flink version
-ARG FLINK_VERSION=1.1.3
-ARG HADOOP_VERSION=27
-ARG SCALA_VERSION=2.11
-
 # Flink environment variables
 ENV FLINK_INSTALL_PATH=/opt
 ENV FLINK_HOME $FLINK_INSTALL_PATH/flink
@@ -36,22 +31,25 @@ ENV PATH $PATH:$FLINK_HOME/bin
 EXPOSE 8081
 EXPOSE 6123
 
+# flink-dist can point to a directory, a tarball on the local system, or a url to a tarball
+ARG flink_dist=NOT_SET
+
 # Install build dependencies and flink
+ADD $flink_dist $FLINK_INSTALL_PATH
 RUN set -x && \
   mkdir -p $FLINK_INSTALL_PATH && \
-  apk --update add --virtual build-dependencies curl && \
-  curl -s $(curl -s https://www.apache.org/dyn/closer.cgi\?preferred\=true)flink/flink-${FLINK_VERSION}/flink-${FLINK_VERSION}-bin-hadoop${HADOOP_VERSION}-scala_${SCALA_VERSION}.tgz
| \
-  tar xvz -C $FLINK_INSTALL_PATH && \
-  ln -s $FLINK_INSTALL_PATH/flink-$FLINK_VERSION $FLINK_HOME && \
+  ln -s $FLINK_INSTALL_PATH/flink-* $FLINK_HOME && \
   addgroup -S flink && adduser -D -S -H -G flink -h $FLINK_HOME flink &&
\
-  chown -R flink:flink $FLINK_INSTALL_PATH/flink-$FLINK_VERSION && \
+  chown -R flink:flink $FLINK_INSTALL_PATH/flink-* && \
   chown -h flink:flink $FLINK_HOME && \
-  sed -i -e "s/echo \$mypid >> \$pid/echo \$mypid >> \$pid \&\& wait/g"
$FLINK_HOME/bin/flink-daemon.sh && \
-  apk del build-dependencies && \
-  rm -rf /var/cache/apk/*
+  sed -i -e "s/echo \$mypid >> \$pid/echo \$mypid >> \$pid \&\& wait/g"
$FLINK_HOME/bin/flink-daemon.sh
 
 # Configure container
 USER flink
 ADD docker-entrypoint.sh $FLINK_HOME/bin/
+
+# Overwrite default logging settings.  This will additionally log to stdout so we can use
'docker logs'
+ADD log4j.properties $FLINK_HOME/conf/
+
 ENTRYPOINT ["docker-entrypoint.sh"]
 CMD ["sh", "-c"]

http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/build.sh
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/build.sh b/flink-contrib/docker-flink/build.sh
index 92a61ad..c1003ad 100755
--- a/flink-contrib/docker-flink/build.sh
+++ b/flink-contrib/docker-flink/build.sh
@@ -18,4 +18,82 @@
 # limitations under the License.
 ################################################################################
 
-docker build -t "flink" .
+usage() {
+  cat <<HERE
+Usage:
+  build.sh --from-local-dist [--image-name <image>]
+  build.sh --from-release --flink-version <x.x.x> --hadoop-version <x.x> --scala-version
<x.xx> [--image-name <image>]
+  build.sh --help
+
+  If the --image-name flag is not used the built image name will be 'flink'.
+HERE
+  exit 1
+}
+
+while [[ $# -ge 1 ]]
+do
+key="$1"
+  case $key in
+    --from-local-dist)
+    FROM_LOCAL="true"
+    ;;
+    --from-release)
+    FROM_RELEASE="true"
+    ;;
+    --image-name)
+    IMAGE_NAME="$2"
+    shift
+    ;;
+    --flink-version)
+    FLINK_VERSION="$2"
+    shift
+    ;;
+    --hadoop-version)
+    HADOOP_VERSION="$(echo "$2" | sed 's/\.//')"
+    shift
+    ;;
+    --scala-version)
+    SCALA_VERSION="$2"
+    shift
+    ;;
+    --help)
+    usage
+    ;;
+    *)
+    # unknown option
+    ;;
+  esac
+  shift
+done
+
+IMAGE_NAME=${IMAGE_NAME:-flink}
+
+TMPDIR=_TMP_
+mkdir -p "${TMPDIR}"
+
+if [ -n "${FROM_RELEASE}" ]; then
+
+  [[ -n "${FLINK_VERSION}" ]] && [[ -n "${HADOOP_VERSION}" ]] && [[ -n "${SCALA_VERSION}"
]] || usage
+
+  FLINK_BASE_URL="$(curl -s https://www.apache.org/dyn/closer.cgi\?preferred\=true)flink/flink-${FLINK_VERSION}/"
+  FLINK_DIST_FILE_NAME="flink-${FLINK_VERSION}-bin-hadoop${HADOOP_VERSION}-scala_${SCALA_VERSION}.tgz"
+  CURL_OUTPUT="${TMPDIR}/${FLINK_DIST_FILE_NAME}"
+
+  echo "Downloading ${FLINK_DIST_FILE_NAME} from ${FLINK_BASE_URL}"
+  curl -s ${FLINK_BASE_URL}${FLINK_DIST_FILE_NAME} --output ${CURL_OUTPUT}
+
+  FLINK_DIST="${CURL_OUTPUT}"
+
+elif [ -n "${FROM_LOCAL}" ]; then
+
+    DIST_DIR="../../flink-dist/target/flink-*-bin"
+    FLINK_DIST="${TMPDIR}/flink.tgz"
+    echo "Using flink dist: ${DIST_DIR}"
+    tar -C ${DIST_DIR} -cvzf "${FLINK_DIST}" .
+else
+  usage
+fi
+
+docker build --build-arg flink_dist="${FLINK_DIST}" -t "${IMAGE_NAME}" .
+
+rm -rf "${TMPDIR}"

http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/create-docker-swarm-service.sh
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/create-docker-swarm-service.sh b/flink-contrib/docker-flink/create-docker-swarm-service.sh
new file mode 100755
index 0000000..4393a70
--- /dev/null
+++ b/flink-contrib/docker-flink/create-docker-swarm-service.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+################################################################################
+#  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.
+################################################################################
+
+usage() {
+  cat <<HERE
+Usage:
+  create-docker-swarm-service.sh [--image-name <image>] <service-name> <service-port>
+
+  If the --image-name flag is not used the service will use the 'flink' image.
+HERE
+  exit 1
+}
+
+if [ "$1" == "--image-name" ]; then
+  IMAGE_NAME="$2"
+  shift; shift
+else
+  IMAGE_NAME=flink
+fi
+
+[[ $# -ne 2 ]] && usage
+
+SERVICE_BASE_NAME="$1"
+SERVICE_PORT="${2}"
+JOB_MANAGER_NAME=${SERVICE_BASE_NAME}-jobmanager
+TASK_MANAGER_NAME=${SERVICE_BASE_NAME}-taskmanager
+JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_NAME}
+OVERLAY_NETWORK_NAME=${SERVICE_BASE_NAME}
+
+# Create overlay network
+docker network create -d overlay ${OVERLAY_NETWORK_NAME}
+
+# Create the jobmanager service
+docker service create --name ${JOB_MANAGER_NAME} --env JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS}
-p ${SERVICE_PORT}:8081 --network ${OVERLAY_NETWORK_NAME} ${IMAGE_NAME} jobmanager
+
+# Create the taskmanger service (scale this out as needed)
+docker service create --name ${TASK_MANAGER_NAME} --env JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS}
--network ${OVERLAY_NETWORK_NAME} ${IMAGE_NAME} taskmanager

http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/docker-compose.yml
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/docker-compose.yml b/flink-contrib/docker-flink/docker-compose.yml
index 6a13353..702d318 100644
--- a/flink-contrib/docker-flink/docker-compose.yml
+++ b/flink-contrib/docker-flink/docker-compose.yml
@@ -16,21 +16,22 @@
 # limitations under the License.
 ################################################################################
 
-version: "2"
+# Set the FLINK_DOCKER_IMAGE_NAME environment variable to override the image name to use
+
+version: "2.1"
 services:
   jobmanager:
-    image: flink
-    container_name: "jobmanager"
+    image: ${FLINK_DOCKER_IMAGE_NAME:-flink}
     expose:
       - "6123"
     ports:
-      - "48081:8081"
+      - "8081:8081"
     command: jobmanager
     environment:
-      - JOB_MANAGER_RPC_ADDRESS="jobmanager"
+      - JOB_MANAGER_RPC_ADDRESS=jobmanager
 
   taskmanager:
-    image: flink
+    image: ${FLINK_DOCKER_IMAGE_NAME:-flink}
     expose:
       - "6121"
       - "6122"
@@ -40,4 +41,4 @@ services:
     links:
       - "jobmanager:jobmanager"
     environment:
-      - JOB_MANAGER_RPC_ADDRESS="jobmanager"
+      - JOB_MANAGER_RPC_ADDRESS=jobmanager

http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/log4j.properties
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/log4j.properties b/flink-contrib/docker-flink/log4j.properties
new file mode 100644
index 0000000..2bd1210
--- /dev/null
+++ b/flink-contrib/docker-flink/log4j.properties
@@ -0,0 +1,47 @@
+################################################################################
+#  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.
+################################################################################
+
+# This affects logging for both user code and Flink
+log4j.rootLogger=INFO, file, console
+
+# Uncomment this if you want to _only_ change Flink's logging
+#log4j.logger.org.apache.flink=INFO
+
+# The following lines keep the log level of common libraries/connectors on
+# log level INFO. The root logger does not override this. You have to manually
+# change the log levels here.
+log4j.logger.akka=INFO
+log4j.logger.org.apache.kafka=INFO
+log4j.logger.org.apache.hadoop=INFO
+log4j.logger.org.apache.zookeeper=INFO
+
+# Log all infos in the given file
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.file=${log.file}
+log4j.appender.file.append=false
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x -
%m%n
+
+# Log to stdout as well
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.err
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x
- %m%n
+
+# Suppress the irrelevant (wrong) warnings from the Netty channel handler
+log4j.logger.org.jboss.netty.channel.DefaultChannelPipeline=ERROR, file, console

http://git-wip-us.apache.org/repos/asf/flink/blob/227478bc/flink-contrib/docker-flink/remove-docker-swarm-service.sh
----------------------------------------------------------------------
diff --git a/flink-contrib/docker-flink/remove-docker-swarm-service.sh b/flink-contrib/docker-flink/remove-docker-swarm-service.sh
new file mode 100755
index 0000000..7cdc1c7
--- /dev/null
+++ b/flink-contrib/docker-flink/remove-docker-swarm-service.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+################################################################################
+#  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.
+################################################################################
+
+usage() {
+  cat <<HERE
+Usage:
+  remove-docker-swarm-service.sh <service-name> 
+HERE
+  exit 1
+}
+
+[[ $# -ne 1 ]] && usage
+
+SERVICE_BASE_NAME="$1"
+JOB_MANAGER_NAME=${SERVICE_BASE_NAME}-jobmanager
+TASK_MANAGER_NAME=${SERVICE_BASE_NAME}-taskmanager
+OVERLAY_NETWORK_NAME=${SERVICE_BASE_NAME}
+
+# Remove taskmanager service
+docker service rm ${TASK_MANAGER_NAME}
+
+# Remove jobmanager service
+docker service rm ${JOB_MANAGER_NAME}
+
+# Remove overlay network
+docker network rm ${OVERLAY_NETWORK_NAME}


Mime
View raw message