mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-26 06:12:56 +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,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