|
@ -7,8 +7,22 @@ |
|
|
## Launcher |
|
|
## Launcher |
|
|
## - should need minimum requirement to run |
|
|
## - should need minimum requirement to run |
|
|
## - no shell libs |
|
|
## - no shell libs |
|
|
## |
|
|
|
|
|
|
|
|
## |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_os() { |
|
|
|
|
|
local uname_output machine |
|
|
|
|
|
|
|
|
|
|
|
uname_output="$(uname -s)" |
|
|
|
|
|
case "${uname_output}" in |
|
|
|
|
|
Linux*) machine=linux;; |
|
|
|
|
|
Darwin*) machine=mac;; |
|
|
|
|
|
CYGWIN*) machine=cygwin;; |
|
|
|
|
|
MINGW*) machine=mingw;; |
|
|
|
|
|
*) machine="UNKNOWN:${uname_output}" |
|
|
|
|
|
esac |
|
|
|
|
|
echo "${machine}" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
read-0() { |
|
|
read-0() { |
|
@ -49,7 +63,7 @@ is_volume_used() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clean_unused_sessions() { |
|
|
clean_unused_sessions() { |
|
|
for f in /var/lib/compose/sessions/*; do |
|
|
|
|
|
|
|
|
for f in "$COMPOSE_VAR/sessions/"*; do |
|
|
[ -e "$f" ] || continue |
|
|
[ -e "$f" ] || continue |
|
|
is_volume_used "$f" && continue |
|
|
is_volume_used "$f" && continue |
|
|
rm -f "$f" |
|
|
rm -f "$f" |
|
@ -75,10 +89,10 @@ mk_docker_run_options() { |
|
|
docker_run_opts=("-v" "/var/run/docker.sock:/var/run/docker.sock") |
|
|
docker_run_opts=("-v" "/var/run/docker.sock:/var/run/docker.sock") |
|
|
|
|
|
|
|
|
## CACHE/DATA DIRS |
|
|
## CACHE/DATA DIRS |
|
|
docker_run_opts+=("-v" "/var/lib/compose:/var/lib/compose") |
|
|
|
|
|
docker_run_opts+=("-v" "/var/cache/compose:/var/cache/compose") |
|
|
|
|
|
|
|
|
docker_run_opts+=("-v" "$COMPOSE_VAR:/var/lib/compose") |
|
|
|
|
|
docker_run_opts+=("-v" "$COMPOSE_CACHE:/var/cache/compose") |
|
|
|
|
|
|
|
|
docker_run_opts+=("-v" "/etc/timezone:/etc/timezone:ro") |
|
|
|
|
|
|
|
|
docker_run_opts+=("-v" "$TZ_PATH:/etc/timezone:ro") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## current dir |
|
|
## current dir |
|
@ -91,7 +105,7 @@ mk_docker_run_options() { |
|
|
cd .. |
|
|
cd .. |
|
|
done |
|
|
done |
|
|
); then |
|
|
); then |
|
|
docker_path=/var/lib/compose/root/$(basename "$parent") |
|
|
|
|
|
|
|
|
docker_path=$COMPOSE_VAR/root/$(basename "$parent") |
|
|
docker_run_opts+=("-v" "$parent:$docker_path:ro" \ |
|
|
docker_run_opts+=("-v" "$parent:$docker_path:ro" \ |
|
|
"-w" "$docker_path") |
|
|
"-w" "$docker_path") |
|
|
fi |
|
|
fi |
|
@ -102,23 +116,13 @@ mk_docker_run_options() { |
|
|
## |
|
|
## |
|
|
|
|
|
|
|
|
if [ -z "$DISABLE_SYSTEM_CONFIG_FILE" ]; then |
|
|
if [ -z "$DISABLE_SYSTEM_CONFIG_FILE" ]; then |
|
|
if [ -r /etc/default/charm ]; then |
|
|
|
|
|
docker_run_opts+=("-v" "/etc/default/charm:/etc/default/charm:ro") |
|
|
|
|
|
. /etc/default/charm |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
## XXXvlab: should provide YML config opportunities in possible parent dirs ? |
|
|
## XXXvlab: should provide YML config opportunities in possible parent dirs ? |
|
|
## userdir ? and global /etc/compose.yml ? |
|
|
## userdir ? and global /etc/compose.yml ? |
|
|
for cfgfile in /etc/compose.conf /etc/compose.local.conf \ |
|
|
|
|
|
/etc/default/compose /etc/compose/local.conf; do |
|
|
|
|
|
|
|
|
for cfgfile in "${compose_config_files[@]}"; do |
|
|
[ -e "$cfgfile" ] || continue |
|
|
[ -e "$cfgfile" ] || continue |
|
|
docker_run_opts+=("-v" "$cfgfile:$cfgfile:ro") |
|
|
docker_run_opts+=("-v" "$cfgfile:$cfgfile:ro") |
|
|
. "$cfgfile" |
|
|
. "$cfgfile" |
|
|
done |
|
|
done |
|
|
for cfgfile in /etc/default/datastore; do |
|
|
|
|
|
[ -e "$cfgfile" ] || continue |
|
|
|
|
|
docker_run_opts+=("-v" "$cfgfile:$cfgfile:ro") |
|
|
|
|
|
done |
|
|
|
|
|
else |
|
|
else |
|
|
docker_run_opts+=("-e" "DISABLE_SYSTEM_CONFIG_FILE=$DISABLE_SYSTEM_CONFIG_FILE") |
|
|
docker_run_opts+=("-e" "DISABLE_SYSTEM_CONFIG_FILE=$DISABLE_SYSTEM_CONFIG_FILE") |
|
|
fi |
|
|
fi |
|
@ -131,9 +135,13 @@ mk_docker_run_options() { |
|
|
## CHARM_STORE |
|
|
## CHARM_STORE |
|
|
CHARM_STORE=${CHARM_STORE:-/srv/charm-store} |
|
|
CHARM_STORE=${CHARM_STORE:-/srv/charm-store} |
|
|
[ -L "$CHARM_STORE" ] && { |
|
|
[ -L "$CHARM_STORE" ] && { |
|
|
CHARM_STORE=$(readlink "$CHARM_STORE") || exit 1 |
|
|
|
|
|
|
|
|
CHARM_STORE=$(readlink -f "$CHARM_STORE") || exit 1 |
|
|
} |
|
|
} |
|
|
docker_run_opts+=("-v" "$CHARM_STORE:/srv/charm-store:ro") |
|
|
|
|
|
|
|
|
docker_run_opts+=( |
|
|
|
|
|
"-v" "$CHARM_STORE:/srv/charm-store:ro" |
|
|
|
|
|
"-e" "CHARM_STORE=/srv/charm-store" |
|
|
|
|
|
"-e" "HOST_CHARM_STORE=$CHARM_STORE" |
|
|
|
|
|
) |
|
|
relink_subdirs /srv/charm-store/* |
|
|
relink_subdirs /srv/charm-store/* |
|
|
|
|
|
|
|
|
## DEFAULT_COMPOSE_FILE |
|
|
## DEFAULT_COMPOSE_FILE |
|
@ -148,22 +156,29 @@ mk_docker_run_options() { |
|
|
## COMPOSE_YML_FILE |
|
|
## COMPOSE_YML_FILE |
|
|
if [ "${COMPOSE_YML_FILE+x}" ]; then |
|
|
if [ "${COMPOSE_YML_FILE+x}" ]; then |
|
|
if [ -e "${COMPOSE_YML_FILE}" ]; then |
|
|
if [ -e "${COMPOSE_YML_FILE}" ]; then |
|
|
docker_run_opts+=("-v" "$COMPOSE_YML_FILE:/tmp/compose.yml:ro") |
|
|
|
|
|
docker_run_opts+=("-e" "COMPOSE_YML_FILE=/tmp/compose.yml") |
|
|
|
|
|
|
|
|
docker_run_opts+=( |
|
|
|
|
|
"-v" "$COMPOSE_YML_FILE:/tmp/compose.yml:ro" |
|
|
|
|
|
"-e" "COMPOSE_YML_FILE=/tmp/compose.yml" |
|
|
|
|
|
"-e" "HOST_COMPOSE_YML_FILE=/tmp/compose.yml" |
|
|
|
|
|
) |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
## DATASTORE |
|
|
## DATASTORE |
|
|
if [ "${DATASTORE+x}" ]; then |
|
|
|
|
|
docker_run_opts+=("-v" "$DATASTORE:/srv/datastore/data:rw") |
|
|
|
|
|
docker_run_opts+=("-e" "DATASTORE=/srv/datastore/data") |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
DATASTORE=${DATASTORE:-/srv/datastore/data} |
|
|
|
|
|
docker_run_opts+=( |
|
|
|
|
|
"-v" "$DATASTORE:/srv/datastore/data:rw" |
|
|
|
|
|
"-e" "DATASTORE=/srv/datastore/data" |
|
|
|
|
|
"-e" "HOST_DATASTORE=$DATASTORE" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
## CONFIGSTORE |
|
|
## CONFIGSTORE |
|
|
if [ "${CONFIGSTORE+x}" ]; then |
|
|
|
|
|
docker_run_opts+=("-v" "$CONFIGSTORE:/srv/datastore/config:rw") |
|
|
|
|
|
docker_run_opts+=("-e" "CONFIGSTORE=/srv/datastore/config") |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
CONFIGSTORE=${CONFIGSTORE:-/srv/datastore/config} |
|
|
|
|
|
docker_run_opts+=( |
|
|
|
|
|
"-v" "$CONFIGSTORE:/srv/datastore/config:rw" |
|
|
|
|
|
"-e" "CONFIGSTORE=/srv/datastore/config" |
|
|
|
|
|
"-e" "HOST_CONFIGSTORE=$CONFIGSTORE" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
docker_run_opts+=("-v" "$HOME/.docker:/root/.docker") |
|
|
docker_run_opts+=("-v" "$HOME/.docker:/root/.docker") |
|
|
|
|
|
|
|
@ -171,6 +186,7 @@ mk_docker_run_options() { |
|
|
docker_run_opts+=("-e" "COMPOSE_DOCKER_IMAGE=$COMPOSE_DOCKER_IMAGE") |
|
|
docker_run_opts+=("-e" "COMPOSE_DOCKER_IMAGE=$COMPOSE_DOCKER_IMAGE") |
|
|
|
|
|
|
|
|
COMPOSE_LAUNCHER_BIN=$(readlink -f "${BASH_SOURCE[0]}") |
|
|
COMPOSE_LAUNCHER_BIN=$(readlink -f "${BASH_SOURCE[0]}") |
|
|
|
|
|
docker_run_opts+=("-v" "$COMPOSE_LAUNCHER_BIN:/usr/local/bin/compose") |
|
|
|
|
|
|
|
|
filename=$(mktemp -p /tmp/ -t launch_opts-XXXXXXXXXXXXXXXX) |
|
|
filename=$(mktemp -p /tmp/ -t launch_opts-XXXXXXXXXXXXXXXX) |
|
|
{ |
|
|
{ |
|
@ -178,19 +194,55 @@ mk_docker_run_options() { |
|
|
} > "$filename" |
|
|
} > "$filename" |
|
|
sha=$(sha256sum "$filename") |
|
|
sha=$(sha256sum "$filename") |
|
|
sha=${sha:0:64} |
|
|
sha=${sha:0:64} |
|
|
dest="/var/lib/compose/sessions/$sha" |
|
|
|
|
|
|
|
|
dest="$COMPOSE_VAR/sessions/$sha" |
|
|
{ |
|
|
{ |
|
|
printf "%s\0" "-v" "$dest:$dest" |
|
|
printf "%s\0" "-v" "$dest:$dest" |
|
|
printf "%s\0" "-e" "COMPOSE_LAUNCHER_OPTS=$dest" |
|
|
printf "%s\0" "-e" "COMPOSE_LAUNCHER_OPTS=$dest" |
|
|
printf "%s\0" "-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN" |
|
|
printf "%s\0" "-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN" |
|
|
} >> "$filename" |
|
|
} >> "$filename" |
|
|
mkdir -p /var/lib/compose/sessions |
|
|
|
|
|
|
|
|
mkdir -p "$COMPOSE_VAR"/sessions |
|
|
mv "$filename" "$dest" |
|
|
mv "$filename" "$dest" |
|
|
echo "$dest" |
|
|
echo "$dest" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
run() { |
|
|
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 |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docker_run_opts=() |
|
|
docker_run_opts=() |
|
|
if [ -z "$COMPOSE_LAUNCHER_OPTS" ]; then |
|
|
if [ -z "$COMPOSE_LAUNCHER_OPTS" ]; then |
|
|
clean_unused_sessions |
|
|
clean_unused_sessions |
|
|