mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-17 13:55:08 +00:00
267 lines
6.1 KiB
Bash
Executable file
267 lines
6.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
get_single_host_proxy_mode_id() {
|
|
local proxy_mode="${1}"
|
|
|
|
case "${proxy_mode}" in
|
|
"Traefik (HTTP, built-in proxy)")
|
|
printf 'traefik-http\n'
|
|
;;
|
|
"Traefik (HTTPS + Let's Encrypt)")
|
|
printf 'traefik-https\n'
|
|
;;
|
|
"nginx-proxy (HTTP)")
|
|
printf 'nginxproxy-http\n'
|
|
;;
|
|
"nginx-proxy + acme-companion (HTTPS)")
|
|
printf 'nginxproxy-https\n'
|
|
;;
|
|
"Caddy (external reverse proxy)")
|
|
printf 'caddy-external\n'
|
|
;;
|
|
"No reverse proxy (direct :8080)")
|
|
printf 'no-proxy\n'
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_single_host_proxy_overrides() {
|
|
local proxy_mode="${1}"
|
|
|
|
case "${proxy_mode}" in
|
|
"Traefik (HTTP, built-in proxy)")
|
|
printf 'overrides/compose.proxy.yaml\n'
|
|
;;
|
|
"Traefik (HTTPS + Let's Encrypt)")
|
|
printf 'overrides/compose.https.yaml\n'
|
|
;;
|
|
"nginx-proxy (HTTP)")
|
|
printf 'overrides/compose.nginxproxy.yaml\n'
|
|
;;
|
|
"nginx-proxy + acme-companion (HTTPS)")
|
|
printf 'overrides/compose.nginxproxy.yaml\noverrides/compose.nginxproxy-ssl.yaml\n'
|
|
;;
|
|
"Caddy (external reverse proxy)" | "No reverse proxy (direct :8080)")
|
|
printf 'overrides/compose.noproxy.yaml\n'
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_single_host_database_id() {
|
|
local database_choice="${1}"
|
|
|
|
case "${database_choice}" in
|
|
"MariaDB (recommended)")
|
|
printf 'mariadb\n'
|
|
;;
|
|
"PostgreSQL")
|
|
printf 'postgres\n'
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_single_host_database_override() {
|
|
local database_choice="${1}"
|
|
|
|
case "${database_choice}" in
|
|
"MariaDB (recommended)")
|
|
printf 'overrides/compose.mariadb.yaml\n'
|
|
;;
|
|
"PostgreSQL")
|
|
printf 'overrides/compose.postgres.yaml\n'
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_single_host_redis_id() {
|
|
local redis_choice="${1}"
|
|
|
|
case "${redis_choice}" in
|
|
"Include Redis (recommended)")
|
|
printf 'enabled\n'
|
|
;;
|
|
"Skip Redis (experienced users only)")
|
|
printf 'disabled\n'
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_single_host_redis_override() {
|
|
local redis_choice="${1}"
|
|
|
|
case "${redis_choice}" in
|
|
"Include Redis (recommended)")
|
|
printf 'overrides/compose.redis.yaml\n'
|
|
;;
|
|
"Skip Redis (experienced users only)")
|
|
printf ''
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
persist_single_host_env_file() {
|
|
local stack_dir="${1}"
|
|
local env_lines="${2}"
|
|
local env_path=""
|
|
local env_tmp_path=""
|
|
local generated_at=""
|
|
|
|
env_path="$(get_stack_env_path "${stack_dir}")"
|
|
env_tmp_path="${env_path}.tmp"
|
|
generated_at="$(get_current_utc_timestamp)"
|
|
|
|
if ! {
|
|
printf '# Generated by easy-docker wizard at %s\n' "${generated_at}"
|
|
printf '# Adjust values as needed for this stack.\n'
|
|
if [ -n "${env_lines}" ]; then
|
|
printf '\n%s\n' "${env_lines}"
|
|
else
|
|
printf '\n# No additional environment variables configured by the wizard.\n'
|
|
fi
|
|
} >"${env_tmp_path}"; then
|
|
rm -f -- "${env_tmp_path}" >/dev/null 2>&1 || true
|
|
return 1
|
|
fi
|
|
|
|
if ! mv -- "${env_tmp_path}" "${env_path}"; then
|
|
rm -f -- "${env_tmp_path}" >/dev/null 2>&1 || true
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
persist_single_host_selection_metadata() {
|
|
local stack_dir="${1}"
|
|
local proxy_mode_id="${2}"
|
|
local database_id="${3}"
|
|
local redis_id="${4}"
|
|
local compose_files_lines="${5}"
|
|
local env_lines="${6}"
|
|
local updated_at=""
|
|
local compose_files_json=""
|
|
local env_json_object=""
|
|
local wizard_json_object=""
|
|
|
|
updated_at="$(get_current_utc_timestamp)"
|
|
compose_files_json="$(build_compose_files_json_array "${compose_files_lines}")"
|
|
env_json_object="$(build_env_json_object "${env_lines}")"
|
|
|
|
if ! wizard_json_object="$(
|
|
cat <<EOF
|
|
{
|
|
"topology": "single-host",
|
|
"selection": {
|
|
"proxy_mode_id": "${proxy_mode_id}",
|
|
"database_id": "${database_id}",
|
|
"redis_id": "${redis_id}"
|
|
},
|
|
"env": ${env_json_object},
|
|
"compose_files": [
|
|
${compose_files_json}
|
|
],
|
|
"updated_at": "${updated_at}"
|
|
}
|
|
EOF
|
|
)"; then
|
|
return 1
|
|
fi
|
|
|
|
if ! persist_stack_metadata_wizard_object "${stack_dir}" "${wizard_json_object}"; then
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
save_single_host_selection() {
|
|
local stack_dir="${1}"
|
|
local proxy_mode="${2}"
|
|
local database_choice="${3}"
|
|
local redis_choice="${4}"
|
|
local proxy_mode_id=""
|
|
local database_id=""
|
|
local redis_id=""
|
|
local database_override=""
|
|
local redis_override=""
|
|
local proxy_overrides=""
|
|
local compose_files_lines=""
|
|
local env_lines=""
|
|
local apps_metadata_json_object=""
|
|
local wizard_metadata_status=0
|
|
local apps_metadata_status=0
|
|
local collect_env_status=0
|
|
|
|
proxy_mode_id="$(get_single_host_proxy_mode_id "${proxy_mode}")" || return 1
|
|
database_id="$(get_single_host_database_id "${database_choice}")" || return 1
|
|
redis_id="$(get_single_host_redis_id "${redis_choice}")" || return 1
|
|
|
|
database_override="$(get_single_host_database_override "${database_choice}")" || return 1
|
|
redis_override="$(get_single_host_redis_override "${redis_choice}")" || return 1
|
|
proxy_overrides="$(get_single_host_proxy_overrides "${proxy_mode}")" || return 1
|
|
|
|
compose_files_lines="$(printf 'compose.yaml\n%s' "${database_override}")"
|
|
if [ -n "${redis_override}" ]; then
|
|
compose_files_lines="$(printf '%s\n%s' "${compose_files_lines}" "${redis_override}")"
|
|
fi
|
|
compose_files_lines="$(printf '%s\n%s' "${compose_files_lines}" "${proxy_overrides}")"
|
|
|
|
if collect_single_host_env_lines env_lines apps_metadata_json_object "${stack_dir}" "${proxy_mode_id}" "${database_id}"; then
|
|
:
|
|
else
|
|
collect_env_status=$?
|
|
return "${collect_env_status}"
|
|
fi
|
|
|
|
if ! persist_single_host_env_file "${stack_dir}" "${env_lines}"; then
|
|
return 1
|
|
fi
|
|
|
|
if persist_single_host_selection_metadata \
|
|
"${stack_dir}" \
|
|
"${proxy_mode_id}" \
|
|
"${database_id}" \
|
|
"${redis_id}" \
|
|
"${compose_files_lines}" \
|
|
"${env_lines}"; then
|
|
:
|
|
else
|
|
wizard_metadata_status=$?
|
|
return "${wizard_metadata_status}"
|
|
fi
|
|
|
|
if [ -z "${apps_metadata_json_object}" ]; then
|
|
return 1
|
|
fi
|
|
|
|
if persist_stack_metadata_apps_object "${stack_dir}" "${apps_metadata_json_object}"; then
|
|
:
|
|
else
|
|
apps_metadata_status=$?
|
|
return "${apps_metadata_status}"
|
|
fi
|
|
|
|
if ! persist_stack_apps_json_from_metadata_apps "${stack_dir}"; then
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|