Skip to content

Commit

Permalink
Trivial implementation of automated schema/user creation - just good …
Browse files Browse the repository at this point in the history
…enough for dev.
  • Loading branch information
Duty Human committed Oct 2, 2022
1 parent cfd2934 commit dbc3476
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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}}

0 comments on commit dbc3476

Please sign in to comment.