From 96aa95c4043112dcf4435900f79e99f5065fac76 Mon Sep 17 00:00:00 2001 From: Daniel Meiburg Date: Mon, 13 Feb 2023 01:16:22 +0100 Subject: [PATCH] Update README --- README.md | 40 ++++++++++++++++++++++++++++++++++------ post-receive | 9 ++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 74beaeb..1b48452 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,42 @@ # Container This project contains my personal docker compose configurations. -To use this configuartions the .env files have to be decrypted with -the key@dmeiburg.de key + +#### Operating principle: +Changes in this repo get pushed to a bare repo on dmeiburg.de. +Whenever a push is received a post-receive hook runs. + +The post-receive hook then: +- deploys the code into a working directory +- decrypts .env.gpg files +- restarts stacks with changed compose files + +The env files are encrypted for key@dmeiburg.de and server@dmeiburg.de. + +#### Server setup ```sh -$ gpg -d .env.gpg > .env +# create bare repo on dmeiburg.de +mkdir -p git/container.git +cd git/container.git +git init --bare ``` -To encrypt an .env file the following command is used: +```sh +# install the post receive hook +# whenever the hook is edited, this command has to be used again +scp post-receive dmeiburg:~/git/container/hooks/ +``` + +#### Local setup +```sh +# add bare repos as remote on local machine +git remote add dmeiburg ssh://root@dmeiburg.de:/root/git/container.git +``` + +#### Encrypting .env files + +To encrypt an .env files, the following command is used: ```sh $ gpg -er key@dmeiburg.de -r server@dmeiburg.de .env @@ -18,8 +46,8 @@ $ gpg -er key@dmeiburg.de -r server@dmeiburg.de .env #### Deployment ```bash -git remote add dmeiburg ssh://root@dmeiburg.de:/root/git/container.git git push dmeiburg ``` -Make sure `post-receive` hook is installed in the bare repository. +If necessary the post-receive hook has to be updated via scp. + diff --git a/post-receive b/post-receive index 6a9efc1..974c716 100755 --- a/post-receive +++ b/post-receive @@ -6,16 +6,15 @@ WORK_TREE=~/container # get changed folders -changed=`GIT_WORK_TREE=$WORK_TREE git diff --dirstat=files,0 HEAD | awk '{print $NF}' ` - -[ -n "$changed" ] && echo -e "Changed apps:\n$changed" +changed_apps=`GIT_WORK_TREE=$WORK_TREE git diff --dirstat=files,0 HEAD | awk '{print $NF}' ` +[ -n "$changed_apps" ] && echo -e "Changed apps:\n$changed_apps" # update files in working direcotry GIT_WORK_TREE=~/container git checkout -f # restart changed docker compose stacks -for app in $changed; do - cd $WORK_TREE/$changed +for app in $changed_apps; do + cd $WORK_TREE/$app echo -e "\nUpdate $app" # remove old .env if no .env.gpg is supplied