Browse Source

fix: avoid calculating md5 when there is only one argument.

raw-remaining-args
Valentin Lab 8 years ago
parent
commit
5dbf63f865
  1. 40
      bin/compose

40
bin/compose

@ -196,7 +196,7 @@ export -f file_put
_get_docker_compose_links() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
links charm charm_part master_charm
if [ -z "$service" ]; then
print_syntax_error "$FUNCNAME: Please specify a service as first argument."
@ -227,7 +227,7 @@ _get_docker_compose_links() {
_get_docker_compose_opts() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
links charm charm_part master_charm
if [ -z "$service" ]; then
print_syntax_error "$FUNCNAME: Please specify a service as first argument."
@ -255,7 +255,7 @@ _get_docker_compose_opts() {
## Some metadata.yml (of subordinates) will indeed modify other
## services than themselves.
_get_docker_compose_service_mixin() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" links charm charm_part
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" links charm charm_part
if [ -z "$service" ]; then
print_syntax_error "$FUNCNAME: Please specify a service as first argument."
return 1
@ -286,8 +286,7 @@ _get_docker_compose_service_mixin() {
merge_yaml_str "$links_yaml" "$charm_yaml" "$docker_compose_options"
else
echo "$links_yaml"
fi > "$cache_file"
cat "$cache_file"
fi | tee "$cache_file"
}
export -f _get_docker_compose_service_mixin
@ -299,7 +298,7 @@ export -f _get_docker_compose_service_mixin
## @export
## @cache: !system !nofail +stdout
get_docker_compose () {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" entries services service
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" entries services service start
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -347,7 +346,7 @@ export -f get_docker_compose
## XXXvlab: a lot to be done to cache the results
get_compose_service_def () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -378,7 +377,7 @@ export -f get_compose_service_def
get_service_charm () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -419,7 +418,7 @@ export -f get_service_def
## Return the base docker image name of a service
service_base_docker_image() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
master_charm charm service_image service_build service_dockerfile
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -597,7 +596,7 @@ export -f array_member
get_charm_relation_def () {
local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
relation_def metadata
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -612,7 +611,7 @@ export -f get_charm_relation_def
get_charm_tech_dep_orientation_for_relation() {
local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
relation_def metadata value
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -630,7 +629,7 @@ export -f get_charm_tech_dep_orientation_for_relation
## Use compose file to get deps, and relation definition in metadata.yml
## for tech-dep attribute.
get_service_deps() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -714,8 +713,7 @@ get_ordered_service_dependencies() {
fi
done
i=$((i + 1))
done > "$cache_file"
cat "$cache_file"
done | tee "$cache_file"
}
export -f get_ordered_service_dependencies
@ -950,7 +948,7 @@ export -f _run_service_relation
get_compose_relations () {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" relation_name relation_def
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" relation_name relation_def
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -1103,7 +1101,7 @@ export -f _run_service_action_relation
get_relation_data_dir() {
local charm="$1" target_charm="$2" relation_name="$3" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local charm="$1" target_charm="$2" relation_name="$3" cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -1149,7 +1147,7 @@ export -f get_relation_data_file
has_service_action () {
local service="$1" action="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" action="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
target_script charm target_charm
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
@ -1204,7 +1202,7 @@ export -f run_service_action
get_compose_relation_config() {
local service=$1 relation_config cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)"
local service=$1 relation_config cache_file="$state_tmpdir/$FUNCNAME.cache.$1"
if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file"
@ -1242,7 +1240,7 @@ export -f get_compose_relation_config
_get_master_charm_for_service() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
charm metadata requires master_charm target_charm target_service service_def
if [ -e "$cache_file" ]; then
@ -1308,7 +1306,7 @@ export -f _get_master_charm_for_service
_get_top_master_charm_for_service() {
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
current_service
if [ -e "$cache_file" ]; then
@ -1345,7 +1343,7 @@ export -f get_charm_metadata
## docker-compose entry (thinking of subordinates). The result
## will be merge with master charms.
get_docker_compose_mixin_from_metadata() {
local charm="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \
local charm="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$1" \
metadata_file metadata volumes docker_compose subordinate image
if [ -e "$cache_file" ]; then

Loading…
Cancel
Save