Browse Source

chg: dev: always 2 newlines between 2 functions def !minor

test
Valentin Lab 6 years ago
parent
commit
cebda50840
  1. 37
      bin/compose

37
bin/compose

@ -117,7 +117,6 @@ clean_cache() {
} }
usage="$exname SERVICE"' usage="$exname SERVICE"'
Deploy and manage a swarm of containers to provide services based on Deploy and manage a swarm of containers to provide services based on
@ -291,6 +290,7 @@ docker_has_image() {
} }
export -f docker_has_image export -f docker_has_image
cmd_on_base_image() { cmd_on_base_image() {
local service="$1" base_image local service="$1" base_image
shift shift
@ -299,6 +299,7 @@ cmd_on_base_image() {
} }
export -f cmd_on_base_image export -f cmd_on_base_image
cached_cmd_on_base_image() { cached_cmd_on_base_image() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
shift shift
@ -323,10 +324,12 @@ export -f image_exposed_ports_0
## Generic ## Generic
## ##
fn.exists() { fn.exists() {
declare -F "$1" >/dev/null declare -F "$1" >/dev/null
} }
str_pattern_matches() { str_pattern_matches() {
local str="$1" local str="$1"
shift shift
@ -355,6 +358,7 @@ gen_password() {
} }
export -f gen_password export -f gen_password
file_put() { file_put() {
local TARGET="$1" local TARGET="$1"
mkdir -p "$(dirname "$TARGET")" && mkdir -p "$(dirname "$TARGET")" &&
@ -370,6 +374,7 @@ file_put_0() {
} }
export -f file_put_0 export -f file_put_0
fetch_file() { fetch_file() {
local src="$1" local src="$1"
@ -390,6 +395,7 @@ fetch_file() {
} }
export -f fetch_file export -f fetch_file
## receives stdin content to decompress on stdout ## receives stdin content to decompress on stdout
## stdout content should be tar format. ## stdout content should be tar format.
uncompress_file() { uncompress_file() {
@ -412,6 +418,7 @@ uncompress_file() {
} }
export -f uncompress_file export -f uncompress_file
get_file() { get_file() {
local src="$1" local src="$1"
@ -437,6 +444,7 @@ _clean_docker() {
} }
export -f _clean_docker export -f _clean_docker
get_service_base_image_dir_uid_gid() { get_service_base_image_dir_uid_gid() {
local service="$1" dir="$2" uid_gid local service="$1" dir="$2" uid_gid
uid_gid=$(cached_cmd_on_base_image "$service" "stat -c '%u %g' '$dir'") || { uid_gid=$(cached_cmd_on_base_image "$service" "stat -c '%u %g' '$dir'") || {
@ -448,6 +456,7 @@ get_service_base_image_dir_uid_gid() {
} }
export -f get_service_base_image_dir_uid_gid export -f get_service_base_image_dir_uid_gid
are_files_locked_in_dir() { are_files_locked_in_dir() {
local dir="$1" device hdev ldev local dir="$1" device hdev ldev
device=$(stat -c %d "$dir") || { device=$(stat -c %d "$dir") || {
@ -472,6 +481,7 @@ are_files_locked_in_dir() {
} }
export -f are_files_locked_in_dir export -f are_files_locked_in_dir
export _PID="$$" export _PID="$$"
ensure_db_docker_running () { ensure_db_docker_running () {
local _STATE_FILE local _STATE_FILE
@ -580,6 +590,7 @@ ensure_db_docker_running () {
} }
export -f ensure_db_docker_running export -f ensure_db_docker_running
## Require to set $db_docker_opts if needed, and $DB_PASSFILE ## Require to set $db_docker_opts if needed, and $DB_PASSFILE
## ##
_dcmd() { _dcmd() {
@ -635,6 +646,7 @@ get_docker_ips() {
} }
export -f get_docker_ips export -f get_docker_ips
get_docker_ip() { get_docker_ip() {
local name="$1" local name="$1"
get_docker_ips "$name" get_docker_ips "$name"
@ -863,6 +875,7 @@ _get_docker_compose_service_mixin() {
} }
export -f _get_docker_compose_service_mixin export -f _get_docker_compose_service_mixin
## ##
## Get full `docker-compose.yml` format for all listed services (and ## Get full `docker-compose.yml` format for all listed services (and
## their deps) ## their deps)
@ -970,6 +983,7 @@ _get_compose_service_def_cached () {
} }
export -f _get_compose_service_def_cached export -f _get_compose_service_def_cached
## XXXvlab: a lot to be done to cache the results ## XXXvlab: a lot to be done to cache the results
get_compose_service_def () { get_compose_service_def () {
local service="$1" docker_compose cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ local service="$1" docker_compose cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
@ -1005,6 +1019,7 @@ _get_service_charm_cached () {
} }
export -f _get_service_charm_cached export -f _get_service_charm_cached
get_service_charm () { get_service_charm () {
local service="$1" local service="$1"
if [ -z "$service" ]; then if [ -z "$service" ]; then
@ -1017,6 +1032,7 @@ get_service_charm () {
} }
export -f get_service_charm export -f get_service_charm
## built above the docker-compose abstraction, so it relies on the ## built above the docker-compose abstraction, so it relies on the
## full docker-compose.yml to be already built. ## full docker-compose.yml to be already built.
get_service_def () { get_service_def () {
@ -1106,6 +1122,7 @@ get_charm_tech_dep_orientation_for_relation() {
} }
export -f get_charm_tech_dep_orientation_for_relation export -f get_charm_tech_dep_orientation_for_relation
## ##
## Use compose file to get deps, and relation definition in metadata.yml ## Use compose file to get deps, and relation definition in metadata.yml
## for tech-dep attribute. ## for tech-dep attribute.
@ -1200,6 +1217,7 @@ get_ordered_service_dependencies() {
} }
export -f get_ordered_service_dependencies export -f get_ordered_service_dependencies
run_service_hook () { run_service_hook () {
local action="$1" service subservice subservices loaded local action="$1" service subservice subservices loaded
shift shift
@ -1397,6 +1415,7 @@ _config_merge() {
} }
export -f _config_merge export -f _config_merge
## XXXvlab; this can be used only in relation, I'd like to use it in init. ## XXXvlab; this can be used only in relation, I'd like to use it in init.
config-add() { config-add() {
local metadata="$1" local metadata="$1"
@ -1404,6 +1423,7 @@ config-add() {
} }
export -f config-add export -f config-add
## XXXvlab; this can be used only in relation, I'd like to use it in init. ## XXXvlab; this can be used only in relation, I'd like to use it in init.
init-config-add() { init-config-add() {
local metadata="$1" local metadata="$1"
@ -1581,6 +1601,7 @@ _get_compose_relations_cached () {
} }
export -f _get_compose_relations_cached export -f _get_compose_relations_cached
get_compose_relations () { get_compose_relations () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
compose_def compose_def
@ -1933,6 +1954,7 @@ _get_master_service_for_service_cached () {
} }
export -f _get_master_service_for_service_cached export -f _get_master_service_for_service_cached
get_master_service_for_service() { get_master_service_for_service() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \ local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
charm metadata result charm metadata result
@ -2087,6 +2109,7 @@ _save() {
} }
export -f _save export -f _save
get_default_project_name() { get_default_project_name() {
if [ "$DEFAULT_PROJECT_NAME" ]; then if [ "$DEFAULT_PROJECT_NAME" ]; then
echo "$DEFAULT_PROJECT_NAME" echo "$DEFAULT_PROJECT_NAME"
@ -2167,6 +2190,7 @@ launch_docker_compose() {
} }
export -f launch_docker_compose export -f launch_docker_compose
get_compose_yml_location() { get_compose_yml_location() {
if ! [ -z ${COMPOSE_YML_FILE+x} ]; then ## if set, even if empty if ! [ -z ${COMPOSE_YML_FILE+x} ]; then ## if set, even if empty
echo "$COMPOSE_YML_FILE" echo "$COMPOSE_YML_FILE"
@ -2198,6 +2222,7 @@ get_compose_yml_location() {
} }
export -f get_compose_yml_location export -f get_compose_yml_location
get_compose_yml_content() { get_compose_yml_content() {
local cache_file="$state_tmpdir/$FUNCNAME.cache" local cache_file="$state_tmpdir/$FUNCNAME.cache"
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
@ -2294,6 +2319,7 @@ get_docker_compose_help_msg() {
tee "$cache_file" || return 1 tee "$cache_file" || return 1
} }
get_docker_compose_usage() { get_docker_compose_usage() {
local action="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$1"; cat "$(which docker-compose)" | md5_compat)" \ local action="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$1"; cat "$(which docker-compose)" | md5_compat)" \
docker_compose_help_msg docker_compose_help_msg
@ -2330,6 +2356,7 @@ get_docker_compose_opts_help() {
tee "$cache_file" || return 1 tee "$cache_file" || return 1
} }
get_docker_compose_commands_help() { get_docker_compose_commands_help() {
local action="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$1"; cat "$(which docker-compose)" | md5_compat)" \ local action="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$1"; cat "$(which docker-compose)" | md5_compat)" \
docker_compose_help_msg docker_compose_help_msg
@ -2392,10 +2419,10 @@ remove_options_in_option_help_msg() {
} }
_MULTIOPTION_REGEX='^((-[a-zA-Z]|--[a-zA-Z0-9-]+)(, )?)+' _MULTIOPTION_REGEX='^((-[a-zA-Z]|--[a-zA-Z0-9-]+)(, )?)+'
_MULTIOPTION_REGEX_LINE_FILTER=$_MULTIOPTION_REGEX'(\s|=)' _MULTIOPTION_REGEX_LINE_FILTER=$_MULTIOPTION_REGEX'(\s|=)'
multi_opts_filter() { multi_opts_filter() {
egrep "$_MULTIOPTION_REGEX_LINE_FILTER" | egrep "$_MULTIOPTION_REGEX_LINE_FILTER" |
sed -r "s/^($_MULTIOPTION_REGEX)(\s|=).*$/\1/g" | sed -r "s/^($_MULTIOPTION_REGEX)(\s|=).*$/\1/g" |
@ -2415,6 +2442,7 @@ get_docker_compose_multi_opts_list() {
echo "$opts_list" | multi_opts_filter echo "$opts_list" | multi_opts_filter
} }
get_docker_compose_single_opts_list() { get_docker_compose_single_opts_list() {
local action="$1" opts_list local action="$1" opts_list
opts_list=$(get_docker_compose_opts_list "$action") || return 1 opts_list=$(get_docker_compose_opts_list "$action") || return 1
@ -2447,6 +2475,7 @@ display_help() {
get_docker_compose_commands_help | sed -r "s/ ([a-z]+)(\s+)/ ${DARKCYAN}\1${NORMAL}\2/g" get_docker_compose_commands_help | sed -r "s/ ([a-z]+)(\s+)/ ${DARKCYAN}\1${NORMAL}\2/g"
} }
_graph_service() { _graph_service() {
local service="$1" base="$1" local service="$1" base="$1"
@ -2557,12 +2586,14 @@ fi)
EOF EOF
} }
cla_contains () { cla_contains () {
local e local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1 return 1
} }
filter_docker_compose_help_message() { filter_docker_compose_help_message() {
cat - | cat - |
sed -r "s/docker-compose run/${DARKWHITE}compose${NORMAL} ${DARKCYAN}$action${NORMAL}/g; sed -r "s/docker-compose run/${DARKWHITE}compose${NORMAL} ${DARKCYAN}$action${NORMAL}/g;
@ -2573,6 +2604,7 @@ filter_docker_compose_help_message() {
s/docker-compose/${DARKWHITE}compose${NORMAL}/g" s/docker-compose/${DARKWHITE}compose${NORMAL}/g"
} }
graph() { graph() {
local services=("$@") local services=("$@")
declare -A entries declare -A entries
@ -2603,6 +2635,7 @@ EOF
echo "}" echo "}"
} }
cached_wget() { cached_wget() {
local cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ local cache_file="$CACHEDIR/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
url="$1" url="$1"

Loading…
Cancel
Save