Skip to content

Commit eb4c0f4

Browse files
author
Duty Human
committed
Trivial implementation of automated schema/user creation - just good enough for dev.
1 parent cfd2934 commit eb4c0f4

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

templates/mariadb-entrypoint.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
/usr/local/bin/docker-gen mariadb.tmpl /tmp/sql.sh
4+
while true;
5+
do
6+
ls -l /tmp/sql.sh
7+
source /tmp/sql.sh
8+
/usr/local/bin/docker-gen --watch mariadb.tmpl /tmp/sql.sh
9+
done

templates/mariadb.dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM jwilder/docker-gen AS docker-gen
2+
FROM mariadb:latest
3+
COPY --from=docker-gen /usr/local/bin/docker-gen /usr/local/bin/docker-gen
4+
COPY mariadb-entrypoint.sh /
5+
COPY mariadb.tmpl /
6+
ENTRYPOINT ["/mariadb-entrypoint.sh"]

templates/mariadb.tmpl

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
{{ range $index, $value := . }}
4+
5+
{{ if $value.Env.DB_HOST }}
6+
# TODO: Save password from dbserver startup into files then read config
7+
/usr/bin/mysql -h{{$value.Env.DB_HOST}} -ppass -e '
8+
CREATE USER IF NOT EXISTS `{{$value.Env.DB_USER}}` IDENTIFIED BY "{{$value.Env.DB_PASS}}";
9+
CREATE SCHEMA IF NOT EXISTS `{{$value.Env.DB_SCHEMA}}`;
10+
GRANT ALL ON `{{$value.Env.DB_SCHEMA}}`.* TO `{{$value.Env.DB_USER}}`@`%`;
11+
'
12+
{{ end }}
13+
{{end}}

0 commit comments

Comments
 (0)