fix env variable load and subst order
This commit is contained in:
@@ -62,9 +62,9 @@ namespace dropshell
|
||||
return services;
|
||||
}
|
||||
|
||||
bool get_bool_variable(const std::map<std::string, std::string> &variables, const std::string &variable_name)
|
||||
bool get_bool_variable(const ordered_env_vars &variables, const std::string &variable_name)
|
||||
{
|
||||
auto it = variables.find(variable_name);
|
||||
auto it = find_var(variables, variable_name);
|
||||
if (it == variables.end())
|
||||
{
|
||||
error << "Variable " << variable_name << " not found in the service " << filenames::template_info_env << std::endl;
|
||||
@@ -97,12 +97,12 @@ namespace dropshell
|
||||
}
|
||||
|
||||
// now set the template name and path.
|
||||
std::map<std::string, std::string> variables;
|
||||
ordered_env_vars variables;
|
||||
if (!get_all_service_env_vars(server_name, service_name, variables))
|
||||
return LocalServiceInfo();
|
||||
|
||||
{ // confirm TEMPLATE is defined.
|
||||
auto it = variables.find("TEMPLATE");
|
||||
auto it = find_var(variables, "TEMPLATE");
|
||||
if (it == variables.end())
|
||||
{
|
||||
error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
@@ -123,7 +123,7 @@ namespace dropshell
|
||||
service.local_template_path = tinfo.local_template_path();
|
||||
|
||||
{ // set the user.
|
||||
auto it = variables.find("SSH_USER");
|
||||
auto it = find_var(variables, "SSH_USER");
|
||||
if (it == variables.end())
|
||||
{
|
||||
error << "SSH_USER variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
@@ -138,7 +138,7 @@ namespace dropshell
|
||||
service.requires_docker_root = get_bool_variable(variables, "REQUIRES_DOCKER_ROOT");
|
||||
|
||||
{ // determine if the service template hash matches the template hash.
|
||||
auto it = variables.find("TEMPLATE_HASH");
|
||||
auto it = find_var(variables, "TEMPLATE_HASH");
|
||||
service.service_template_hash_match = false;
|
||||
|
||||
if (it == variables.end())
|
||||
@@ -221,9 +221,9 @@ namespace dropshell
|
||||
return backups;
|
||||
}
|
||||
|
||||
bool get_all_service_env_vars(const std::string &server_name, const std::string &service_name, std::map<std::string, std::string> &all_env_vars)
|
||||
bool get_all_service_env_vars(const std::string &server_name, const std::string &service_name, ordered_env_vars &all_env_vars)
|
||||
{
|
||||
all_env_vars.clear();
|
||||
clear_vars(all_env_vars);
|
||||
|
||||
if (localpath::service(server_name, service_name).empty() || !fs::exists(localpath::service(server_name, service_name)))
|
||||
{
|
||||
@@ -236,11 +236,11 @@ namespace dropshell
|
||||
{
|
||||
if (!file.empty() && std::filesystem::exists(file))
|
||||
{
|
||||
std::map<std::string, std::string> env_vars;
|
||||
ordered_env_vars env_vars;
|
||||
envmanager env_manager(file);
|
||||
env_manager.load();
|
||||
env_manager.get_all_variables(env_vars);
|
||||
all_env_vars.merge(env_vars);
|
||||
merge_vars(all_env_vars, env_vars);
|
||||
}
|
||||
else
|
||||
warning << "Expected environment file not found: " << file << std::endl;
|
||||
@@ -248,15 +248,15 @@ namespace dropshell
|
||||
|
||||
|
||||
// add in some simple variables first, as others below may depend on/use these in bash.
|
||||
all_env_vars["SERVER"] = server_name;
|
||||
all_env_vars["SERVICE"] = service_name;
|
||||
all_env_vars["DOCKER_CLI_HINTS"] = "false"; // turn off docker junk.
|
||||
set_var(all_env_vars, "SERVER", server_name);
|
||||
set_var(all_env_vars, "SERVICE", service_name);
|
||||
set_var(all_env_vars, "DOCKER_CLI_HINTS", "false"); // turn off docker junk.
|
||||
|
||||
// Load environment files
|
||||
load_env_file(localfile::service_env(server_name, service_name));
|
||||
load_env_file(localfile::template_info_env(server_name, service_name));
|
||||
|
||||
std::string user = all_env_vars["SSH_USER"];
|
||||
std::string user = get_var(all_env_vars, "SSH_USER");
|
||||
if (user.empty())
|
||||
{
|
||||
error << "SSH_USER variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
@@ -266,12 +266,12 @@ namespace dropshell
|
||||
}
|
||||
|
||||
// more additional, these depend on others above.
|
||||
all_env_vars["CONFIG_PATH"] = remotepath(server_name, user).service_config(service_name);
|
||||
all_env_vars["AGENT_PATH"] = remotepath(server_name, user).agent();
|
||||
set_var(all_env_vars, "CONFIG_PATH", remotepath(server_name, user).service_config(service_name));
|
||||
set_var(all_env_vars, "AGENT_PATH", remotepath(server_name, user).agent());
|
||||
|
||||
|
||||
// determine template name.
|
||||
auto it = all_env_vars.find("TEMPLATE");
|
||||
auto it = find_var(all_env_vars, "TEMPLATE");
|
||||
if (it == all_env_vars.end())
|
||||
{
|
||||
error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user