Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-20915][docker] Move docker entrypoint to distribution #14630

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions flink-dist/src/main/flink-bin/bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script shows up in build-target/bin. If we keep it there, we need to add a message that it shall not be used manually.

Maybe, it makes sense to move the script to opt/docker/docker-entrypoint.sh to not further pollute bin/? (This is really just a thought for discussion)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a lot of stuff in bin/ at this point that users should never use directly (bash-java-utils, config.sh, flink-console.sh, flink-daemon.sh, find-flink-home.sh), that I'm not too concerned about adding one more.
I see the point of trying to hide it, but this whole "put-into-opt-but-load-it-automatically-in-some-scenarios" business that the table-api introduced is rubbing me the wrong way.
The overall semantics for bin/opt seem rather ill-defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. We should clean up the bin directory in a separate effort.


###############################################################################
# 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.
###############################################################################

zentol marked this conversation as resolved.
Show resolved Hide resolved
COMMAND_STANDALONE="standalone-job"
# Deprecated, should be remove in Flink release 1.13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Deprecated, should be remove in Flink release 1.13
# Deprecated, should be removed in Flink release 1.13

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is against master, which will eventually become release 1.13?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only moving the script, any logic/API changes should be relegated to follow-ups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the master branch, the native K8s will not need the native-k8s command anymore. It will generate the command and arguments as followings.

  - args:
    - bash
    - -c
    - $JAVA_HOME/bin/java -classpath $FLINK_CLASSPATH -Xmx1073741824 -Xms1073741824
      -XX:MaxMetaspaceSize=268435456 -Dlog.file=/opt/flink/log/jobmanager.log -Dlogback.configurationFile=file:/opt/flink/conf/logback-console.xml
      -Dlog4j.configuration=file:/opt/flink/conf/log4j2.xml -Dlog4j.configurationFile=file:/opt/flink/conf/log4j2.xml
      org.apache.flink.kubernetes.entrypoint.KubernetesApplicationClusterEntrypoint
      ...
    command:
    - /docker-entrypoint.sh

We already have a ticket FLINK-20676 to track this.

COMMAND_NATIVE_KUBERNETES="native-k8s"
COMMAND_HISTORY_SERVER="history-server"
COMMAND_DISABLE_JEMALLOC="disable-jemalloc"

args=("$@")
echo "${args[@]}"
Copy link
Contributor

@wangyang0918 wangyang0918 Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not print any text in the pass-through mode. Otherwise, the PR for docker-library/official-images will fail since CI will run the this test[1].

[1]. https://github.com/docker-library/official-images/blob/master/test/tests/override-cmd/run.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, this was for debugging.


bin=`dirname "$0"`
bin=`cd "$bin"; pwd`

# FLINK_HOME is set by the docker image
zentol marked this conversation as resolved.
Show resolved Hide resolved
export _FLINK_HOME_DETERMINED=true
. ${FLINK_HOME}/bin/config.sh

# If unspecified, the hostname of the container is taken as the JobManager address
JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-$(hostname -f)}
CONF_FILE="${FLINK_CONF_DIR}/flink-conf.yaml"

copy_plugins_if_required() {
if [ -z "$ENABLE_BUILT_IN_PLUGINS" ]; then
return 0
fi

echo "Enabling required built-in plugins"
for target_plugin in $(echo "$ENABLE_BUILT_IN_PLUGINS" | tr ';' ' '); do
echo "Linking ${target_plugin} to plugin directory"
plugin_name=${target_plugin%.jar}

mkdir -p "${FLINK_PLUGINS_DIR}/${plugin_name}"
if [ ! -e "${FLINK_OPT_DIR}/${target_plugin}" ]; then
echo "Plugin ${target_plugin} does not exist. Exiting."
exit 1
else
ln -fs "${FLINK_OPT_DIR}/${target_plugin}" "${FLINK_HOME}/plugins/${plugin_name}"
echo "Successfully enabled ${target_plugin}"
fi
done
}

set_config_option() {
local option=$1
local value=$2

# escape periods for usage in regular expressions
local escaped_option=$(echo ${option} | sed -e "s/\./\\\./g")

# either override an existing entry, or append a new one
if grep -E "^${escaped_option}:.*" "${CONF_FILE}" > /dev/null; then
sed -i -e "s/${escaped_option}:.*/$option: $value/g" "${CONF_FILE}"
else
echo "${option}: ${value}" >> "${CONF_FILE}"
fi
}

set_common_options() {
set_config_option jobmanager.rpc.address ${JOB_MANAGER_RPC_ADDRESS}
set_config_option blob.server.port 6124
set_config_option query.server.port 6125
}

prepare_job_manager_start() {
echo "Starting Job Manager"
copy_plugins_if_required

set_common_options

if [ -n "${FLINK_PROPERTIES}" ]; then
echo "${FLINK_PROPERTIES}" >> "${CONF_FILE}"
fi
envsubst < "${CONF_FILE}" > "${CONF_FILE}.tmp" && mv "${CONF_FILE}.tmp" "${CONF_FILE}"
}

echo "${args[@]}"

if [ "$1" = "help" ]; then
printf "Usage: $(basename "$0") (jobmanager|${COMMAND_STANDALONE}|taskmanager|${COMMAND_HISTORY_SERVER}) [${COMMAND_DISABLE_JEMALLOC}]\n"
printf " Or $(basename "$0") help\n\n"
printf "By default, Flink image adopts jemalloc as default memory allocator and will disable jemalloc if option '${COMMAND_DISABLE_JEMALLOC}' given.\n"
exit 0
elif [ "$1" = "jobmanager" ]; then
args=("${args[@]:1}")

prepare_job_manager_start

exec "${FLINK_BIN_DIR}/jobmanager.sh" start-foreground "${args[@]}"
elif [ "$1" = ${COMMAND_STANDALONE} ]; then
args=("${args[@]:1}")

prepare_job_manager_start

exec "${FLINK_BIN_DIR}/standalone-job.sh" start-foreground "${args[@]}"
elif [ "$1" = ${COMMAND_HISTORY_SERVER} ]; then
args=("${args[@]:1}")

echo "Starting History Server"
copy_plugins_if_required

if [ -n "${FLINK_PROPERTIES}" ]; then
echo "${FLINK_PROPERTIES}" >> "${CONF_FILE}"
fi
envsubst < "${CONF_FILE}" > "${CONF_FILE}.tmp" && mv "${CONF_FILE}.tmp" "${CONF_FILE}"

exec "${FLINK_BIN_DIR}/historyserver.sh" start-foreground "${args[@]}"
elif [ "$1" = "taskmanager" ]; then
args=("${args[@]:1}")

echo "Starting Task Manager"
copy_plugins_if_required

TASK_MANAGER_NUMBER_OF_TASK_SLOTS=${TASK_MANAGER_NUMBER_OF_TASK_SLOTS:-$(grep -c ^processor /proc/cpuinfo)}

set_common_options
set_config_option taskmanager.numberOfTaskSlots ${TASK_MANAGER_NUMBER_OF_TASK_SLOTS}

if [ -n "${FLINK_PROPERTIES}" ]; then
echo "${FLINK_PROPERTIES}" >> "${CONF_FILE}"
fi
envsubst < "${CONF_FILE}" > "${CONF_FILE}.tmp" && mv "${CONF_FILE}.tmp" "${CONF_FILE}"

exec "${FLINK_BIN_DIR}/taskmanager.sh" start-foreground "${args[@]}"
elif [ "$1" = "$COMMAND_NATIVE_KUBERNETES" ]; then
args=("${args[@]:1}")

copy_plugins_if_required

# Override classpath since it was assembled manually
export FLINK_CLASSPATH="`constructFlinkClassPath`:${INTERNAL_HADOOP_CLASSPATHS}"
# Start commands for jobmanager and taskmanager are generated by Flink internally.
echo "Start command: ${args[@]}"
exec bash -c "${args[@]}"
fi

copy_plugins_if_required

# Override classpath since it was assembled manually
export FLINK_CLASSPATH="`constructFlinkClassPath`:${INTERNAL_HADOOP_CLASSPATHS}"

# Running command in pass-through mode
exec "${args[@]}"
2 changes: 1 addition & 1 deletion flink-end-to-end-tests/test-scripts/common_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function build_image() {
local server_pid=$!

echo "Preparing Dockeriles"
zentol marked this conversation as resolved.
Show resolved Hide resolved
git clone https://github.com/apache/flink-docker.git --branch dev-master --single-branch
git clone https://github.com/zentol/flink-docker.git --branch 20915 --single-branch
cd flink-docker
./add-custom.sh -u ${file_server_address}:9999/flink.tgz -n ${image_name}

Expand Down