From dbc34766711d62dd770887452f0fd72cb3780107 Mon Sep 17 00:00:00 2001 From: Duty Human Date: Sun, 2 Oct 2022 03:55:50 +0100 Subject: [PATCH] Trivial implementation of automated schema/user creation - just good enough for dev. --- templates/mariadb-entrypoint.sh | 9 +++++++++ templates/mariadb.dockerfile | 6 ++++++ templates/mariadb.tmpl | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 templates/mariadb-entrypoint.sh create mode 100644 templates/mariadb.dockerfile create mode 100644 templates/mariadb.tmpl diff --git a/templates/mariadb-entrypoint.sh b/templates/mariadb-entrypoint.sh new file mode 100644 index 00000000..30473ed8 --- /dev/null +++ b/templates/mariadb-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +/usr/local/bin/docker-gen mariadb.tmpl /tmp/sql.sh +while true; +do + ls -l /tmp/sql.sh + source /tmp/sql.sh + /usr/local/bin/docker-gen --watch mariadb.tmpl /tmp/sql.sh +done diff --git a/templates/mariadb.dockerfile b/templates/mariadb.dockerfile new file mode 100644 index 00000000..96577c75 --- /dev/null +++ b/templates/mariadb.dockerfile @@ -0,0 +1,6 @@ +FROM jwilder/docker-gen AS docker-gen +FROM mariadb:latest +COPY --from=docker-gen /usr/local/bin/docker-gen /usr/local/bin/docker-gen +COPY mariadb-entrypoint.sh / +COPY mariadb.tmpl / +ENTRYPOINT ["/mariadb-entrypoint.sh"] diff --git a/templates/mariadb.tmpl b/templates/mariadb.tmpl new file mode 100644 index 00000000..e02b42a9 --- /dev/null +++ b/templates/mariadb.tmpl @@ -0,0 +1,13 @@ +#!/bin/bash + +{{ range $index, $value := . }} + + {{ if $value.Env.DB_HOST }} +# TODO: Save password from dbserver startup into files then read config +/usr/bin/mysql -h{{$value.Env.DB_HOST}} -ppass -e ' + CREATE USER IF NOT EXISTS `{{$value.Env.DB_USER}}` IDENTIFIED BY "{{$value.Env.DB_PASS}}"; + CREATE SCHEMA IF NOT EXISTS `{{$value.Env.DB_SCHEMA}}`; + GRANT ALL ON `{{$value.Env.DB_SCHEMA}}`.* TO `{{$value.Env.DB_USER}}`@`%`; +' + {{ end }} +{{end}}