mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
[AB-155] removing ansible dependency from installer, restructuring deployment container to be packaged with the respective versions, removing build for docker container from maven, for now
fixing liquibase setup for feature mode
This commit is contained in:
@@ -2,7 +2,6 @@ FROM ubuntu as base
|
||||
MAINTAINER Sheldan
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
ARG maven_version=3.6.3
|
||||
ARG liquibase_version=3.8.9
|
||||
ARG postgres_driver_version=42.2.14
|
||||
# Install prerequisities for Ansible
|
||||
@@ -26,12 +25,17 @@ RUN mkdir -p /postgres \
|
||||
# Install ansible and required libraries
|
||||
|
||||
FROM python:3.7-slim-buster as runtime
|
||||
RUN pip3 install --no-cache-dir ansible psycopg2-binary SQLAlchemy lxml
|
||||
RUN apt-get update && apt-get install unzip && rm -rf /var/lib/apt/lists/
|
||||
RUN pip3 install --no-cache-dir psycopg2-binary SQLAlchemy jinja2
|
||||
COPY --from=base /liquibase /liquibase
|
||||
COPY --from=base /postgres /postgres
|
||||
COPY --from=base /java /java
|
||||
ENV JAVA_HOME=/java/jre
|
||||
ADD resources/ /
|
||||
ADD python/ /python
|
||||
ADD wrapper/ /
|
||||
RUN chmod +x /deploy.sh
|
||||
ENTRYPOINT ["/deploy.sh"]
|
||||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
|
||||
RUN chmod +x /wait
|
||||
|
||||
ENV LIQUIBASE_PATH=/liquibase
|
||||
ENV POSTGRES_DRIVER=/postgres/driver.jar
|
||||
CMD /wait && /deploy.sh
|
||||
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
|
||||
|
||||
def deploy_liquibase(folder, change_log_file, liquibase_path):
|
||||
stream = os.popen('cd liquibase-zips/%s && %s/liquibase --defaultsFile=%s --liquibaseSchemaName=abstracto --liquibaseCatalogName=abstracto --logLevel=info update' % (folder, liquibase_path, change_log_file))
|
||||
output = stream.read()
|
||||
print(output)
|
||||
@@ -0,0 +1,62 @@
|
||||
import json
|
||||
import os
|
||||
import jinja2
|
||||
import templates_deploy
|
||||
import liquibase_deploy
|
||||
from zipfile import ZipFile
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit('Wrong amount of parameters.')
|
||||
|
||||
deploy_templates = sys.argv[1] == 'yes'
|
||||
deploy_liquibase = sys.argv[2] == 'yes'
|
||||
|
||||
class DbConfig:
|
||||
def __init__(self):
|
||||
self.host = os.getenv('DB_HOST')
|
||||
self.port = os.getenv('DB_PORT')
|
||||
self.database = os.getenv('DB_NAME')
|
||||
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()
|
||||
|
||||
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
template = templateEnv.get_template("liquibase.properties.j2")
|
||||
|
||||
if deploy_liquibase:
|
||||
|
||||
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_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)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
changeLogFile: {{ change_log_file }}
|
||||
driver: org.postgresql.Driver
|
||||
url: jdbc:postgresql://{{ db_host }}:{{ db_port }}/{{ db_database }}
|
||||
username: {{ db_user }}
|
||||
password: {{ db_password }}
|
||||
classpath: {{ postgres_driver_path }}
|
||||
@@ -0,0 +1,29 @@
|
||||
import sqlalchemy as db
|
||||
import glob
|
||||
import os
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
|
||||
def deploy_template_folder(db_config, folder):
|
||||
engine = db.create_engine('postgres://%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("Given path was not a folder. Exiting.")
|
||||
exit(1)
|
||||
|
||||
files = glob.glob(folder + '/**/*.ftl', recursive=True)
|
||||
templates = []
|
||||
for file in files:
|
||||
with open(file) as template_file:
|
||||
file_content = template_file.read()
|
||||
template_key = os.path.splitext(os.path.basename(file))[0]
|
||||
template = {'key': template_key, 'content': file_content}
|
||||
templates.append(template)
|
||||
|
||||
print('Deploying %s templates from folder %s' % (len(templates), folder))
|
||||
|
||||
with engine.connect() as con:
|
||||
statement = text("""INSERT INTO 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)
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
DEPLOY_LIQUIBASE=no
|
||||
DEPLOY_TEMPLATES=no
|
||||
|
||||
if [ "x$EXECUTE_LIQUIBASE" = 'xtrue' ]; then
|
||||
DEPLOY_LIQUIBASE=yes
|
||||
fi
|
||||
|
||||
if [ "x$EXECUTE_TEMPLATES" = 'xtrue' ]; then
|
||||
DEPLOY_TEMPLATES=yes
|
||||
fi
|
||||
|
||||
if [ "x$EXECUTE_DEPLOYMENT" = 'xtrue' ]; then
|
||||
python3 python/main.py $DEPLOY_TEMPLATES $DEPLOY_LIQUIBASE
|
||||
fi
|
||||
|
||||
echo "Finished deployment"
|
||||
@@ -0,0 +1,6 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
bot:
|
||||
build: deployment
|
||||
image: abstracto_deployment:latest
|
||||
@@ -1,28 +0,0 @@
|
||||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<directory>${project.basedir}/src/main/resources/ansible</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<directory>${project.basedir}/src/main/resources/python</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<directory>${project.basedir}/src/main/resources/wrapper</directory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user