Browse Source

new: timezone is fixed for containers

We prefer to create a file with the ``/etc/timezone`` information
in our own file directory to be shared read-only with containers.

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
test1
Valentin Lab 5 years ago
parent
commit
ade2d7b1d9
  1. 129
      bin/compose

129
bin/compose

@ -259,15 +259,26 @@ relink_subdirs() {
mk_docker_run_options() {
docker_run_opts=("-v" "/var/run/docker.sock:/var/run/docker.sock")
## Order matters, files get to override vars
compose_config_files=(
## DEFAULT LINUX VARS
/etc/default/charm
/etc/default/datastore
/etc/default/compose
## CACHE/DATA DIRS
docker_run_opts+=("-v" "$COMPOSE_VAR:/var/lib/compose")
docker_run_opts+=("-v" "$COMPOSE_CACHE:/var/cache/compose")
## COMPOSE SYSTEM-WIDE FILES
/etc/compose.conf
/etc/compose.local.conf
/etc/compose/local.conf
docker_run_opts+=("-v" "$TZ_PATH:/etc/timezone:ro")
## COMPOSE USER FILES
~/.compose/etc/local.conf
~/.compose.conf
)
docker_run_opts=("-v" "/var/run/docker.sock:/var/run/docker.sock")
## current dir
if parent=$(while true; do
[ -e "./compose.yml" ] && {
@ -301,6 +312,41 @@ mk_docker_run_options() {
fi
COMPOSE_LOCAL_ROOT=${COMPOSE_LOCAL_ROOT:-"$HOME/.compose"}
case "$(get_os)" in
linux)
if [ "$UID" == 0 ]; then
COMPOSE_VAR=${COMPOSE_VAR:-/var/lib/compose}
COMPOSE_CACHE=${COMPOSE_CACHE:-/var/cache/compose}
else
COMPOSE_VAR="$COMPOSE_LOCAL_ROOT"/lib
COMPOSE_CACHE="$COMPOSE_LOCAL_ROOT"/cache
fi
;;
mac)
COMPOSE_VAR=${COMPOSE_VAR:-"$COMPOSE_LOCAL_ROOT"/lib}
COMPOSE_CACHE=${COMPOSE_CACHE:-"$COMPOSE_LOCAL_ROOT"/cache}
;;
*)
echo "System '$os' not supported yet." >&2
exit 1
;;
esac
## get TZ value and prepare TZ_PATH
TZ=$(get_tz) || exit 1
mkdir -p "${COMPOSE_VAR}/timezones"
TZ_PATH="${COMPOSE_VAR}/timezones/$(e "$TZ" | sha256sum | cut -c 1-8)" || exit 1
[ -e "$TZ_PATH" ] || e "$TZ" > "$TZ_PATH"
## CACHE/DATA DIRS
docker_run_opts+=("-v" "$COMPOSE_VAR:/var/lib/compose")
docker_run_opts+=("-v" "$COMPOSE_CACHE:/var/cache/compose")
docker_run_opts+=("-v" "$TZ_PATH:/etc/timezone:ro")
##
## Checking vars
##
@ -397,42 +443,47 @@ mk_docker_run_options() {
}
run() {
local os docker_run_opts
## Order matters, files get to override vars
compose_config_files=(
/etc/default/charm
/etc/default/datastore
/etc/compose.conf
/etc/compose.local.conf
/etc/default/compose
~/.compose/etc/local.conf
/etc/compose/local.conf
)
get_tz() {
if [ -n "$TZ" ]; then
:
elif [ -n "$COMPOSE_LOCAL_ROOT" ] && ## previous compose run
[ -e "$COMPOSE_LOCAL_ROOT/etc/timezone" ]; then
read -r TZ < /etc/timezone
elif [ -e "/etc/timezone" ]; then ## debian host system timezone
read -r TZ < /etc/timezone
elif [ -e "/etc/localtime" ]; then ## redhat and macosx sys timezone
local fullpath dirname
fullpath="$(readlink -f /etc/localtime)"
dirname="${fullpath%/*}"
TZ=${TZ:-${fullpath##*/}/${dirname##*/}}
else
err "Timezone not found nor inferable !"
echo " compose relies on '/etc/timezone' or '/etc/localtime' to be present " >&2
echo " so as to ensure same timezone for all containers that need it." >&2
echo >&2
echo " You can set a default value for compose by create issuing:" >&2
echo >&2
if [ -n "$COMPOSE_LOCAL_ROOT" ] && [ "$UID" != 0 ]; then
echo " mkdir -p $COMPOSE_LOCAL_ROOT/etc &&" >&2
echo " echo \"Europe/Paris\" > $COMPOSE_LOCAL_ROOT/etc/timezone" >&2
else
echo " echo \"Europe/Paris\" > /etc/timezone" >&2
fi
echo >&2
echo " Of course, you can change 'Europe/Paris' value by any other valid timezone." >&2
echo " timezone." >&2
echo >&2
echo " Notice you can also use \$TZ environment variable, but the value" >&2
echo " will be necessary each time you launch compose." >&2
echo >&2
return 1
fi
e "$TZ"
}
os=$(get_os)
case "$os" in
linux)
COMPOSE_VAR=/var/lib/compose
COMPOSE_CACHE=/var/cache/compose
TZ_PATH=/etc/timezone
;;
mac)
if ! [ -e "$HOME/.compose/etc/timezone" ]; then
TZ=${TZ:-"Europe/Paris"}
echo "$TZ" > "$HOME"/.compose/etc/timezone
fi
TZ_PATH="$HOME"/.compose/etc/timezone
COMPOSE_VAR="$HOME"/.compose/lib
COMPOSE_CACHE="$HOME"/.compose/cache
;;
*)
echo "System '$os' not supported yet." >&2
exit 1
;;
esac
run() {
local os docker_run_opts
docker_run_opts=()
if [ -z "$COMPOSE_LAUNCHER_OPTS" ]; then

Loading…
Cancel
Save