diff --git a/feed.xml b/feed.xml index dd61b66..9b4c150 100644 --- a/feed.xml +++ b/feed.xml @@ -109,36 +109,38 @@ <p><code>/etc/caddy/Caddyfile</code></p> <pre><code># Global options block { - email you@example.com # &lt;&lt;&lt;&lt; change this - on_demand_tls { - ask http://localhost/check - } + email you@example.com # &lt;&lt;&lt;&lt; CHANGE THIS &lt;&lt;&lt;&lt; + on_demand_tls { + ask http://localhost/check + } } -omitted.webhooks.subdomain.tld { # &lt;&lt;&lt;&lt; change this - reverse_proxy localhost:9000 +# Webhooks +https://webhooks.subdomain.here.tld { &lt;&lt;&lt;&lt; CHANGE THIS &lt;&lt;&lt;&lt; + reverse_proxy localhost:9000 } +# Filter for which SSL certs we will create. Prevents abuse. http://localhost { - handle /check { - root * /var/www - @deny not file /{query.domain}/ - respond @deny 404 - } + handle /check { + root * /var/www + @deny not file /{query.domain}/ + respond @deny 404 + } } +# This automatically handles upgrading http:// requests with a redirect https:// { - tls { - on_demand - } - root /var/www - rewrite /{host}{uri} - # Block files that start with a . - @forbidden { - path /.* - } - respond @forbidden 404 - file_server + tls { + on_demand + } + root /var/www + rewrite /{host}{uri} + @forbidden { + path /.* + } + respond @forbidden 404 + file_server } # Refer to the Caddy docs for more information: @@ -153,225 +155,132 @@ https:// { <code>chown -R joshua:joshua /var/www</code> since the webhooks will run as my login account. </p> -<h3 id="webhook" tabindex="-1"> +<h3 id="webhooks" tabindex="-1"> <a class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#webhook" + href="https://joshua.seigler.net/posts/my-very-own-github-pages/#webhooks" aria-hidden="true" ></a> - Webhook + Webhooks </h3> -<p> - I altered the systemd service definition for <code>webhook</code> so I could - organize the hook definitions into separate files. I also set - <code>User=joshua</code> and <code>Group=joshua</code> so the commands run as - my user instead of root. -</p> -<p><code>sudo mkdir /etc/webhook.conf.d/</code></p> -<p><code>/lib/systemd/system/webhook.service</code></p> -<pre><code class="language-ini">[Unit] -Description=Small server for creating HTTP endpoints (hooks) -Documentation=https://github.com/adnanh/webhook/ -ConditionPathExists=/etc/webhook.conf - -[Service] -ExecStart=/usr/bin/webhook -nopanic -hooks /etc/webhook.conf.d/*.conf - -User=joshua -Group=joshua - -[Install] -WantedBy=multi-user.target -</code></pre> -<p> - If you are debugging your webhook output, consider adding - <code>-debug</code> next to <code>-nopanic</code> for more useful logs. -</p> -<p> - After changing the service definition, reload systemd to run the updated - service: -</p> -<pre><code class="language-bash">sudo systemctl daemon-reload -</code></pre> -<p>Then you can remove the now-unused config file:</p> -<pre><code class="language-bash">sudo rm /etc/webhook.conf -</code></pre> -<p>Here are the three hook definitions:</p> -<h4 id="create-pages" tabindex="-1"> - <a - class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#create-pages" - aria-hidden="true" - ></a> - Create pages -</h4> -<p><code>/etc/webhook.conf.d/create-pages.conf</code></p> -<pre><code class="language-json">[ - { - &quot;id&quot;: &quot;create-pages&quot;, - &quot;execute-command&quot;: &quot;/home/joshua/webhooks/create-pages.sh&quot;, - &quot;command-working-directory&quot;: &quot;/var/www&quot;, - &quot;pass-arguments-to-command&quot;: - [ - { - &quot;source&quot;: &quot;payload&quot;, - &quot;name&quot;: &quot;repository.name&quot; - }, - { - &quot;source&quot;: &quot;payload&quot;, - &quot;name&quot;: &quot;clone_url&quot;, - } - ], - &quot;trigger-rule&quot;: - { - &quot;and&quot;: - [ - { - &quot;match&quot;: - { - &quot;type&quot;: &quot;payload-hmac-sha256&quot;, - &quot;secret&quot;: &quot;(omitted)&quot;, - &quot;parameter&quot;: - { - &quot;source&quot;: &quot;header&quot;, - &quot;name&quot;: &quot;X-Forgejo-Signature&quot; - } - } - } - ] - } - } -] -</code></pre> -<h4 id="remove-pages" tabindex="-1"> - <a - class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#remove-pages" - aria-hidden="true" - ></a> - Remove pages -</h4> -<p><code>/etc/webhook.conf.d/remove-pages.conf</code></p> -<pre><code class="language-json">[ - { - &quot;id&quot;: &quot;remove-pages&quot;, - &quot;execute-command&quot;: &quot;/home/joshua/webhooks/remove-pages.sh&quot;, - &quot;command-working-directory&quot;: &quot;/var/www&quot;, - &quot;pass-arguments-to-command&quot;: - [ - { - &quot;source&quot;: &quot;payload&quot;, - &quot;name&quot;: &quot;repository.name&quot; - }, - ], - &quot;trigger-rule&quot;: - { - &quot;and&quot;: - [ - { - &quot;match&quot;: - { - &quot;type&quot;: &quot;payload-hmac-sha256&quot;, - &quot;secret&quot;: &quot;(omitted)&quot;, - &quot;parameter&quot;: - { - &quot;source&quot;: &quot;header&quot;, - &quot;name&quot;: &quot;X-Forgejo-Signature&quot; - } - } - } - ] - } - } -] -</code></pre> -<h4 id="update-pages" tabindex="-1"> - <a - class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#update-pages" - aria-hidden="true" - ></a> - Update pages -</h4> -<p><code>/etc/webhook.conf.d/update-pages.conf</code></p> -<pre><code class="language-json">[ - { - &quot;id&quot;: &quot;update-pages&quot;, - &quot;execute-command&quot;: &quot;/home/joshua/webhooks/update-pages.sh&quot;, - &quot;command-working-directory&quot;: &quot;/var/www&quot;, - &quot;pass-arguments-to-command&quot;: - [ - { - &quot;source&quot;: &quot;payload&quot;, - &quot;name&quot;: &quot;repository.name&quot; - }, - ], - &quot;trigger-rule&quot;: - { - &quot;and&quot;: - [ - { - &quot;match&quot;: - { - &quot;type&quot;: &quot;payload-hmac-sha256&quot;, - &quot;secret&quot;: &quot;(omitted)&quot;, - &quot;parameter&quot;: - { - &quot;source&quot;: &quot;header&quot;, - &quot;name&quot;: &quot;X-Forgejo-Signature&quot; - } - } - }, - { - &quot;match&quot;: - { - &quot;type&quot;: &quot;value&quot;, - &quot;value&quot;: &quot;refs/heads/gh-pages&quot;, - &quot;parameter&quot;: - { - &quot;source&quot;: &quot;payload&quot;, - &quot;name&quot;: &quot;ref&quot; - } - } - } - ] - } - } -] -</code></pre> -<p>In my home directory I defined all three hook scripts:</p> -<p><code>webhooks/create-pages.sh</code></p> -<pre><code class="language-bash">#!/bin/bash -# parameter 1 is repo name, parameter 2 is clone URL -[[ &quot;$1&quot; == *&quot;/&quot;* ]] &amp;&amp; exit 1; # no slashes in the name -[[ &quot;$1&quot; == *&quot;..&quot;* ]] &amp;&amp; exit 1; # no .. in the name -[[ &quot;$1&quot; == *&quot;*&quot;* ]] &amp;&amp; exit 1; # no wildcards in the name -[ -d &quot;/var/www/$1&quot; ] &amp;&amp; exit 1; # the directory must not exist -cd &quot;/var/www&quot;; -git clone -b gh-pages --single-branch &quot;$2&quot; &quot;$1&quot; || exit 1; -</code></pre> -<p><code>webhooks/remove-pages.sh</code></p> -<pre><code class="language-bash">#!/bin/bash -# parameter 1 is repo name -[[ &quot;$1&quot; == *&quot;/&quot;* ]] &amp;&amp; exit 1; # no slashes in the name -[[ &quot;$1&quot; == *&quot;..&quot;* ]] &amp;&amp; exit 1; # no .. in the name -[[ &quot;$1&quot; == *&quot;*&quot;* ]] &amp;&amp; exit 1; # no wildcards in the name -[ -d &quot;/var/www/$1&quot; ] &amp;&amp; exit 1; # the directory must exist -cd &quot;/var/www&quot;; -rm -rf &quot;/var/www/$1&quot;; -</code></pre> -<p><code>webhooks/update-pages.sh</code></p> -<pre><code class="language-bash">#!/bin/bash -# parameter 1 is repo name -[[ &quot;$1&quot; == *&quot;/&quot;* ]] &amp;&amp; exit 1; # no slashes in the name -[[ &quot;$1&quot; == *&quot;..&quot;* ]] &amp;&amp; exit 1; # no .. in the name -[[ &quot;$1&quot; == *&quot;*&quot;* ]] &amp;&amp; exit 1; # no wildcards in the name -[ -d &quot;/var/www/$1&quot; ] || exit 1; # the directory must exist +<p>In my home directory I defined two hook scripts:</p> +<p><code>~/webhooks/update-pages.sh</code></p> +<pre><code class="language-bash"> +#!/bin/bash +# parameter 1 is repo name, parameter 2 is clone url +[[ &quot;$1&quot; == *&quot;/&quot;* ]] &amp;&amp; exit 1; +[[ &quot;$1&quot; == *&quot;..&quot;* ]] &amp;&amp; exit 1; +[[ &quot;$1&quot; == *&quot;*&quot;* ]] &amp;&amp; exit 1; +if [ -d &quot;/var/www/$1&quot; ]; then + git clone -b gh-pages --single-branch &quot;$2&quot; &quot;$1&quot; || exit 1; + exit; +fi; cd &quot;/var/www/$1&quot;; git fetch origin gh-pages; git reset --hard origin/gh-pages; exit; </code></pre> +<p><code>~/webhooks/remove-pages.sh</code></p> +<pre><code class="language-bash">#!/bin/bash +# parameter 1 is repo name +[[ &quot;$1&quot; == *&quot;/&quot;* ]] &amp;&amp; exit 1; +[[ &quot;$1&quot; == *&quot;..&quot;* ]] &amp;&amp; exit 1; +[[ &quot;$1&quot; == *&quot;*&quot;* ]] &amp;&amp; exit 1; +[ -d &quot;/var/www/$1&quot; ] || exit 1; +cd &quot;/var/www&quot;; +rm -rf &quot;/var/www/$1&quot;; +</code></pre> +<p> + To trigger these hooks I am using <code>webhook</code> which is in the default + Debian repository. +</p> +<p> + Here are the hook definitions: one for creating/updating a site, and one for + deleting. You will need to generate one or two secret values that the server + can use to know that the webhook is authorized to run. I used linux command + <code>uuidgen -r</code> to create mine. Save these values so you can enter + them in Forgejo later. +</p> +<p> + Also make sure to replace your execute-command lines with ones referencing + your username and script paths. +</p> +<p><code>/etc/webhook.conf</code></p> +<pre><code class="language-json">[ + { + &quot;id&quot;: &quot;update-pages&quot;, + &quot;execute-command&quot;: &quot;su joshua /home/joshua/webhooks/update-pages.sh&quot;, + &quot;command-working-directory&quot;: &quot;/var/www&quot;, + &quot;pass-arguments-to-command&quot;: + [ + { + &quot;source&quot;: &quot;payload&quot;, + &quot;name&quot;: &quot;repository.name&quot; + }, + ], + &quot;trigger-rule&quot;: + { + &quot;and&quot;: + [ + { + &quot;match&quot;: + { + &quot;type&quot;: &quot;payload-hmac-sha256&quot;, + &quot;secret&quot;: &quot;(omitted)&quot;, + &quot;parameter&quot;: + { + &quot;source&quot;: &quot;header&quot;, + &quot;name&quot;: &quot;X-Forgejo-Signature&quot; + } + } + }, + { + &quot;match&quot;: + { + &quot;type&quot;: &quot;value&quot;, + &quot;value&quot;: &quot;refs/heads/gh-pages&quot;, + &quot;parameter&quot;: + { + &quot;source&quot;: &quot;payload&quot;, + &quot;name&quot;: &quot;ref&quot; + } + } + } + ] + } + }, + { + &quot;id&quot;: &quot;remove-pages&quot;, + &quot;execute-command&quot;: &quot;su joshua /home/joshua/webhooks/remove-pages.sh&quot;, + &quot;command-working-directory&quot;: &quot;/var/www&quot;, + &quot;pass-arguments-to-command&quot;: + [ + { + &quot;source&quot;: &quot;payload&quot;, + &quot;name&quot;: &quot;repository.name&quot; + }, + ], + &quot;trigger-rule&quot;: + { + &quot;and&quot;: + [ + { + &quot;match&quot;: + { + &quot;type&quot;: &quot;payload-hmac-sha256&quot;, + &quot;secret&quot;: &quot;(omitted)&quot;, + &quot;parameter&quot;: + { + &quot;source&quot;: &quot;header&quot;, + &quot;name&quot;: &quot;X-Forgejo-Signature&quot; + } + } + } + ] + } + } +] +</code></pre> <h3 id="forgejo" tabindex="-1"> <a class="header-anchor" @@ -385,42 +294,10 @@ exit; conditions.<br /> Under my main user settings I set up each webhook: </p> -<h4 id="create-pages-1" tabindex="-1"> +<h4 id="update-pages" tabindex="-1"> <a class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#create-pages-1" - aria-hidden="true" - ></a> - Create pages -</h4> -<p> - Target URL: https:// <em>your domain here</em> /hooks/create-pages<br /> - HTTP Method: <code>POST</code> (the default)<br /> - POST content type: <code>application/json</code> (the default)<br /> - Secret: <em>omitted, use your own</em><br /> - Trigger on: Custom Events &gt; Create<br /> - Branch filter: <code>gh-pages</code> -</p> -<h4 id="remove-pages-1" tabindex="-1"> - <a - class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#remove-pages-1" - aria-hidden="true" - ></a> - Remove pages -</h4> -<p> - Target URL: https:// <em>your domain here</em> /hooks/remove-pages<br /> - HTTP Method: <code>POST</code> (the default)<br /> - POST content type: <code>application/json</code> (the default)<br /> - Secret: <em>omitted, use your own</em><br /> - Trigger on: Custom Events &gt; Repository &gt; Delete<br /> - Branch filter: <code>gh-pages</code> -</p> -<h4 id="update-pages-1" tabindex="-1"> - <a - class="header-anchor" - href="https://joshua.seigler.net/posts/my-very-own-github-pages/#update-pages-1" + href="https://joshua.seigler.net/posts/my-very-own-github-pages/#update-pages" aria-hidden="true" ></a> Update pages @@ -433,6 +310,22 @@ exit; Trigger on: Push events<br /> Branch filter: <code>gh-pages</code> </p> +<h4 id="remove-pages" tabindex="-1"> + <a + class="header-anchor" + href="https://joshua.seigler.net/posts/my-very-own-github-pages/#remove-pages" + aria-hidden="true" + ></a> + Remove pages +</h4> +<p> + Target URL: https:// <em>your domain here</em> /hooks/remove-pages<br /> + HTTP Method: <code>POST</code> (the default)<br /> + POST content type: <code>application/json</code> (the default)<br /> + Secret: <em>omitted, use your own</em><br /> + Trigger on: Custom Events &gt; Repository &gt; Delete<br /> + Branch filter: <code>gh-pages</code> +</p> <h2 id="conclusion" tabindex="-1"> <a class="header-anchor" @@ -456,25 +349,18 @@ exit; > </p> <p> - There is room to make the scripts a little smarter. They don’t handle renaming - very well right now, and a few times I had to log in and manually run my - webhook scripts, like this: -</p> -<pre><code class="language-bash">~/webhooks/create-pages.sh marklink.pages.seigler.net &quot;https://git.apps.seigler.net/joshua/marklink.pages.seigler.net.git&quot; -</code></pre> -<p> - The really important thing is that updates just require pushing to - <code>gh-pages</code> which you can easily do with e.g. + For repos with npm build scripts, I use <a href="https://www.npmjs.com/package/gh-pages" target="_blank" rel="noopener" >gh-pages @ npm</a - >. + > + to push the build to the gh-pages branch and up to the server. </p> <p> - I’m also putting off rolling my own CI server, but I imagine that’s the next - stage here. Stay tuned. + I’m putting off rolling my own CI server, but I imagine that’s the next stage + here. Stay tuned. </p> diff --git a/pagefind/fragment/en_7f9e26e.pf_fragment b/pagefind/fragment/en_7f9e26e.pf_fragment new file mode 100644 index 0000000..1070c8a Binary files /dev/null and b/pagefind/fragment/en_7f9e26e.pf_fragment differ diff --git a/pagefind/index/en_192d582.pf_index b/pagefind/index/en_192d582.pf_index new file mode 100644 index 0000000..038645c Binary files /dev/null and b/pagefind/index/en_192d582.pf_index differ diff --git a/pagefind/pagefind-entry.json b/pagefind/pagefind-entry.json index 9b3de80..777d4c2 100644 --- a/pagefind/pagefind-entry.json +++ b/pagefind/pagefind-entry.json @@ -1 +1 @@ -{"version":"1.3.0","languages":{"en":{"hash":"en_e6a3ea1351","wasm":"en","page_count":26}}} \ No newline at end of file +{"version":"1.3.0","languages":{"en":{"hash":"en_9ba5dde7b9","wasm":"en","page_count":26}}} \ No newline at end of file diff --git a/pagefind/pagefind.en_9ba5dde7b9.pf_meta b/pagefind/pagefind.en_9ba5dde7b9.pf_meta new file mode 100644 index 0000000..eff5ccf Binary files /dev/null and b/pagefind/pagefind.en_9ba5dde7b9.pf_meta differ diff --git a/posts/my-very-own-github-pages/index.html b/posts/my-very-own-github-pages/index.html index dfb7435..a9425cc 100644 --- a/posts/my-very-own-github-pages/index.html +++ b/posts/my-very-own-github-pages/index.html @@ -177,36 +177,38 @@

/etc/caddy/Caddyfile

# Global options block
 {
-		email you@example.com # <<<< change this
-        on_demand_tls {
-                ask http://localhost/check
-        }
+	email you@example.com # <<<< CHANGE THIS <<<<
+	on_demand_tls {
+		ask http://localhost/check
+	}
 }
 
-omitted.webhooks.subdomain.tld { # <<<< change this
-        reverse_proxy localhost:9000
+# Webhooks
+https://webhooks.subdomain.here.tld { <<<< CHANGE THIS <<<<
+	reverse_proxy localhost:9000
 }
 
+# Filter for which SSL certs we will create. Prevents abuse.
 http://localhost {
-        handle /check {
-                root * /var/www
-                @deny not file /{query.domain}/
-                respond @deny 404
-        }
+	handle /check {
+		root * /var/www
+		@deny not file /{query.domain}/
+		respond @deny 404
+	}
 }
 
+# This automatically handles upgrading http:// requests with a redirect
 https:// {
-        tls {
-                on_demand
-        }
-        root /var/www
-        rewrite /{host}{uri}
-        # Block files that start with a .
-        @forbidden {
-                path /.*
-        }
-        respond @forbidden 404
-        file_server
+	tls {
+		on_demand
+	}
+	root /var/www
+	rewrite /{host}{uri}
+	@forbidden {
+		path /.*
+	}
+	respond @forbidden 404
+	file_server
 }
 
 # Refer to the Caddy docs for more information:
@@ -221,207 +223,127 @@ https:// {
         chown -R joshua:joshua /var/www since the webhooks will run
         as my login account.
       

-

- Webhook +

+ + Webhooks

-

- I altered the systemd service definition for webhook so I - could organize the hook definitions into separate files. I also set - User=joshua and Group=joshua so the commands - run as my user instead of root. -

-

sudo mkdir /etc/webhook.conf.d/

-

/lib/systemd/system/webhook.service

-
[Unit]
-Description=Small server for creating HTTP endpoints (hooks)
-Documentation=https://github.com/adnanh/webhook/
-ConditionPathExists=/etc/webhook.conf
-
-[Service]
-ExecStart=/usr/bin/webhook -nopanic -hooks /etc/webhook.conf.d/*.conf
-
-User=joshua
-Group=joshua
-
-[Install]
-WantedBy=multi-user.target
-
-

- If you are debugging your webhook output, consider adding - -debug next to -nopanic for more useful logs. -

-

- After changing the service definition, reload systemd to run the updated - service: -

-
sudo systemctl daemon-reload
-
-

Then you can remove the now-unused config file:

-
sudo rm /etc/webhook.conf
-
-

Here are the three hook definitions:

-

- - Create pages -

-

/etc/webhook.conf.d/create-pages.conf

-
[
-  {
-    "id": "create-pages",
-    "execute-command": "/home/joshua/webhooks/create-pages.sh",
-    "command-working-directory": "/var/www",
-    "pass-arguments-to-command":
-    [
-      {
-        "source": "payload",
-        "name": "repository.name"
-      },
-      {
-        "source": "payload",
-        "name": "clone_url",
-      }
-    ],
-    "trigger-rule":
-    {
-      "and":
-      [
-        {
-          "match":
-          {
-            "type": "payload-hmac-sha256",
-            "secret": "(omitted)",
-            "parameter":
-            {
-              "source": "header",
-              "name": "X-Forgejo-Signature"
-            }
-          }
-        }
-      ]
-    }
-  }
-]
-
-

- - Remove pages -

-

/etc/webhook.conf.d/remove-pages.conf

-
[
-  {
-    "id": "remove-pages",
-    "execute-command": "/home/joshua/webhooks/remove-pages.sh",
-    "command-working-directory": "/var/www",
-    "pass-arguments-to-command":
-    [
-      {
-        "source": "payload",
-        "name": "repository.name"
-      },
-    ],
-    "trigger-rule":
-    {
-      "and":
-      [
-        {
-          "match":
-          {
-            "type": "payload-hmac-sha256",
-            "secret": "(omitted)",
-            "parameter":
-            {
-              "source": "header",
-              "name": "X-Forgejo-Signature"
-            }
-          }
-        }
-      ]
-    }
-  }
-]
-
-

- - Update pages -

-

/etc/webhook.conf.d/update-pages.conf

-
[
-  {
-    "id": "update-pages",
-    "execute-command": "/home/joshua/webhooks/update-pages.sh",
-    "command-working-directory": "/var/www",
-    "pass-arguments-to-command":
-    [
-      {
-        "source": "payload",
-        "name": "repository.name"
-      },
-    ],
-    "trigger-rule":
-    {
-      "and":
-      [
-        {
-          "match":
-          {
-            "type": "payload-hmac-sha256",
-            "secret": "(omitted)",
-            "parameter":
-            {
-              "source": "header",
-              "name": "X-Forgejo-Signature"
-            }
-          }
-        },
-        {
-          "match":
-          {
-            "type": "value",
-            "value": "refs/heads/gh-pages",
-            "parameter":
-            {
-              "source": "payload",
-              "name": "ref"
-            }
-          }
-        }
-      ]
-    }
-  }
-]
-
-

In my home directory I defined all three hook scripts:

-

webhooks/create-pages.sh

-
#!/bin/bash
-# parameter 1 is repo name, parameter 2 is clone URL
-[[ "$1" == *"/"* ]] && exit 1; # no slashes in the name
-[[ "$1" == *".."* ]] && exit 1; # no .. in the name
-[[ "$1" == *"*"* ]] && exit 1; # no wildcards in the name
-[ -d "/var/www/$1" ] && exit 1; # the directory must not exist
-cd "/var/www";
-git clone -b gh-pages --single-branch "$2" "$1" || exit 1;
-
-

webhooks/remove-pages.sh

-
#!/bin/bash
-# parameter 1 is repo name
-[[ "$1" == *"/"* ]] && exit 1; # no slashes in the name
-[[ "$1" == *".."* ]] && exit 1; # no .. in the name
-[[ "$1" == *"*"* ]] && exit 1; # no wildcards in the name
-[ -d "/var/www/$1" ] && exit 1; # the directory must exist
-cd "/var/www";
-rm -rf "/var/www/$1";
-
-

webhooks/update-pages.sh

-
#!/bin/bash
-# parameter 1 is repo name
-[[ "$1" == *"/"* ]] && exit 1; # no slashes in the name
-[[ "$1" == *".."* ]] && exit 1; # no .. in the name
-[[ "$1" == *"*"* ]] && exit 1; # no wildcards in the name
-[ -d "/var/www/$1" ] || exit 1; # the directory must exist
+      

In my home directory I defined two hook scripts:

+

~/webhooks/update-pages.sh

+

+#!/bin/bash
+# parameter 1 is repo name, parameter 2 is clone url
+[[ "$1" == *"/"* ]] && exit 1;
+[[ "$1" == *".."* ]] && exit 1;
+[[ "$1" == *"*"* ]] && exit 1;
+if [ -d "/var/www/$1" ]; then
+	git clone -b gh-pages --single-branch "$2" "$1" || exit 1;
+	exit;
+fi;
 cd "/var/www/$1";
 git fetch origin gh-pages;
 git reset --hard origin/gh-pages;
 exit;
+
+

~/webhooks/remove-pages.sh

+
#!/bin/bash
+# parameter 1 is repo name
+[[ "$1" == *"/"* ]] && exit 1;
+[[ "$1" == *".."* ]] && exit 1;
+[[ "$1" == *"*"* ]] && exit 1;
+[ -d "/var/www/$1" ] || exit 1;
+cd "/var/www";
+rm -rf "/var/www/$1";
+
+

+ To trigger these hooks I am using webhook which is in the + default Debian repository. +

+

+ Here are the hook definitions: one for creating/updating a site, and one + for deleting. You will need to generate one or two secret values that + the server can use to know that the webhook is authorized to run. I used + linux command uuidgen -r to create mine. Save these values + so you can enter them in Forgejo later. +

+

+ Also make sure to replace your execute-command lines with ones + referencing your username and script paths. +

+

/etc/webhook.conf

+
[
+	{
+		"id": "update-pages",
+		"execute-command": "su joshua /home/joshua/webhooks/update-pages.sh",
+		"command-working-directory": "/var/www",
+		"pass-arguments-to-command":
+		[
+			{
+				"source": "payload",
+				"name": "repository.name"
+			},
+		],
+		"trigger-rule":
+		{
+			"and":
+			[
+				{
+					"match":
+					{
+						"type": "payload-hmac-sha256",
+						"secret": "(omitted)",
+						"parameter":
+						{
+							"source": "header",
+							"name": "X-Forgejo-Signature"
+						}
+					}
+				},
+				{
+					"match":
+					{
+						"type": "value",
+						"value": "refs/heads/gh-pages",
+						"parameter":
+						{
+							"source": "payload",
+							"name": "ref"
+						}
+					}
+				}
+			]
+		}
+	},
+	{
+		"id": "remove-pages",
+		"execute-command": "su joshua /home/joshua/webhooks/remove-pages.sh",
+		"command-working-directory": "/var/www",
+		"pass-arguments-to-command":
+		[
+			{
+				"source": "payload",
+				"name": "repository.name"
+			},
+		],
+		"trigger-rule":
+		{
+			"and":
+			[
+				{
+					"match":
+					{
+						"type": "payload-hmac-sha256",
+						"secret": "(omitted)",
+						"parameter":
+						{
+							"source": "header",
+							"name": "X-Forgejo-Signature"
+						}
+					}
+				}
+			]
+		}
+	}
+]
 

Forgejo @@ -431,32 +353,8 @@ exit; conditions.
Under my main user settings I set up each webhook:

-

- - Create pages -

-

- Target URL: https:// your domain here /hooks/create-pages
- HTTP Method: POST (the default)
- POST content type: application/json (the default)
- Secret: omitted, use your own
- Trigger on: Custom Events > Create
- Branch filter: gh-pages -

-

- - Remove pages -

-

- Target URL: https:// your domain here /hooks/remove-pages
- HTTP Method: POST (the default)
- POST content type: application/json (the default)
- Secret: omitted, use your own
- Trigger on: Custom Events > Repository > Delete
- Branch filter: gh-pages -

-

- +

+ Update pages

@@ -467,6 +365,18 @@ exit; Trigger on: Push events
Branch filter: gh-pages

+

+ + Remove pages +

+

+ Target URL: https:// your domain here /hooks/remove-pages
+ HTTP Method: POST (the default)
+ POST content type: application/json (the default)
+ Secret: omitted, use your own
+ Trigger on: Custom Events > Repository > Delete
+ Branch filter: gh-pages +

Conclusion @@ -489,25 +399,18 @@ exit; >

- There is room to make the scripts a little smarter. They don’t handle - renaming very well right now, and a few times I had to log in and - manually run my webhook scripts, like this: -

-
~/webhooks/create-pages.sh marklink.pages.seigler.net "https://git.apps.seigler.net/joshua/marklink.pages.seigler.net.git"
-
-

- The really important thing is that updates just require pushing to - gh-pages which you can easily do with e.g. + For repos with npm build scripts, I use gh-pages @ npm. + > + to push the build to the gh-pages branch and up to the server.

- I’m also putting off rolling my own CI server, but I imagine that’s the - next stage here. Stay tuned. + I’m putting off rolling my own CI server, but I imagine that’s the next + stage here. Stay tuned.