From 7b4d1f029b3e6907e8ea27573c9b8f6243d4f466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Draszik?= Date: Mon, 23 Jul 2018 09:54:17 +0100 Subject: [PATCH] mvn-entrypoint: substantial speed-up Copying a reference tree with ca. 7600 files and ~410MiB currently takes about 47 (!) seconds and thusly delays container creation substantially. Rewrite the copying script to address this: 1) by being less verbose in the log file and doing fewer parameter expansions, we shave off about 1 second 2) using cp's --reflink=auto we bring this down to about 42 seconds, in addition to decreasing disk space used (where the underlying file system supports this) 3) using find's -exec {} + syntax, rather than -exec {} ; we're now at 32 seconds 4) using sh instead of bash, time goes down to about 22 seconds 5) as a final optimisation, if the target directory is empty, we can just copy everything in one go, bringing the time down to under 2 seconds. All of the above numbers are for the debian-slim version, using alpine linux, step 4) takes about 15 seconds and the time taken in step 5) doesn't change, as alpine's busybox cp doesn't support --reflink=auto at the moment. --- ibmjava-8-alpine/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ ibmjava-8/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-10-slim/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-10/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-11-slim/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-11/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-7-alpine/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-7-slim/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-7/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-8-alpine/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-8-slim/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-8/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-9-slim/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ jdk-9/mvn-entrypoint.sh | 55 ++++++++++++++++++------------ 14 files changed, 462 insertions(+), 308 deletions(-) diff --git a/ibmjava-8-alpine/mvn-entrypoint.sh b/ibmjava-8-alpine/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/ibmjava-8-alpine/mvn-entrypoint.sh +++ b/ibmjava-8-alpine/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/ibmjava-8/mvn-entrypoint.sh b/ibmjava-8/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/ibmjava-8/mvn-entrypoint.sh +++ b/ibmjava-8/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-10-slim/mvn-entrypoint.sh b/jdk-10-slim/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-10-slim/mvn-entrypoint.sh +++ b/jdk-10-slim/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-10/mvn-entrypoint.sh b/jdk-10/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-10/mvn-entrypoint.sh +++ b/jdk-10/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-11-slim/mvn-entrypoint.sh b/jdk-11-slim/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-11-slim/mvn-entrypoint.sh +++ b/jdk-11-slim/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-11/mvn-entrypoint.sh b/jdk-11/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-11/mvn-entrypoint.sh +++ b/jdk-11/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-7-alpine/mvn-entrypoint.sh b/jdk-7-alpine/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-7-alpine/mvn-entrypoint.sh +++ b/jdk-7-alpine/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-7-slim/mvn-entrypoint.sh b/jdk-7-slim/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-7-slim/mvn-entrypoint.sh +++ b/jdk-7-slim/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-7/mvn-entrypoint.sh b/jdk-7/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-7/mvn-entrypoint.sh +++ b/jdk-7/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-8-alpine/mvn-entrypoint.sh b/jdk-8-alpine/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-8-alpine/mvn-entrypoint.sh +++ b/jdk-8-alpine/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-8-slim/mvn-entrypoint.sh b/jdk-8-slim/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-8-slim/mvn-entrypoint.sh +++ b/jdk-8-slim/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-8/mvn-entrypoint.sh b/jdk-8/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-8/mvn-entrypoint.sh +++ b/jdk-8/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-9-slim/mvn-entrypoint.sh b/jdk-9-slim/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-9-slim/mvn-entrypoint.sh +++ b/jdk-9-slim/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@" diff --git a/jdk-9/mvn-entrypoint.sh b/jdk-9/mvn-entrypoint.sh index b20bda41..9f87dfa2 100755 --- a/jdk-9/mvn-entrypoint.sh +++ b/jdk-9/mvn-entrypoint.sh @@ -1,39 +1,50 @@ -#! /bin/bash -eu - -set -o pipefail +#! /bin/sh -eu # Copy files from /usr/share/maven/ref into ${MAVEN_CONFIG} # So the initial ~/.m2 is set with expected content. # Don't override, as this is just a reference setup -copy_reference_file() { - local root="${1}" - local f="${2%/}" - local logfile="${3}" - local rel="${f/${root}/}" # path relative to /usr/share/maven/ref/ - echo "$f" >> "$logfile" - echo " $f -> $rel" >> "$logfile" - if [[ ! -e ${MAVEN_CONFIG}/${rel} || $f = *.override ]] - then - echo "copy $rel to ${MAVEN_CONFIG}" >> "$logfile" - mkdir -p "${MAVEN_CONFIG}/$(dirname "${rel}")" - cp -r "${f}" "${MAVEN_CONFIG}/${rel}"; - fi; -} copy_reference_files() { local log="$MAVEN_CONFIG/copy_reference_file.log" + local ref="/usr/share/maven/ref" - if (sh -c "mkdir -p \"$MAVEN_CONFIG\" && touch \"${log}\"" > /dev/null 2>&1) - then - echo "--- Copying files at $(date)" >> "$log" - find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \; + if mkdir -p "${MAVEN_CONFIG}/repository" && touch "${log}" > /dev/null 2>&1 ; then + cd "${ref}" + local reflink="" + if cp --help 2>&1 | grep -q reflink ; then + reflink="--reflink=auto" + fi + if [ -n "$(find "${MAVEN_CONFIG}/repository" -maxdepth 0 -type d -empty 2>/dev/null)" ] ; then + # destination is empty... + echo "--- Copying all files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + cp -rv ${reflink} . "${MAVEN_CONFIG}" >> "${log}" + else + # destination is non-empty, copy file-by-file + echo "--- Copying individual files to ${MAVEN_CONFIG} at $(date)" >> "${log}" + find . -type f -exec sh -eu -c ' + log="${1}" + shift + reflink="${1}" + shift + for f in "$@" ; do + if [ ! -e "${MAVEN_CONFIG}/${f}" ] || [ -e "${f}.override" ] ; then + mkdir -p "${MAVEN_CONFIG}/$(dirname "${f}")" + cp -rv ${reflink} "${f}" "${MAVEN_CONFIG}/${f}" >> "${log}" + fi + done + ' _ "${log}" "${reflink}" {} + + fi + echo >> "${log}" else echo "Can not write to ${log}. Wrong volume permissions? Carrying on ..." fi } -export -f copy_reference_file +owd="$(pwd)" copy_reference_files unset MAVEN_CONFIG +cd "${owd}" +unset owd + exec "$@"