[AB-152] adding optional parameter to deploy config script in order to deploy template config

This commit is contained in:
Sheldan
2020-11-02 15:42:43 +01:00
parent a5b2e40c6b
commit c60cdb9d98

View File

@@ -6,9 +6,15 @@ import liquibase_deploy
from zipfile import ZipFile
import sys
if len(sys.argv) != 3:
if len(sys.argv) < 3:
sys.exit('Wrong amount of parameters.')
use_folder = False
local_folder = None
if len(sys.argv) == 4:
use_folder = True
local_folder = sys.argv[3]
deploy_templates = sys.argv[1] == 'yes'
deploy_liquibase = sys.argv[2] == 'yes'
@@ -20,43 +26,46 @@ class DbConfig:
self.user = os.getenv('DB_USER')
self.password = os.getenv('DB_PASS')
postgres_driver_path = os.getenv('POSTGRES_DRIVER')
liquibase_path = os.getenv('LIQUIBASE_PATH')
with open('artifact_versions.json') as artifact_config_file:
artifact_config = json.load(artifact_config_file)
db_config = DbConfig()
if not use_folder:
postgres_driver_path = os.getenv('POSTGRES_DRIVER')
liquibase_path = os.getenv('LIQUIBASE_PATH')
with open('artifact_versions.json') as artifact_config_file:
artifact_config = json.load(artifact_config_file)
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("liquibase.properties.j2")
if deploy_liquibase:
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("liquibase.properties.j2")
for liquibase_artifact in artifact_config['liquibase_artifacts']:
zip_file = liquibase_artifact['zip']
target_folder = '/liquibase-zips/' + zip_file
with ZipFile('liquibase-zips/' + zip_file + '.zip', 'r') as liquibase_zip:
liquibase_zip.extractall(target_folder)
change_log_file = liquibase_artifact['file']
liquibase_config_text = template.render(change_log_file=change_log_file, db_host=db_config.host, db_port=db_config.port,
db_database=db_config.database, db_user=db_config.user, db_password=db_config.password, postgres_driver_path=postgres_driver_path)
property_path = target_folder + '/liquibase.properties'
with open(property_path, 'w') as liquibase_target_properties:
liquibase_target_properties.write(liquibase_config_text)
liquibase_deploy.deploy_liquibase(zip_file, property_path, liquibase_path)
if deploy_liquibase:
if deploy_templates:
for template_artifact in artifact_config['template_artifacts']:
with ZipFile('templates/' + template_artifact + '.zip', 'r') as template_zip:
template_zip.extractall(template_artifact)
templates_deploy.deploy_template_folder(db_config, template_artifact)
for liquibase_artifact in artifact_config['liquibase_artifacts']:
zip_file = liquibase_artifact['zip']
target_folder = '/liquibase-zips/' + zip_file
with ZipFile('liquibase-zips/' + zip_file + '.zip', 'r') as liquibase_zip:
liquibase_zip.extractall(target_folder)
change_log_file = liquibase_artifact['file']
liquibase_config_text = template.render(change_log_file=change_log_file, db_host=db_config.host, db_port=db_config.port,
db_database=db_config.database, db_user=db_config.user, db_password=db_config.password, postgres_driver_path=postgres_driver_path)
property_path = target_folder + '/liquibase.properties'
with open(property_path, 'w') as liquibase_target_properties:
liquibase_target_properties.write(liquibase_config_text)
liquibase_deploy.deploy_liquibase(zip_file, property_path, liquibase_path)
for template_artifact in artifact_config['translation_artifacts']:
with ZipFile('translations/' + template_artifact + '.zip', 'r') as template_zip:
template_zip.extractall(template_artifact)
templates_deploy.deploy_template_folder(db_config, template_artifact)
if deploy_templates:
for template_artifact in artifact_config['template_artifacts']:
with ZipFile('templates/' + template_artifact + '.zip', 'r') as template_zip:
template_zip.extractall(template_artifact)
templates_deploy.deploy_template_folder(db_config, template_artifact)
for template_artifact in artifact_config['translation_artifacts']:
with ZipFile('translations/' + template_artifact + '.zip', 'r') as template_zip:
template_zip.extractall(template_artifact)
templates_deploy.deploy_template_folder(db_config, template_artifact)
if use_folder:
templates_deploy.deploy_template_folder(db_config, local_folder)