commit 8424960f4a35893b01386245d42a2302cb3950f7
parent 22db9654d5246f59190f4e97e45fcd9362e6a458
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Sat, 19 Sep 2020 14:03:05 +0200
readme
Diffstat:
M | README.md | | | 128 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- |
M | deploy-output.sh | | | 19 | +++++++++++-------- |
2 files changed, 122 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
@@ -1,34 +1,129 @@
# packer-builds
-For lxc on Turris, create a symbolic link:
+This repo contains some snippets to build containers with Packer.
+
+The notes in this Readme do not follow a particular structure, but should help using the scripts.
+
+## Build Instructions
+
+For instance, to build the MariaDB image with debug logs:
```bash
-ln -s /srv/lxc/ /var/lib/lxc
+$ PACKER_LOG=1 packer build mariadb-lxc.json
+```
+
+### Suggested Build Order
+
+The following sequence of builds allows you to spin up a small Nextcloud installation.
+
+**1 Build Mariadb**
+
+```
+PACKER_LOG=1 packer build \
+ -var 'mysql_root_password=123' \
+ -var 'mysql_additional_passwords="456"' \
+ mariadb-nextcloud.json
+
+./deploy-output.sh output-packer-mariadb-nextcloud mariadb
+```
+
+**2 Build Haproxy**
+
+```
+PACKER_LOG=1 packer build haproxy-lxc.json
+./deploy-output.sh output-packer-haproxy haproxy
+```
+
+**3 Nextcloud**
+
+First, start the previously built components:
+```bash
+lxc-start haproxy
+lxc-start mariadb
+```
+
+Afterwards, build the Nextcloud container:
+```bash
+# install nextcloud with the correct database password from step (1)
+PACKER_LOG=1 packer build \
+ -var 'nextcloud_admin_user=admin' \
+ -var 'nextcloud_admin_pass=abc' \
+ -var 'nextcloud_database_pass=456' \
+ -var 'certbot_mail=root@dev.mail' \
+ nextcloud-lxc.json
+
+./deploy-output.sh output-packer-nextcloud nextcloud
+```
+
+## Manual Container Install to LXC Directory
+
+Prepare container name and target config file variables:
+```bash
+name="container_name"
+target_config="/srv/lxc/$name/config"
+mkdir "/srv/lxc/$name"
+```
+
+Extract the rootfs tarball and add the config:
+```bash
+# exctract root fs
+tar -xvf output-lxc/rootfs.tar.gz -C "/srv/lxc/$name"
+
+# copy config
+cp output-lxc/lxc-config $target_config
+
+# adjust rootfs path
+echo -e "\nlxc.rootfs.path = dir:/srv/lxc/$name/rootfs" >> $target_config
```
-(yep, it's [hardcoded](https://github.com/hashicorp/packer/blob/master/builder/lxc/step_lxc_create.go#L22))
-## Build
+The script `deploy-output.sh` automates the above steps. Usage:
+```
+$ ./deploy-output.sh
+ This script deploys templates built with the lxc builder for Packer:
+ https://www.packer.io/docs/builders/lxc.html
+
+ No arguments supplied, required args:
+ PACKER_OUTPUT_DIR: Packer lxc output directory with rootfs and config template
+ CONTAINER_NAME: Name of the new container
+
+ Usage: deploy-output.sh PACKER_OUTPUT_DIR CONTAINER_NAME
+
+ Copy lxc template from PACKER_OUTPUT_DIR to /var/lib/lxc/CONTAINER_NAME
+```
-For instance, to build the MariaDB image on Turris with debug logs:
+## Haproxy stats
```bash
-root@turris:~/packer-builds# PACKER_LOG=1 packer build mariadb-lxc.json
+echo "show stat" | socat stdio /run/haproxy/admin.sock
```
-## Container from Template Tarball
+## Isssues
+### Issue: Missing LXC Library Dir
-http://syed.github.io/post/2015-5-6-LXC-tarball-create/
+```
+Build 'lxc' errored: Error creating container: Command error: touch: /var/lib/lxc/packer-lxc/rootfs/tmp/.tmpfs: No such file or directory
+```
-Installing the template:
+For lxc on Turris, create a symbolic link:
```bash
-curl -L https://raw.githubusercontent.com/in0rdr/salt/fix/lxc/salt/templates/lxc/salt_tarball -o /usr/share/lxc/templates/lxc-tarball
-chmod +x /usr/share/lxc/templates/lxc-tarball
+ln -s /srv/lxc/ /var/lib/lxc
```
+(yep, it's [hardcoded](https://github.com/hashicorp/packer/blob/master/builder/lxc/step_lxc_create.go#L22))
+
-Using the template - make sure that the config file is named "config":
+### Issue: Script not Found
```bash
-mv output-mariadb/{lxc-config,config}
+chmod: cannot access '/tmp/script_9801.sh': No such file or directory
+/bin/sh: 1: /tmp/script_9801.sh: not found
```
-Create the container from the template using a default brideg interface:
+Fix: Retry, most likely a timing bug on repeated builds
+
+
+### Issue: Duplicate Nexctloud User
+```
+Username is invalid because files already exist for this user
+```
+
+Fix: Choose another Nextcloud admin user name
```bash
-root@turris:~/packer-builds# lxc-create -n mariadb -t tarball -- --network_link br-lan --imgtar output-mariadb/rootfs.tar.gz
-```
-\ No newline at end of file
+$ PACKER_LOG=1 packer build -var 'nextcloud_admin_user=admin2' -var 'nextcloud_admin_pass=admin2' nextcloud-lxc.json
+```
diff --git a/deploy-output.sh b/deploy-output.sh
@@ -11,22 +11,25 @@ output="$1"
name="$2"
if [[ $# -eq 0 ]]; then
-cat <<EOF
-This script deploys templates built with the lxc builder for Packer:
-https://www.packer.io/docs/builders/lxc.html
+ cat <<EOF
+ This script deploys templates built with the lxc builder for Packer:
+ https://www.packer.io/docs/builders/lxc.html
-No arguments supplied, required args:
- PACKER_OUTPUT_DIR: Packer lxc output directory with rootfs and config template
- CONTAINER_NAME: Name of the new container
+ No arguments supplied, required args:
+ PACKER_OUTPUT_DIR: Packer lxc output directory with rootfs and config template
+ CONTAINER_NAME: Name of the new container
-Usage: deploy-output.sh PACKER_OUTPUT_DIR CONTAINER_NAME
+ Usage: deploy-output.sh PACKER_OUTPUT_DIR CONTAINER_NAME
-Copy lxc template from PACKER_OUTPUT_DIR to /var/lib/lxc/CONTAINER_NAME
+ Copy lxc template from PACKER_OUTPUT_DIR to /var/lib/lxc/CONTAINER_NAME
EOF
+ exit 1
elif [[ -z "$1" ]]; then
echo "No packer lxc output dir specified"
+ exit 1
elif [[ -z "$2" ]]; then
echo "No packer lxc output dir specified"
+ exit 1
fi