From ffffd9e15f09f9f7a02824912e7edfc5cf2b0586 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 2 Oct 2025 17:57:40 +0200 Subject: [PATCH] feat(other): deploy styleguide scripts and description (#8935) --- deployment/styleguide/README.md | 74 ++++++++++++++++++++++ deployment/styleguide/deploy-styleguide.sh | 32 ++++++++++ deployment/styleguide/hooks.json.template | 37 +++++++++++ deployment/styleguide/webhook.template | 4 ++ 4 files changed, 147 insertions(+) create mode 100644 deployment/styleguide/README.md create mode 100755 deployment/styleguide/deploy-styleguide.sh create mode 100644 deployment/styleguide/hooks.json.template create mode 100644 deployment/styleguide/webhook.template diff --git a/deployment/styleguide/README.md b/deployment/styleguide/README.md new file mode 100644 index 000000000..581191542 --- /dev/null +++ b/deployment/styleguide/README.md @@ -0,0 +1,74 @@ +# Styleguide Deployment + +You can use the webhook template `webhook.conf.template` and the `deploy-styleguide.sh` script in `deployment/styleguide/` for an automatic deployment from a (github) webhook. + +For this to work follow these steps (using alpine): + +Setup webhook service +```sh +apk add webhook +cp deployment/styleguide/hooks.json.template deployment/styleguide/hooks.json +vi deployment/styleguide/hooks.json +# adjust content of .github/webhooks/hooks.json +# replace all variables accordingly + +# copy webhook service file +cp deployment/styleguide/webhook.template /etc/init.d/webhook +vi /etc/init.d/webhook +# adjust content of /etc/init.d/webhook +chmod +x /etc/init.d/webhook + +service webhook start +rc-update add webhook boot +``` + +Setup nginx +```sh +vi /etc/nginx/http.d/default.conf + +# contents of /etc/nginx/http.d/default.conf +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/localhost/htdocs; + + # The github payload is quite big sometimes, hence those two lines can prevent an reoccurring error message on nginx + client_body_buffer_size 10M; + client_max_body_size 10M; + + location / { + index index.html; + try_files $uri $uri/ /index.html; + } + + location /hooks/ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + + proxy_pass http://127.0.0.1:9000/hooks/; + proxy_redirect off; + } +} +# contents of /etc/nginx/http.d/default.conf + +service nginx reload + +# delete htdocs/ folder to allow creation of symlink +rm -r /var/www/localhost/htdocs +``` + +For the github webhook configure the following: + +| Field | Value | +|------------------------------------------------------|-----------------------------------------------| +| Payload URL | https://styleguide.ocelot.social/hooks/github | +| Content type | application/json | +| Secret | A SECRET | +| SSL verification | Enable SSL verification | +| Which events would you like to trigger this webhook? | Send me everything. | +| Active | [x] | \ No newline at end of file diff --git a/deployment/styleguide/deploy-styleguide.sh b/deployment/styleguide/deploy-styleguide.sh new file mode 100755 index 000000000..12ef0f421 --- /dev/null +++ b/deployment/styleguide/deploy-styleguide.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# Find current directory & configure paths +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) +PROJECT_ROOT=$SCRIPT_DIR/../.. +# by default this will create folders in the project root +DEPLOY_DIR=${1:-test} +BUILD_DIR=$PROJECT_ROOT/styleguide/docs + +# assuming you are already on the right branch +git pull -ff + +# Deploy physical Location +GIT_REF=$(git rev-parse --short HEAD) +DEPLOY_DIR_REF=$DEPLOY_DIR-$GIT_REF + +## Parameter is a proper directory? +if [ -d "$DEPLOY_DIR_REF" ]; then + return "Directory '$DEPLOY_DIR_REF' does already exist" 2>/dev/null || exit 1 +fi + +## Build the project +cd $PROJECT_ROOT/styleguide +rm -R $BUILD_DIR +yarn install +yarn run build + +## Copy files and Sym link to deploy dir +mkdir "$DEPLOY_DIR_REF/" +cp -r $BUILD_DIR/* "$DEPLOY_DIR_REF/" +ln -sfn "$DEPLOY_DIR_REF" $DEPLOY_DIR \ No newline at end of file diff --git a/deployment/styleguide/hooks.json.template b/deployment/styleguide/hooks.json.template new file mode 100644 index 000000000..9e9f75760 --- /dev/null +++ b/deployment/styleguide/hooks.json.template @@ -0,0 +1,37 @@ +[ + { + "id": "github", + "execute-command": "$PROJECT_ROOT/deployment/styleguide/deploy-styleguide.sh", + "pass-arguments-to-command": [ + { + "source": "string", + "name": "$DEPLOY_DIR" + } + ], + "command-working-directory": "$PROJECT_ROOT", + "trigger-rule": { + "and": [ + { + "match": { + "type": "payload-hash-sha1", + "secret": "$WEBHOOK_GITHUB_SECRET", + "parameter": { + "source": "header", + "name": "X-Hub-Signature" + } + } + }, + { + "match": { + "type": "value", + "value": "refs/heads/$WEBHOOK_GITHUB_BRANCH", + "parameter": { + "source": "payload", + "name": "ref" + } + } + } + ] + } + } +] \ No newline at end of file diff --git a/deployment/styleguide/webhook.template b/deployment/styleguide/webhook.template new file mode 100644 index 000000000..2b387ea7c --- /dev/null +++ b/deployment/styleguide/webhook.template @@ -0,0 +1,4 @@ +#!/sbin/openrc-run + +command=webhook +command_args="-hooks $PROJECT_ROOT/deployment/styleguide/hooks.json &" \ No newline at end of file