From 88a771f3c11bdc2a1643e90c18f7f33fc3fb7b7e Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 29 Dec 2020 15:20:26 -0500 Subject: [PATCH] Add volume mount and config.xml in packer image for syncthing --- prod/syncthing-packer/.gitignore | 1 + prod/syncthing-packer/packer/Makefile | 7 ++ .../packer/syncthing-config.xml.template | 119 ++++++++++++++++++ prod/syncthing-packer/packer/syncthing.json | 19 ++- prod/syncthing-packer/terraform/main.tf | 11 +- 5 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 prod/syncthing-packer/.gitignore create mode 100644 prod/syncthing-packer/packer/Makefile create mode 100644 prod/syncthing-packer/packer/syncthing-config.xml.template diff --git a/prod/syncthing-packer/.gitignore b/prod/syncthing-packer/.gitignore new file mode 100644 index 0000000..8131a23 --- /dev/null +++ b/prod/syncthing-packer/.gitignore @@ -0,0 +1 @@ +packer/syncthing-config.xml diff --git a/prod/syncthing-packer/packer/Makefile b/prod/syncthing-packer/packer/Makefile new file mode 100644 index 0000000..42cb620 --- /dev/null +++ b/prod/syncthing-packer/packer/Makefile @@ -0,0 +1,7 @@ +.PHONY: packer + +packer: syncthing-config.xml syncthing.json + packer build syncthing.json + +syncthing-config.xml: syncthing-config.xml.template + sigil -p -f syncthing-config.xml.template > syncthing-config.xml diff --git a/prod/syncthing-packer/packer/syncthing-config.xml.template b/prod/syncthing-packer/packer/syncthing-config.xml.template new file mode 100644 index 0000000..d1748c1 --- /dev/null +++ b/prod/syncthing-packer/packer/syncthing-config.xml.template @@ -0,0 +1,119 @@ + + + basic + + + + + 1 + + + + + + 0 + 0 + 0 + random + false + 0 + 0 + -1 + false + false + false + 25 + .stfolder + false + 0 + 2 + false + standard + + +
dynamic
+ false + false + 0 + 0 + 0 +
+ +
dynamic
+ false + false + 0 + 0 + 0 +
+ +
dynamic
+ false + false + 0 + 0 + 0 +
+ +
dynamic
+ false + false + 0 + 0 + 0 +
+ +
127.0.0.1:8384
+ ${SYNCTHING_USER:?} + ${SYNCTHING_PW:?} + ${SYNCTHING_API_KEY:?} + default +
+ + + default + default + true + true + 21027 + [ff12::8384]:21027 + 0 + 0 + 60 + true + 10 + true + true + 60 + 30 + 10 + -1 + 3 + + https://data.syncthing.net/newdata + false + 1800 + true + 12 + false + 24 + false + 5 + false + 1 + https://upgrades.syncthing.net/meta.json + false + 10 + 0 + ~ + true + 0 + https://crash.syncthing.net/newcrash + true + 180 + 20 + default + auto + 0 + +
diff --git a/prod/syncthing-packer/packer/syncthing.json b/prod/syncthing-packer/packer/syncthing.json index 4142430..9060d81 100644 --- a/prod/syncthing-packer/packer/syncthing.json +++ b/prod/syncthing-packer/packer/syncthing.json @@ -10,19 +10,36 @@ } ], "provisioners": [ + { + "type": "shell", + "inline": [ + "sudo useradd -m syncthing", + "sudo mkdir -p /mnt/syncthing-volume", + "sudo chown syncthing:syncthing /mnt/syncthing-volume", + "sudo echo \"/dev/disk/by-label/syncthing-volume /mnt/syncthing-volume ext4 defaults,nofail,discard,noatime 0 2\" >> /etc/fstab", + "sudo findmnt --verify --verbose" + ] + }, { "type": "file", "source": "syncthing@.service", "destination": "/tmp/syncthing@.service" }, + { + "type": "file", + "source": "syncthing-config.xml", + "destination": "/tmp/syncthing-config.xml" + }, { "type": "shell", "inline": [ - "sudo useradd -m syncthing", "curl -s https://syncthing.net/release-key.txt | sudo apt-key add -", "echo \"deb https://apt.syncthing.net/ syncthing stable\" | sudo tee /etc/apt/sources.list.d/syncthing.list", "sudo apt-get update", "sudo apt-get install -y syncthing", + "sudo mkdir -p /home/syncthing/.config/syncthing", + "sudo mv /tmp/syncthing-config.xml /home/syncthing/.config/syncthing/config.xml", + "sudo chown -R syncthing:syncthing /home/syncthing/.config/syncthing", "sudo mv /tmp/syncthing@.service /etc/systemd/system/syncthing@.service", "sudo systemctl daemon-reload", "sudo systemctl enable syncthing@syncthing" diff --git a/prod/syncthing-packer/terraform/main.tf b/prod/syncthing-packer/terraform/main.tf index ecefe9c..718abfc 100644 --- a/prod/syncthing-packer/terraform/main.tf +++ b/prod/syncthing-packer/terraform/main.tf @@ -5,7 +5,7 @@ provider "digitalocean" { } data "digitalocean_image" "syncthing" { - name = "syncthing-packer-1608562878" + name = "syncthing-packer-1609271401" } data "terraform_remote_state" "do_ssh_keys" { @@ -37,7 +37,10 @@ resource "digitalocean_droplet" "syncthing" { } resource "digitalocean_volume" "syncthing_volume" { - name = "syncthing-volume" - region = "nyc1" - size = 100 + name = "syncthing-volume" + description = "The volume to hold the default Sync folder" + region = "nyc1" + size = 100 + initial_filesystem_label = "syncthing-volume" + initial_filesystem_type = "ext4" }