packer-builds

Packer Builds for LXC and Libvirt
git clone https://git.in0rdr.ch/packer-builds.git
Log | Files | Refs | README

commit 7d10de44d90efb4b65adbc4e54c911aa0187dbc3
parent 04d28eb7eddb9173dbba707735f6d68610c06111
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sat, 19 Sep 2020 13:26:16 +0200

update mariadb build

Diffstat:
Dconfig/mariadb-config | 12------------
Mmariadb-lxc.json | 29+++++++++++++++--------------
Mscripts/mariadb.sh | 18++++++++++++------
Ascripts/timezone.sh | 13+++++++++++++
4 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/config/mariadb-config b/config/mariadb-config @@ -1,12 +0,0 @@ -# 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 @@ -1,11 +1,11 @@ { "variables": { "manifest": "manifest.json", + "mysql_bind": "127.0.0.1", "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" + "mysql_additional_users": "\"user1\" \"user2\" \"user3\"", + "mysql_additional_passwords": "\"password1\" \"password2\" \"password3\"", + "mysql_additional_hosts": "\"127.0.0.1\" \"localhost\" \"localhost\"" }, "sensitive-variables": [ "mysql_root_password", @@ -14,30 +14,31 @@ "builders": [ { "type": "lxc", - "config_file": "config/mariadb-config", + "name": "mariadb", + "config_file": "config/lxc-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` }}" + "template_parameters": ["--dist", "Debian", "--release", "Buster", "--arch", "armv7l", "--no-validate"] } ], "provisioners": [ { "type": "shell", + "script": "scripts/timezone.sh" + }, + { + "type": "shell", "script": "scripts/mariadb.sh", "environment_vars": [ + "MYSQL_BIND={{ user `mysql_bind` }}", "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 + "type": "shell", + "inline": ["mysql -e \"GRANT ALL PRIVILEGES on db1.* to 'user1'@'localhost';\""] } ] } diff --git a/scripts/mariadb.sh b/scripts/mariadb.sh @@ -5,7 +5,7 @@ set -o nounset set -o xtrace # install mariadb server and tools -apt install -y mariadb-server mariadb-backup +apt-get install -y mariadb-server mariadb-backup # MySql cecure install @@ -29,9 +29,15 @@ 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; +users=($MYSQL_ADDITIONAL_USERS) +hosts=($MYSQL_ADDITIONAL_HOSTS) +passwords=($MYSQL_ADDITIONAL_PASSWORDS) +no_users="${#users[@]}" +for ((i = 0 ; i < $no_users ; i++)); do + mysql -e "CREATE USER '${users[$i]}'@'${hosts[$i]}' IDENTIFIED BY '${passwords[$i]}';" done; + +# bind +#IP_ETH0=$(ip route | grep eth0 | grep src | awk '{print $9}') +#HOSTNAME=LXCNAME works as well, but refers to the container that was built last (nslookup LXCNAME) +sed -i "s/\(bind.*\) 127.0.0.1/\1 $MYSQL_BIND/g" /etc/mysql/mariadb.conf.d/50-server.cnf diff --git a/scripts/timezone.sh b/scripts/timezone.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o xtrace + +# symlink the proper timezone file, +# https://wiki.debian.org/TimeZoneChanges +ln -fs /usr/share/zoneinfo/Europe/Zurich /etc/localtime + +# reconfigure tzdata package to udpate /etc/timezone +dpkg-reconfigure --frontend noninteractive tzdata +cat /etc/timezone