summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-04-03 18:56:17 +0200
committerRory& <root@rory.gay>2024-06-05 15:52:38 +0200
commit18f2b544d29899b440d0307d29199ae8e7e6e578 (patch)
treefdf12080c8d870a205cdacb5043d6092a9b88cc9
parentClarify boot message (diff)
downloadSpacebar-Open-Infrastructure-18f2b544d29899b440d0307d29199ae8e7e6e578.tar.xz
Add auto redeploy
-rw-r--r--modules/auto-redeploy.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/auto-redeploy.nix b/modules/auto-redeploy.nix
new file mode 100644
index 0000000..c49399c
--- /dev/null
+++ b/modules/auto-redeploy.nix
@@ -0,0 +1,30 @@
+{ config, pkgs, lib, secrets, ... }:
+{
+  systemd.services = {
+    "auto-redeploy" = {
+        wantedBy = [ "multi-user.target" ];
+        after = [ "network.target" ];
+        serviceConfig = {
+            ExecStart = ''
+              ${pkgs.curl}/bin/curl -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "System started redeploy."}' ${secrets.webhooks.discord.deploy}
+              cd /Spacebar-Open-Architecture
+              #store current commit hash
+              currentCommit=$(git rev-parse HEAD)
+              #pull from git, and exit if nothing to pull
+              ${pkgs.git}/bin/git pull || exit 0
+              #send commit log to discord
+              ${pkgs.curl}/bin/curl -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "```$(git log --pretty=format:"%h - %s" $currentCommit..HEAD)```"}' ${secrets.webhooks.discord.deploy}
+              #call ./update.sh and store output (including stderr) in a file
+              ./update.sh 2>&1 | tee /tmp/update.log
+              #send the output to discord as a file
+              ${pkgs.curl}/bin/curl -F "file=@/tmp/update.log" -F "filename=update.log" -F "content=System finished redeploy." -H "Content-Type: multipart/form-data" ${secrets.webhooks.discord.deploy}
+              
+              '';
+            #Restart = "never";
+            User = "root";
+        };
+    };
+  };
+}
+
+