TERM ?= 'dumb' pwd:=$(shell pwd) ifdef mounted_orchestration orchestration_dir=$(mounted_orchestration) else orchestration_dir=${pwd}/<%= env.orchestration_dir_name %> endif ifdef env_file custom_env_file ?= 1 else custom_env_file ?= 0 endif ifneq (,$(wildcard ${pwd}/config/database.yml)) database_enabled = 1 else database_enabled = 0 endif make=$(MAKE) $1 orchestration_config_filename:=.orchestration.yml orchestration_config:=${pwd}/${orchestration_config_filename} print_error=printf '${red}\#${reset} '$1 | tee '${stderr}' println_error=$(call print_error,$1'\n') print=printf '${blue}\#${reset} '$1 println=$(call print,$1'\n') printraw=printf $1 printrawln=$(call printraw,$1'\n') stdout=${pwd}/log/orchestration.stdout.log stderr=${pwd}/log/orchestration.stderr.log log_path_length=$(shell echo "${stdout}" | wc -c) ifndef verbose log_tee:= 2>&1 | tee -a ${stdout} log:= >>${stdout} 2>>${stderr} progress_point:=perl -e 'while( my $$line = ) { printf("."); select()->flush(); }' log_progress:= > >(tee -ai ${stdout} >&1 | ${progress_point}) 2> >(tee -ai ${stderr} 2>&1 | ${progress_point}) endif red:=$(shell tput setaf 1) green:=$(shell tput setaf 2) yellow:=$(shell tput setaf 3) blue:=$(shell tput setaf 4) magenta:=$(shell tput setaf 5) cyan:=$(shell tput setaf 6) gray:=$(shell tput setaf 7) reset:=$(shell tput sgr0) tick=[${green}✓${reset}] cross=[${red}✘${reset}] warn=[${yellow}!${reset}] hr=$(call println,"$1$(shell head -c ${log_path_length} < /dev/zero | tr '\0' '=')${reset}") managed_env_tag:=\# -|- ORCHESTRATION standard_env_path:=${pwd}/.env backup_env_path:=${pwd}/.env.orchestration.backup is_managed_env:=$$(test -f '${standard_env_path}' && tail -n 1 '${standard_env_path}') == "${managed_env_tag}"* token:=$(shell cat /dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | fold -w8 | head -n1) back_up_env:=( \ [ ! -f '${standard_env_path}' ] \ || \ ( \ [ -f '${standard_env_path}' ] \ && cp '${standard_env_path}' '${backup_env_path}' \ ) \ ) replace_env:=( \ ( [ "${custom_env_file}" == "0" ] ) \ || \ ( \ [ "${custom_env_file}" == "1" ] \ && ${back_up_env} \ && cp ${env_file} '${standard_env_path}' \ && $(call printraw,'\n${managed_env_tag}') >> '${standard_env_path}' \ ) \ ) restore_env:=( \ ( \ [[ ! ${is_managed_env} ]] \ || [ ! -f '${backup_env_path}' ] \ ) \ || \ ( \ [ -f '${backup_env_path}' ] \ && [[ ${is_managed_env} ]] \ && mv '${backup_env_path}' '${standard_env_path}' \ ) \ ) key_chars:=[a-zA-Z0-9_] censored:=********** censor=s/\(^${key_chars}*$(1)${key_chars}*\)=\(.*\)$$/\1=${censored}/ censor_urls:=s|\([a-zA-Z0-9_+]\+://.*:\).*\(@.*\)$$|\1${censored}\2| format_env:=sed '$(call censor,SECRET); \ $(call censor,TOKEN); \ $(call censor,PRIVATE); \ $(call censor,KEY); \ $(censor_urls); \ /^\s*$$/d; \ /^\s*\#/d; \ s/\(^[a-zA-Z0-9_]\+\)=/${blue}\1${reset}=/; \ s/^/ /; \ s/=\(.*\)$$/=${yellow}\1${reset}/' | \ sort fail=( \ $(call printraw,' ${cross}') ; \ ${restore_env} ; \ $(call make,dump) ; \ echo ; \ $(call println,'Failed. ${cross}') ; \ exit 1 \ )