[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 from zipfile import ZipFile
import sys import sys
if len(sys.argv) != 3: if len(sys.argv) < 3:
sys.exit('Wrong amount of parameters.') 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_templates = sys.argv[1] == 'yes'
deploy_liquibase = sys.argv[2] == 'yes' deploy_liquibase = sys.argv[2] == 'yes'
@@ -20,21 +26,22 @@ class DbConfig:
self.user = os.getenv('DB_USER') self.user = os.getenv('DB_USER')
self.password = os.getenv('DB_PASS') self.password = os.getenv('DB_PASS')
db_config = DbConfig()
if not use_folder:
postgres_driver_path = os.getenv('POSTGRES_DRIVER') postgres_driver_path = os.getenv('POSTGRES_DRIVER')
liquibase_path = os.getenv('LIQUIBASE_PATH') liquibase_path = os.getenv('LIQUIBASE_PATH')
with open('artifact_versions.json') as artifact_config_file: with open('artifact_versions.json') as artifact_config_file:
artifact_config = json.load(artifact_config_file) artifact_config = json.load(artifact_config_file)
db_config = DbConfig()
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates") templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
templateEnv = jinja2.Environment(loader=templateLoader) templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("liquibase.properties.j2") template = templateEnv.get_template("liquibase.properties.j2")
if deploy_liquibase: if deploy_liquibase:
for liquibase_artifact in artifact_config['liquibase_artifacts']: for liquibase_artifact in artifact_config['liquibase_artifacts']:
zip_file = liquibase_artifact['zip'] zip_file = liquibase_artifact['zip']
@@ -49,7 +56,7 @@ if deploy_liquibase:
liquibase_target_properties.write(liquibase_config_text) liquibase_target_properties.write(liquibase_config_text)
liquibase_deploy.deploy_liquibase(zip_file, property_path, liquibase_path) liquibase_deploy.deploy_liquibase(zip_file, property_path, liquibase_path)
if deploy_templates: if deploy_templates:
for template_artifact in artifact_config['template_artifacts']: for template_artifact in artifact_config['template_artifacts']:
with ZipFile('templates/' + template_artifact + '.zip', 'r') as template_zip: with ZipFile('templates/' + template_artifact + '.zip', 'r') as template_zip:
template_zip.extractall(template_artifact) template_zip.extractall(template_artifact)
@@ -60,3 +67,5 @@ if deploy_templates:
template_zip.extractall(template_artifact) template_zip.extractall(template_artifact)
templates_deploy.deploy_template_folder(db_config, template_artifact) templates_deploy.deploy_template_folder(db_config, template_artifact)
if use_folder:
templates_deploy.deploy_template_folder(db_config, local_folder)