Compare commits

..

4 Commits

Author SHA1 Message Date
f1d29c5ed1 Start of makefile 2022-10-18 00:19:46 +02:00
365fc9405d Example config 2022-10-18 00:19:05 +02:00
a51a89a968 Adjusted gitignore 2022-10-18 00:14:56 +02:00
414473c8c8 source -> database & config templating 2022-10-18 00:14:35 +02:00
7 changed files with 122 additions and 0 deletions

8
.gitignore vendored
View File

@ -21,3 +21,11 @@
# Go workspace file
go.work
# Ignore cached files
src/*/cache/*
# Ignore pycache bullshit
config/__pycache__
# Template generated files:
src/docker-compose.yml

17
config/config.py Normal file
View File

@ -0,0 +1,17 @@
# Checkout the Variables bellow
# Special lines:
# # => Comented lines, they get ignored by python
# #- => Optional Configuration lines
# Variables
## Database Variables
db = {}
#- db['root_pw'] = 'RootPassWord'
db['enabled'] = True
db['user'] = 'DBUser'
db['user_pw'] = 'DBUserPassWord'
db['db'] = 'Database Name'
#- db['data_path_mysql'] = '/var/lib/mysql'
#- db['data_path_mysql_backup'] = '/var/lib/mysql'
#- db['port'] = 3306

0
config/configfiles.py Normal file
View File

27
config/template.py Executable file
View File

@ -0,0 +1,27 @@
from jinja2 import Environment, FileSystemLoader
import config
import os
# Static Variables
templates_directory = 'src/templates'
# Load Templates Directory
file_loader = FileSystemLoader(templates_directory)
env = Environment(loader=file_loader)
# Template everyfile
def template(filename, target_path):
# Load Template
template = env.get_template(filename)
# Render Output
content = template.render(db=config.db)
# Write Template to file
filename_without_ext = os.path.splitext(filename)[0]
cooked_file = target_path+filename_without_ext
file = open(cooked_file, 'w')
file.write(content)
file.close()
# Render the templates:
## Create Docker-Compose
template("docker-compose.yml.j2", "./src/")

37
makefile Normal file
View File

@ -0,0 +1,37 @@
# Make all
all: db api ui
# Start everything
start: db-start api-start ui-start
# Stop everything
stop: ui-stop api-stop db-stop
# Setup Database
db: db-init db-start
db-init:
db-start:
db-stop:
# Setup API
api: api-start
api-start:
api-stop:
# Setup UI
ui: ui-start
ui-start:
ui-stop:
# Regenerate configs
config: config-regenerate
config-regenerate:
python config/template.py

0
src/db/init.sql Normal file
View File

View File

@ -0,0 +1,33 @@
# Do not adjust this file
version: '3.1'
services:
{% if db.enabled == true %}
ngx_mgmt_db:
image: mariadb:latest
restart: always
environment:
{% if db.root_pw is defined %}
MARIADB_ROOT_PASSWORD: {{ db.root_pw }}
{% endif %}
MARIADB_USER: {{ TMPL_DB_USER }}
MARIADB_PASSWORD: {{ TMPL_DB_USER_PW }}
MARIADB_DATABASE: {{ TMPL_DB_DB }}
volumes:
{% if db.data_path_mysql is defined %}
- {{ data_path_mysql }}:/var/lib/mysql
{% else %}
- ./src/db/cache/mysql_data:/var/lib/mysql
{% endif %}
{% if db.data_path_mysql_backup is defined %}
- {{ data_path_mysql_backup }}:/var/lib/mysql
{% else %}
- ./src/db/cache/mysql_backup:/var/lib/mysql
{% endif %}
ports:
{% if db.port is defined %}
- {{ port }}:3306
{% else %}
- 3306:3306
{% endif %}
{% endif %}