Skip to content

Commit

Permalink
Update deploy_helper to append config directly
Browse files Browse the repository at this point in the history
Before, we'll read the config file, append the new config, and write it
back to the file. This is not ideal, and this caused the file to be too
long sometimes, and it's hard to read. So we update the script to append
the new config directly to the file. In the `application.properties`,
even with the same key, the last one will be used. Therefore, we can
just append the new config to the file.
  • Loading branch information
Kaiser-Yang committed Sep 20, 2024
1 parent 06ec4e2 commit 3a7fdf6
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,7 @@ def activate_profile(config):
profile_format = f"spring.profiles.active={parse_iterable_into_str(config.profiles, sep=',')}"
log_debug(f"Profile format: {profile_format}")
try:
lines = None
if os.path.exists(application_config_file_path):
with open(application_config_file_path, 'r') as f:
lines = f.readlines()
with open(application_config_file_path, 'w') as f:
if lines:
for line in lines:
if not line.startswith('spring.profiles.active'):
f.write(line)
with open(application_config_file_path, 'a') as f:
f.write(profile_format + '\n')
except Exception as e:
command_checker(1, f"Error: {e}")
Expand All @@ -214,15 +206,7 @@ def config_datasource(config):
datasource_format = "spring.datasource.druid.{0}={1}"
log_debug(f"Datasource format: {datasource_format}")
try:
lines = None
if os.path.exists(application_config_file_path):
with open(application_config_file_path, 'r') as f:
lines = f.readlines()
with open(application_config_file_path, 'w') as f:
if lines:
for line in lines:
if not line.startswith('spring.datasource.druid'):
f.write(line + '\n')
with open(application_config_file_path, 'a') as f:
for key, value in datasource_map_config.items():
f.write(datasource_format.format(key, value) + '\n')
log_debug(f"Datasource config: {datasource_format.format(key, value)}")
Expand Down Expand Up @@ -363,16 +347,7 @@ def write_other_config(config):
"gitRepositorySuffix": "git.repository.suffix",
}
try:
lines = None
if os.path.exists(application_config_file_path):
with open(application_config_file_path, 'r') as f:
lines = f.readlines()
with open(application_config_file_path, 'w') as f:
if lines:
for line in lines:
for _, value in other_config_map.items():
if not line.startswith(value):
f.write(line)
with open(application_config_file_path, 'a') as f:
for key, value in other_config_map.items():
f.write(f"{value}={getattr(config, key)}\n")
log_debug(f"Other config: {value}={getattr(config, key)}")
Expand Down

0 comments on commit 3a7fdf6

Please sign in to comment.