commit 04d28eb7eddb9173dbba707735f6d68610c06111
parent 37da2fbcf3e55b690c83ad58901f948764642563
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Sun, 6 Sep 2020 15:19:06 +0200
add mariadb lxc packer build
Diffstat:
3 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/config/mariadb-config b/config/mariadb-config
@@ -0,0 +1,12 @@
+# Distribution configuration
+lxc.arch = armv7l
+
+# Container specific configuration
+lxc.include = /usr/share/lxc/config/common.conf
+lxc.hook.start-host = /usr/share/lxc/hooks/systemd-workaround
+
+# Network configuration
+lxc.net.0.type = veth
+lxc.net.0.link = br-lan
+lxc.net.0.flags = up
+lxc.net.0.name = eth0
diff --git a/mariadb-lxc.json b/mariadb-lxc.json
@@ -0,0 +1,43 @@
+{
+ "variables": {
+ "manifest": "manifest.json",
+ "mysql_root_password": "",
+ "mysql_additional_users": "\"user1\", \"user2\", \"user3\"",
+ "mysql_additional_passwords": "\"password1\", \"password2\", \"password3\"",
+ "mysql_additional_hosts": "\"127.0.0.1\", \"localhost\"",
+ "mysql_lxc_container_name": "mariadb"
+ },
+ "sensitive-variables": [
+ "mysql_root_password",
+ "mysql_additional_passwords"
+ ],
+ "builders": [
+ {
+ "type": "lxc",
+ "config_file": "config/mariadb-config",
+ "template_name": "download",
+ "template_parameters": ["--dist", "Debian", "--release", "Buster", "--arch", "armv7l"],
+ "container_name": "{{ user `mysql_lxc_container_name` }}",
+ "output_directory": "output-{{ user `mysql_lxc_container_name` }}"
+ }
+ ],
+ "provisioners": [
+ {
+ "type": "shell",
+ "script": "scripts/mariadb.sh",
+ "environment_vars": [
+ "MYSQL_ROOT_PASSWORD={{ user `mysql_root_password` }}",
+ "MYSQL_ADDITIONAL_USERS={{ user `mysql_additional_users` }}",
+ "MYSQL_ADDITIONAL_PASSWORDS={{ user `mysql_additional_passwords` }}",
+ "MYSQL_ADDITIONAL_HOSTS={{ user `mysql_additional_hosts` }}"
+ ]
+ }
+ ],
+ "post-processors": [
+ {
+ "type": "manifest",
+ "output": "{{user `manifest`}}",
+ "strip_path": true
+ }
+ ]
+}
diff --git a/scripts/mariadb.sh b/scripts/mariadb.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+set -o xtrace
+
+# install mariadb server and tools
+apt install -y mariadb-server mariadb-backup
+
+# MySql cecure install
+
+# remove anonymous user
+mysql -e "DELETE FROM mysql.user WHERE User='';"
+
+# disallow remote access
+mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
+
+# drop test database
+mysql -e "DROP DATABASE IF EXISTS test;"
+
+# set root password and reload privileges
+mysql -e "UPDATE mysql.user SET Password=PASSWORD('$MYSQL_ROOT_PASSWORD') WHERE User='root'; FLUSH PRIVILEGES;"
+
+# configure .my.cnf for root
+cat << EOF > /root/.my.cnf
+[client]
+user = root
+password = $MYSQL_ROOT_PASSWORD
+EOF
+
+# add additional users
+for u in $MYSQL_ADDITIONAL_USERS; do
+ echo $u;
+done;
+for u in $MYSQL_ADDITIONAL_USERS; do
+ echo $u;
+done;