From 5bd0eb88bc666a38f75d1f4c42a4fd9406b3b277 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 11 Nov 2022 14:01:08 +0100 Subject: [PATCH] Update path handling in docker image Expand readme on script usage. --- README.md | 26 ++++++++++++++----- .../image/resources/functions.sh | 8 +++--- .../image/resources/install.sh | 2 +- valid-config.edn | 3 ++- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9ba4529..8cafb3c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # convention 4 kubernetes: c4k-website + [![Clojars Project](https://img.shields.io/clojars/v/org.domaindrivenarchitecture/c4k-website.svg)](https://clojars.org/org.domaindrivenarchitecture/c4k-website) [![pipeline status](https://gitlab.com/domaindrivenarchitecture/c4k-website/badges/master/pipeline.svg)](https://gitlab.com/domaindrivenarchitecture/c4k-website/-/commits/main) [DeltaChat chat over e-mail](mailto:buero@meissa-gmbh.de?subject=community-chat) | [team@social.meissa-gmbh.de team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org) @@ -8,9 +9,7 @@ Delivering cryogen generated static sites with the push of a few buttons. c4k-website generates configuration files for multiple nginx webservers, and -corresponding cryogen static site generator build containers. This automatically downloads a branch.zip -from a specified gitea API url. You need an authorization token to access the specified gitea user -account. The build container is based on clojure:lein. +corresponding cryogen static site generator build containers. This automatically downloads a `.zip` from a specified gitea API url. You need an authorization token to access the specified gitea user account. The build container is based on clojure:lein. Following the example in valid-config.edn and valid-auth.edn you can add as many websites as you like (provided you have the DNS Routes set up). One set of configmaps, deployment, services etc will be created for each element in the :websites and :auth list. @@ -29,7 +28,7 @@ Click on the image to try out live in your browser: Your input will stay in your browser. No server interaction is required. -## Setup +## Usage You need: @@ -40,11 +39,26 @@ You need: * a kubernetes cluster provisioned by [provs] Before deploying, you need an authorization token, that can be generated in your gitea account. -Then you need a URL that points to: `https://your.gitea.host/api/v1/repos///archive/main.zip`. -Add this to your auth.edn config file and you should be ready to go. +Then you need a URL that points to: `https://your.gitea.host/api/v1/repos///archive/.zip`. Add this to your auth.edn config file and you should be ready to go. Let c4k-website generate your .yaml file and `kubectl apply yourApp.yaml`. Done. +### Script Execution + +Optionally you can specify a sha256sum output generated from a script file that should be executed. +Just add the :sha256-output "\[hash-of-file file.name\]" :key value pair to the respective collection in :websites. See the example in valid-config.edn. + +The script file needs to exist in the `.zip` and path specification to the script file +should be relative to the root of the unzipped folder. + +Scripts can be of any type - as long as an according shebang exists in the first line. + +```bash +sha256sum your-script-file # use output of this call +sha256sum scripts/your-script-file # or this +sha256sum scripts/foo/bar/your-script-file # or this +``` + ## License Copyright © 2022 meissa GmbH diff --git a/infrastructure/c4k-website-build/image/resources/functions.sh b/infrastructure/c4k-website-build/image/resources/functions.sh index b4c0204..f5923cd 100644 --- a/infrastructure/c4k-website-build/image/resources/functions.sh +++ b/infrastructure/c4k-website-build/image/resources/functions.sh @@ -7,12 +7,14 @@ function get-and-unzip-website-data() { } function execute-scripts-when-existing { - if [[ -e $BUILDDIR/$SCRIPTFILE ]] + websitedir=$(ls $BUILDDIR) + if [[ -e $BUILDDIR/$websitedir/$SCRIPTFILE ]] then - checksum="$(sha256sum $BUILDDIR/$SCRIPTFILE)" + checksum="$(sha256sum $BUILDDIR/$websitedir/$SCRIPTFILE)" if [[ "$SHA256SUM" == "$checksum" ]] then - /bin/bash $BUILDDIR/$SCRIPTFILE + chmod +x $BUILDDIR/$websitedir/$SCRIPTFILE + (cd $BUILDDIR; dir=$(ls); cd $dir; ./$SCRIPTFILE) #make sure paths defined in scriptfile are relative to $dir else printf "Provided SHA256 Sum does not match calculated sum. Exiting." printf "Calculated SHA256: $checksum" diff --git a/infrastructure/c4k-website-build/image/resources/install.sh b/infrastructure/c4k-website-build/image/resources/install.sh index 9137061..d5f53f6 100755 --- a/infrastructure/c4k-website-build/image/resources/install.sh +++ b/infrastructure/c4k-website-build/image/resources/install.sh @@ -2,7 +2,7 @@ apt update > /dev/null; -apt install -y unzip rsync +apt install -y unzip rsync imagemagick mkdir /etc/lein/ diff --git a/valid-config.edn b/valid-config.edn index c932bd4..0f17e69 100644 --- a/valid-config.edn +++ b/valid-config.edn @@ -4,7 +4,8 @@ :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"] :gitea-host "gitlab.de" :gitea-repo "repo" - :branchname "main"} + :branchname "main" + :sha256sum-output "123456789ab123cd345de script-file-name.sh"} {:unique-name "example.io" :fqdns ["example.org", "www.example.com"] :gitea-host "finegitehost.net"