From 062391ff28fd01b1a7a40744509919a537700779 Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Wed, 4 Sep 2024 13:11:41 -0700 Subject: [PATCH] Update README and deploy script for stacks --- homelab/stacks/README.md | 23 +++++++++++++++++++---- homelab/stacks/deploy.sh | 16 +++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/homelab/stacks/README.md b/homelab/stacks/README.md index 3476a53b..3d789b29 100644 --- a/homelab/stacks/README.md +++ b/homelab/stacks/README.md @@ -1,16 +1,15 @@ # Stacks: Atomic Services using Docker Compose -### Get a Stack (from source with Git) +### Build a Stack (from source with Git) ```sh -STACK=ai +STACK=gitea-runner mkdir -p $HOME/stacks/$STACK git clone -n --depth=1 --filter=tree:0 https://gitea.jafner.tools/Jafner/Jafner.net.git /tmp/repo cd /tmp/repo git sparse-checkout set --no-cone homelab/stacks/$STACK git checkout -mv homelab/stacks/$STACK $HOME/stacks/ -cd $HOME/stacks/$STACK +zip -r $STACK.zip homelab/stacks/$STACK rm -rf /tmp/repo ``` @@ -20,3 +19,19 @@ This will clone the stack from the repo into a tmp directory, extract the stack - This *does not* bring up the stack. - This *does* require Git. +### Pull a Stack (from source with Git) +```sh +STACK=books +mkdir -p /tmp/stack/$STACK +git clone -n --depth=1 --filter=tree:0 https://gitea.jafner.tools/Jafner/Jafner.net.git /tmp/stack/$STACK && cd /tmp/stack/$STACK +git sparse-checkout set --no-cone homelab/stacks/$STACK && git checkout +mv homelab/stacks/$STACK $HOME/stacks/ +cd $HOME/stacks/$STACK && rm -rf /tmp/stack/$STACK + +echo -e "$(cat $HOME/.age/$HOSTNAME.host.key)\n$AGE_DEPLOY_KEY" > $HOME/.age/combined.key +export SOPS_AGE_KEY_FILE="$HOME/.age/combined.key" +for file in $(find . -type f); do + sops decrypt -i --input-type json "$file" 2>/dev/null && echo "Decrypted $file" +done +``` + diff --git a/homelab/stacks/deploy.sh b/homelab/stacks/deploy.sh index 96bd83ea..84447b64 100644 --- a/homelab/stacks/deploy.sh +++ b/homelab/stacks/deploy.sh @@ -10,8 +10,14 @@ mv -f homelab/stacks/$STACK/* $HOME/stacks/$STACK/ mv -f homelab/stacks/$STACK/.* $HOME/stacks/$STACK/ cd $HOME/stacks/$STACK && rm -rf /tmp/stack/$STACK -echo -e "$(cat $HOME/.age/$HOSTNAME.host.key)\n$AGE_DEPLOY_KEY" > $HOME/.age/combined.key -export SOPS_AGE_KEY_FILE="$HOME/.age/combined.key" -for file in $(find . -type f); do - sops decrypt -i --input-type json "$file" 2>/dev/null && echo "Decrypted $file" -done +if [[ -z $AGE_DEPLOY_KEY ]]; then + echo "Error: AGE_DEPLOY_KEY not set. Cannot decrypt secrets." +else + echo -e "$(cat $HOME/.age/$HOSTNAME.host.key)\n$AGE_DEPLOY_KEY" > $HOME/.age/combined.key + export SOPS_AGE_KEY_FILE="$HOME/.age/combined.key" + for file in $(find . -type f); do + sops decrypt -i --input-type json "$file" 2>/dev/null && echo "Decrypted $file" + done +fi + +docker compose -f $HOME/stacks/$STACK/docker-compose.yml pull \ No newline at end of file