Skip to content

Trivial implementation of automated schema/user creation - just good … #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions templates/mariadb-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions templates/mariadb.dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions templates/mariadb.tmpl
Original file line number Diff line number Diff line change
@@ -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}}