Skip to content

Commit

Permalink
[FLINK-5635] [docker] Use start-foreground in Docker entrypoint
Browse files Browse the repository at this point in the history
docker-entrypoint.sh should error on invalid args

Improve docker build.sh cleanup

Dockerfile improvements per review

Remove unnecessary Dockerfile build steps

Now that docker-entrypoint.sh uses 'start-foreground', munging
flink-daemon.sh and overwriting the log4j config are not longer
necessary.

Improve Dockerfile and docker-entrypoint.sh

Clean up Dockerfile and improve docker-entrypoint.sh to support '--help'
and pass through non-(jobmanager|taskmanager) commands.

This closes apache#3205.
This closes apache#3494.
  • Loading branch information
patricklucas authored and uce committed Mar 15, 2017
1 parent 227478b commit a3627f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 83 deletions.
24 changes: 7 additions & 17 deletions flink-contrib/docker-flink/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,20 @@ ENV FLINK_INSTALL_PATH=/opt
ENV FLINK_HOME $FLINK_INSTALL_PATH/flink
ENV PATH $PATH:$FLINK_HOME/bin

# These can be mapped from the host to the container using
# $ docker run -t flink -p 8081:8081 -p 6123:6123 jobmanager
EXPOSE 8081
EXPOSE 6123

# flink-dist can point to a directory, a tarball on the local system, or a url to a tarball
# flink-dist can point to a directory or a tarball on the local system
ARG flink_dist=NOT_SET

# Install build dependencies and flink
ADD $flink_dist $FLINK_INSTALL_PATH
RUN set -x && \
mkdir -p $FLINK_INSTALL_PATH && \
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-* && \
chown -h flink:flink $FLINK_HOME && \
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/
chown -h flink:flink $FLINK_HOME

# Overwrite default logging settings. This will additionally log to stdout so we can use 'docker logs'
ADD log4j.properties $FLINK_HOME/conf/
COPY docker-entrypoint.sh /

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sh", "-c"]
USER flink
EXPOSE 8081 6123
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["--help"]
21 changes: 15 additions & 6 deletions flink-contrib/docker-flink/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ done

IMAGE_NAME=${IMAGE_NAME:-flink}

# TMPDIR must be contained within the working directory so it is part of the
# Docker context. (i.e. it can't be mktemp'd in /tmp)
TMPDIR=_TMP_

cleanup() {
rm -rf "${TMPDIR}"
}
trap cleanup EXIT

mkdir -p "${TMPDIR}"

if [ -n "${FROM_RELEASE}" ]; then
Expand All @@ -86,14 +94,15 @@ if [ -n "${FROM_RELEASE}" ]; then

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}" .
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}"
23 changes: 10 additions & 13 deletions flink-contrib/docker-flink/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,26 @@
################################################################################

### If unspecified, the hostname of the container is taken as the JobManager address
JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-`hostname -f`}
JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-$(hostname -f)}
###

if [ "$1" == "jobmanager" ]; then
if [ "$1" == "--help" -o "$1" == "-h" ]; then
echo "Usage: $(basename $0) (jobmanager|taskmanager)"
exit 0
elif [ "$1" == "jobmanager" ]; then
echo "Starting Job Manager"
sed -i -e "s/jobmanager.rpc.address: localhost/jobmanager.rpc.address: ${JOB_MANAGER_RPC_ADDRESS}/g" $FLINK_HOME/conf/flink-conf.yaml

echo "config file: " && grep '^[^\n#]' $FLINK_HOME/conf/flink-conf.yaml
$FLINK_HOME/bin/jobmanager.sh start cluster

# prevent script to exit
tail -f /dev/null
exec $FLINK_HOME/bin/jobmanager.sh start-foreground cluster
elif [ "$1" == "taskmanager" ]; then

sed -i -e "s/jobmanager.rpc.address: localhost/jobmanager.rpc.address: ${JOB_MANAGER_RPC_ADDRESS}/g" $FLINK_HOME/conf/flink-conf.yaml
sed -i -e "s/taskmanager.numberOfTaskSlots: 1/taskmanager.numberOfTaskSlots: `grep -c ^processor /proc/cpuinfo`/g" $FLINK_HOME/conf/flink-conf.yaml
sed -i -e "s/taskmanager.numberOfTaskSlots: 1/taskmanager.numberOfTaskSlots: $(grep -c ^processor /proc/cpuinfo)/g" $FLINK_HOME/conf/flink-conf.yaml

echo "Starting Task Manager"
echo "config file: " && grep '^[^\n#]' $FLINK_HOME/conf/flink-conf.yaml
$FLINK_HOME/bin/taskmanager.sh start

# prevent script to exit
tail -f /dev/null
else
$@
exec $FLINK_HOME/bin/taskmanager.sh start-foreground
fi

exec "$@"
47 changes: 0 additions & 47 deletions flink-contrib/docker-flink/log4j.properties

This file was deleted.

0 comments on commit a3627f2

Please sign in to comment.