mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-01 15:28:35 +00:00
[AB-XXX] replacing packaged xsd for liquibase with reference
using logging module for db and template deployment updating deployment container dependencies
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
FROM python:3.10.13-alpine3.18
|
||||
FROM python:3.12.2-alpine3.19
|
||||
RUN apk --no-cache add msttcorefonts-installer fontconfig && \
|
||||
update-ms-fonts && \
|
||||
fc-cache -f
|
||||
|
||||
@@ -2,8 +2,8 @@ FROM ubuntu as base
|
||||
MAINTAINER Sheldan
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
ARG liquibase_version=4.3.5
|
||||
ARG postgres_driver_version=42.2.14
|
||||
ARG liquibase_version=4.26.0
|
||||
ARG postgres_driver_version=42.7.1
|
||||
# Install prerequisities for Ansible
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y unzip wget \
|
||||
@@ -24,10 +24,17 @@ RUN mkdir -p /postgres \
|
||||
|
||||
# Install ansible and required libraries
|
||||
|
||||
FROM python:3.7-slim-buster as runtime
|
||||
ARG sql_alchemy_version=1.4.46
|
||||
ARG jinja_version=3.1.2
|
||||
ARG psycopg2_version=2.9.5
|
||||
FROM python:3.12.2-slim-bullseye as runtime
|
||||
ARG sql_alchemy_version=2.0.27
|
||||
ARG jinja_version=3.1.3
|
||||
ARG psycopg2_version=2.9.9
|
||||
# required for psycopg2
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libpq-dev \
|
||||
gcc \
|
||||
g++ \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
RUN pip3 install --no-cache-dir psycopg2-binary==${psycopg2_version} SQLAlchemy==${sql_alchemy_version} jinja2==${jinja_version}
|
||||
COPY --from=base /liquibase /liquibase
|
||||
COPY --from=base /postgres /postgres
|
||||
@@ -36,6 +43,6 @@ ENV JAVA_HOME=/java/jre
|
||||
ADD python /python
|
||||
ADD wrapper /
|
||||
|
||||
ENV LIQUIBASE_PATH=/liquibase
|
||||
ENV ROOT_PATH=/liquibase
|
||||
ENV POSTGRES_DRIVER=/postgres/driver.jar
|
||||
ENTRYPOINT [ "/bin/sh", "/deploy.sh" ]
|
||||
@@ -1,9 +1,9 @@
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import logging
|
||||
|
||||
def deploy_liquibase(folder, change_log_file, liquibase_path, base_path, db_config):
|
||||
print(f'Deploying liquibase of {change_log_file} in folder {folder}')
|
||||
logging.info(f'Deploying liquibase of {change_log_file} in folder {folder}')
|
||||
process_command = [f'{liquibase_path}/liquibase', f'--defaultsFile={change_log_file}', f'--defaultSchemaName={db_config.scheme}', f'--liquibaseSchemaName={db_config.scheme}', f'--liquibaseCatalogName={db_config.scheme}', '--logLevel=info', 'update']
|
||||
process = subprocess.Popen(process_command,
|
||||
cwd=f'{base_path}/liquibase-zips/{folder}',
|
||||
@@ -13,5 +13,5 @@ def deploy_liquibase(folder, change_log_file, liquibase_path, base_path, db_conf
|
||||
process.communicate()
|
||||
code = process.returncode
|
||||
if code != 0:
|
||||
print("Liquibased deployment failed.")
|
||||
logging.error("Liquibased deployment failed.")
|
||||
sys.exit(code)
|
||||
@@ -5,7 +5,10 @@ import re
|
||||
import liquibase_deploy
|
||||
import sys
|
||||
from zipfile import ZipFile
|
||||
import logging
|
||||
|
||||
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
logging.basicConfig(encoding='utf-8', level=logging.INFO, format=FORMAT)
|
||||
|
||||
class DbConfig:
|
||||
def __init__(self):
|
||||
@@ -21,14 +24,14 @@ config_dir = sys.argv[1]
|
||||
|
||||
db_config = DbConfig()
|
||||
postgres_driver_path = os.getenv('POSTGRES_DRIVER', '/postgres/driver.jar')
|
||||
liquibase_path = os.getenv('LIQUIBASE_PATH', '/liquibase')
|
||||
root_path = os.getenv('ROOT_PATH', '/liquibase')
|
||||
script_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
|
||||
print("Loading versions.")
|
||||
logging.info("Loading versions.")
|
||||
with open(config_dir + 'artifact_versions.json') as artifact_config_file:
|
||||
artifact_config = json.load(artifact_config_file)
|
||||
|
||||
print("Loading templates")
|
||||
logging.info("Loading templates")
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
variable_prefix_pattern = re.compile(r'ABSTRACTO_\w+')
|
||||
@@ -39,7 +42,7 @@ for key, val in os.environ.items():
|
||||
|
||||
template = templateEnv.get_template("liquibase.properties.j2")
|
||||
|
||||
print("Starting liquibase deployment")
|
||||
logging.info("Starting liquibase deployment")
|
||||
for liquibase_artifact in artifact_config['liquibase_artifacts']:
|
||||
zip_file = liquibase_artifact['zip']
|
||||
target_folder = config_dir + '/liquibase-zips/' + zip_file
|
||||
@@ -52,4 +55,4 @@ for liquibase_artifact in artifact_config['liquibase_artifacts']:
|
||||
property_path = script_directory + '/templates/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, config_dir, db_config)
|
||||
liquibase_deploy.deploy_liquibase(zip_file, property_path, root_path, config_dir, db_config)
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
|
||||
FROM python:3.7-slim-buster as runtime
|
||||
FROM python:3.12.2-slim-bullseye as runtime
|
||||
MAINTAINER Sheldan
|
||||
ARG sql_alchemy_version=1.4.46
|
||||
ARG psycopg2_version=2.9.5
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libpq-dev \
|
||||
gcc \
|
||||
g++ \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
ARG sql_alchemy_version=2.0.27
|
||||
ARG psycopg2_version=2.9.9
|
||||
RUN pip3 install --no-cache-dir psycopg2-binary==${psycopg2_version} SQLAlchemy==${sql_alchemy_version}
|
||||
ADD python /python
|
||||
ADD wrapper /
|
||||
|
||||
@@ -3,7 +3,10 @@ import os
|
||||
import sys
|
||||
import templates_deploy
|
||||
from zipfile import ZipFile
|
||||
import logging
|
||||
|
||||
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
logging.basicConfig(encoding='utf-8', level=logging.INFO, format=FORMAT)
|
||||
|
||||
use_folder = False
|
||||
local_folder = None
|
||||
@@ -25,12 +28,12 @@ class DbConfig:
|
||||
|
||||
db_config = DbConfig()
|
||||
if not use_folder:
|
||||
print("Not deploying with folder.")
|
||||
print("Loading versions.")
|
||||
logging.info("Not deploying with folder.")
|
||||
logging.info("Loading versions.")
|
||||
with open(config_dir + 'artifact_versions.json') as artifact_config_file:
|
||||
artifact_config = json.load(artifact_config_file)
|
||||
|
||||
print("Deploying templates.")
|
||||
logging.info("Deploying templates.")
|
||||
for template_artifact in artifact_config['template_artifacts']:
|
||||
folder_name = config_dir + '/' + template_artifact + "-templates"
|
||||
os.mkdir(folder_name)
|
||||
@@ -38,7 +41,7 @@ if not use_folder:
|
||||
template_zip.extractall(folder_name)
|
||||
templates_deploy.deploy_template_folder(db_config, folder_name)
|
||||
|
||||
print("Deploying translation templates")
|
||||
logging.info("Deploying translation templates")
|
||||
for template_artifact in artifact_config['translation_artifacts']:
|
||||
folder_name = config_dir + '/' + template_artifact + "-translations"
|
||||
with ZipFile(config_dir + 'translations/' + template_artifact + '.zip', 'r') as template_zip:
|
||||
@@ -46,5 +49,5 @@ if not use_folder:
|
||||
templates_deploy.deploy_template_folder(db_config, folder_name)
|
||||
|
||||
if use_folder:
|
||||
print("Only deploying folder.")
|
||||
logging.info("Only deploying folder.")
|
||||
templates_deploy.deploy_template_folder(db_config, local_folder)
|
||||
@@ -2,13 +2,14 @@ import glob
|
||||
import os
|
||||
import sqlalchemy as db
|
||||
from sqlalchemy.sql import text
|
||||
import logging
|
||||
|
||||
|
||||
def deploy_template_folder(db_config, folder):
|
||||
engine = db.create_engine('postgresql://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
|
||||
|
||||
if not os.path.isdir(folder):
|
||||
print(f'Given path {folder} was not a folder. Exiting.')
|
||||
logging.warn(f'Given path {folder} was not a folder. Exiting.')
|
||||
exit(1)
|
||||
|
||||
files = glob.glob(folder + '/**/*.ftl', recursive=True)
|
||||
@@ -18,14 +19,14 @@ def deploy_template_folder(db_config, folder):
|
||||
file_content = template_file.read()
|
||||
template_key = os.path.splitext(os.path.basename(file))[0]
|
||||
template = {'key': template_key, 'content': file_content}
|
||||
print(f'Deployment template {template}')
|
||||
logging.debug(f'Deployment template {template}')
|
||||
templates.append(template)
|
||||
|
||||
print(f'Deploying {len(templates)} templates from folder {folder}')
|
||||
logging.info(f'Deploying {len(templates)} templates from folder {folder}')
|
||||
|
||||
with engine.connect() as con:
|
||||
with con.begin():
|
||||
statement = text(f"""INSERT INTO {db_config.scheme}template(key, content, last_modified) VALUES(:key, :content, NOW()) ON CONFLICT (key) DO UPDATE SET content = :content""")
|
||||
|
||||
for line in templates:
|
||||
con.execute(statement, **line)
|
||||
con.execute(statement, parameters=line)
|
||||
|
||||
Reference in New Issue
Block a user