Add mariadb addon

This commit is contained in:
pvizeli
2017-06-27 17:59:51 +02:00
parent 9699916301
commit 004a951580
3 changed files with 64 additions and 0 deletions

13
mariadb/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM %%BASE_IMAGE%%
# Add env
ENV LANG C.UTF-8
# Setup base
RUN apk add --no-cache jq mariadb mariadb-client
# Copy data
COPY run.sh /
RUN chmod a+x /run.sh
CMD [ "/run.sh" ]

19
mariadb/config.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "MariaDB",
"version": "0.1",
"slug": "mariadb",
"description": "MariaDB Server is one of the most popular database servers in the world.",
"url": "https://home-assistant.io/addons/mariadb/",
"startup": "before",
"boot": "auto",
"network": {
"tcp/3306": 3306
},
"options": {
"databases": ["homeassistant"]
},
"schema": {
"databases": ["str"]
},
"image": "homeassistant/{arch}-addon-mariadb"
}

32
mariadb/run.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
MARIADB_DATA=/data/databases
DATABASES=$(jq --raw-output ".databases[]" $CONFIG_PATH)
# Init mariadb
if [ ! -d "$MARIADB_DATA" ]; then
echo "[INFO] Create a new mariadb initial system"
mysql_install_db --user=root --datadir="$MARIADB_DATA" > /dev/null
else
echo "[INFO] Use exists mariadb initial system"
fi
# Start mariadb
echo "[INFO] Start MariaDB"
mysqld_safe --datadir="$MARIADB_DATA" --user=root < /dev/null &
MARIADB_PID=$!
# Wait until DB is running
while ! mysql -e 2> /dev/null; do
sleep 1
done
# Init databases
for line in $DATABASES; do
mysql -e "CREATE DATABASE $line;" 2> /dev/null || true
done
wait "$MARIADB_PID"