-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Changes from 2 commits
6de827f
73767fc
8589d47
65b5941
656628f
b3370da
a19d856
fb9fe1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,161 @@ | ||||||
#!/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. | ||||||
############################################################################### | ||||||
|
||||||
zentol marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
COMMAND_STANDALONE="standalone-job" | ||||||
# Deprecated, should be remove in Flink release 1.13 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is against master, which will eventually become release 1.13? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the master branch, the native K8s will not need the
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[@]}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[@]}" |
There was a problem hiding this comment.
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 pollutebin/
? (This is really just a thought for discussion)There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.