From ad5a1bc89912186c1b74ae39e9a7e61b38abb323 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 3 Aug 2019 16:45:18 +0200 Subject: [PATCH] new: mac compatibility --- bin/compose | 81 +++++++++++++++++++++++++++++++++++++++--------- bin/compose-core | 6 +++- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/bin/compose b/bin/compose index 70796a0..55d91d5 100755 --- a/bin/compose +++ b/bin/compose @@ -7,8 +7,22 @@ ## Launcher ## - should need minimum requirement to run ## - 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() { @@ -49,7 +63,7 @@ is_volume_used() { clean_unused_sessions() { - for f in /var/lib/compose/sessions/*; do + for f in "$COMPOSE_VAR/sessions/"*; do [ -e "$f" ] || continue is_volume_used "$f" && continue rm -f "$f" @@ -75,10 +89,10 @@ mk_docker_run_options() { docker_run_opts=("-v" "/var/run/docker.sock:/var/run/docker.sock") ## 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 @@ -91,7 +105,7 @@ mk_docker_run_options() { cd .. done ); then - docker_path=/var/lib/compose/root/$(basename "$parent") + docker_path=$COMPOSE_VAR/root/$(basename "$parent") docker_run_opts+=("-v" "$parent:$docker_path:ro" \ "-w" "$docker_path") fi @@ -133,7 +147,11 @@ mk_docker_run_options() { [ -L "$CHARM_STORE" ] && { CHARM_STORE=$(readlink "$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/* ## DEFAULT_COMPOSE_FILE @@ -148,21 +166,30 @@ mk_docker_run_options() { ## COMPOSE_YML_FILE if [ "${COMPOSE_YML_FILE+x}" ]; 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 ## DATASTORE if [ "${DATASTORE+x}" ]; then - docker_run_opts+=("-v" "$DATASTORE:/srv/datastore/data:rw") - docker_run_opts+=("-e" "DATASTORE=/srv/datastore/data") + docker_run_opts+=( + "-v" "$DATASTORE:/srv/datastore/data:rw" + "-e" "DATASTORE=/srv/datastore/data" + "-e" "HOST_DATASTORE=$DATASTORE" + ) fi ## CONFIGSTORE if [ "${CONFIGSTORE+x}" ]; then - docker_run_opts+=("-v" "$CONFIGSTORE:/srv/datastore/config:rw") - docker_run_opts+=("-e" "CONFIGSTORE=/srv/datastore/config") + docker_run_opts+=( + "-v" "$CONFIGSTORE:/srv/datastore/config:rw" + "-e" "CONFIGSTORE=/srv/datastore/config" + "-e" "HOST_CONFIGSTORE=$CONFIGSTORE" + ) fi docker_run_opts+=("-v" "$HOME/.docker:/root/.docker") @@ -178,19 +205,43 @@ mk_docker_run_options() { } > "$filename" sha=$(sha256sum "$filename") sha=${sha:0:64} - dest="/var/lib/compose/sessions/$sha" + dest="$COMPOSE_VAR/sessions/$sha" { printf "%s\0" "-v" "$dest:$dest" printf "%s\0" "-e" "COMPOSE_LAUNCHER_OPTS=$dest" printf "%s\0" "-e" "COMPOSE_LAUNCHER_BIN=$COMPOSE_LAUNCHER_BIN" } >> "$filename" - mkdir -p /var/lib/compose/sessions + mkdir -p "$COMPOSE_VAR"/sessions mv "$filename" "$dest" echo "$dest" } run() { + local os docker_run_opts + + os=$(get_os) + case "$os" in + linux) + COMPOSE_VAR=/var/lib/compose + COMPOSE_CACHE=/var/cache/compose + ;; + 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=() if [ -z "$COMPOSE_LAUNCHER_OPTS" ]; then clean_unused_sessions diff --git a/bin/compose-core b/bin/compose-core index 34b2a61..5be316f 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -731,7 +731,11 @@ ensure_db_docker_running () { docker rm "$_DB_NAME" 2>/dev/null || true - host_db_working_dir="$DATASTORE/${SERVICE_NAME}$DB_DATADIR" + if [ "${HOST_DATASTORE+x}" ]; then + host_db_working_dir="$HOST_DATASTORE/${SERVICE_NAME}$DB_DATADIR" + else + host_db_working_dir="$DATASTORE/${SERVICE_NAME}$DB_DATADIR" + fi if is_db_locked; then info "Some process is using '$host_db_working_dir'. Trying to find a docker that would do this..."