From 43a10f5f35a3078cab8bc9d568cac47ab46a3962 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 16 Feb 2020 10:58:07 +0100 Subject: [PATCH] :sparkles: Add hook up with the MySQL service --- vscode/Dockerfile | 1 + vscode/config.json | 2 +- vscode/rootfs/etc/cont-init.d/mysql.sh | 27 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 vscode/rootfs/etc/cont-init.d/mysql.sh diff --git a/vscode/Dockerfile b/vscode/Dockerfile index 6dbe607..a51162a 100755 --- a/vscode/Dockerfile +++ b/vscode/Dockerfile @@ -29,6 +29,7 @@ RUN \ git=1:2.17.1-1ubuntu0.5 \ iputils-ping=3:20161105-1ubuntu3 \ locales=2.27-3ubuntu1 \ + mariadb-client=1:10.1.44-0ubuntu0.18.04.1 \ mosquitto-clients=1.4.15-2ubuntu0.18.04.3 \ net-tools=1.60+git20161116.90da8a0-1ubuntu1 \ nmap=7.60-1ubuntu5 \ diff --git a/vscode/config.json b/vscode/config.json index 2d120df..36eaac7 100755 --- a/vscode/config.json +++ b/vscode/config.json @@ -15,7 +15,7 @@ "hassio_role": "manager", "homeassistant_api": true, "map": ["config:rw", "ssl:rw", "addons:rw", "share:rw", "backup:rw"], - "services": ["mqtt:want"], + "services": ["mysql:want", "mqtt:want"], "options": { "packages": [], "init_commands": [], diff --git a/vscode/rootfs/etc/cont-init.d/mysql.sh b/vscode/rootfs/etc/cont-init.d/mysql.sh new file mode 100644 index 0000000..e91f107 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/mysql.sh @@ -0,0 +1,27 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: Visual Studio Code +# Pre-configures the MySQL clients, if the service is available +# ============================================================================== +declare host +declare password +declare port +declare username + +host=$(bashio::services "mysql" "host") +if bashio::var.has_value "${host}"; then + password=$(bashio::services "mysql" "password") + port=$(bashio::services "mysql" "port") + username=$(bashio::services "mysql" "username") + + mkdir -p /root/.config + { + echo "[client]" + echo "host=${host}" + echo "password=\"${password}\"" + echo "port=${port}" + echo "user=\"${username}\"" + } > /etc/mysql/conf.d/service.cnf +else + bashio::log.info "The above error can be ignored if you don't have MariaDB installed" +fi