This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
name: Build and Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
# schedule:
|
||||||
|
# - cron: '0 0 * * *'
|
||||||
|
# timezone: 'Europe/Berlin'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: self-hosted
|
||||||
|
|
||||||
|
container:
|
||||||
|
image: ghcr.io/gohugoio/hugo:latest
|
||||||
|
options: --user root
|
||||||
|
env:
|
||||||
|
HUGO_ENVIRONMENT: production
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true # Required if your theme is a Git submodule
|
||||||
|
fetch-depth: 0 # Hugo uses full history for .GitInfo and lastmod
|
||||||
|
|
||||||
|
- name: Install Sass
|
||||||
|
run: |
|
||||||
|
npm install sass
|
||||||
|
|
||||||
|
- name: Build site
|
||||||
|
run: hugo --minify
|
||||||
|
|
||||||
|
- name: Install rsync and openssh-client
|
||||||
|
run: |
|
||||||
|
apk add --no-cache rsync openssh-client
|
||||||
|
# Hugo's official image is Alpine-based; use apk.
|
||||||
|
# If a Debian-based Hugo image is used, swap to:
|
||||||
|
# apt-get update && apt-get install -y rsync openssh-client
|
||||||
|
|
||||||
|
- name: Set up SSH key
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
|
||||||
|
chmod 644 ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Deploy via rsync
|
||||||
|
run: |
|
||||||
|
rsync -avz --delete \
|
||||||
|
-e "ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=yes" \
|
||||||
|
public/ \
|
||||||
|
${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/{{ secrets.DEPLOY_SUBDIR }}
|
||||||
@@ -24,5 +24,54 @@ docker compose up -d server
|
|||||||
docker compose exec server new content/posts/2024-07-31-my-new-blog-post.md
|
docker compose exec server new content/posts/2024-07-31-my-new-blog-post.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## CI/CD mit Gitea Actions
|
||||||
|
|
||||||
|
Ab 6/2026.
|
||||||
|
|
||||||
|
With a little help from Claude.
|
||||||
|
|
||||||
|
Damit die "Action" die Dateien auf den Webserver übertragen
|
||||||
|
kann, muss die Datei `/home/daniel/.ssh/authorized_keys`
|
||||||
|
folgende Zeile enthalten:
|
||||||
|
|
||||||
|
```plain
|
||||||
|
command="/usr/local/bin/rrsync -wo /var/docker-data/nginx/www",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding ssh-ed25519 AAA... gitea-deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
Wobei oben die Stelle mit `AAA...` durch den öfftl. Schlüssel des SSH-Keys
|
||||||
|
ersetzt werden muss.
|
||||||
|
|
||||||
|
In der Gitea-Weboberfläche müssen die "secrets" hinterlegt werden,
|
||||||
|
zu finden unter `Repository > Einstellungen > Actions > Secrets`.
|
||||||
|
|
||||||
|
- `DEPLOY_HOST=bovender.de`
|
||||||
|
- `DEPLOY_USER=daniel`
|
||||||
|
- `DEPLOY_KNOWN_HOSTS=[1]`
|
||||||
|
- `DEPLOY_SSH_KEY=[2]`
|
||||||
|
- `DEPLOY_SUBDIR=bovender`
|
||||||
|
|
||||||
|
Die Ziffer `[1]` ist zu ersetzen mit der Ausgabe von:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh-keyscan bovender.de
|
||||||
|
```
|
||||||
|
|
||||||
|
Die Ziffer `[2]` ist zu ersetzen mit dem privaten
|
||||||
|
Schlüssel des SSH-Keys. Den Key erstellt man mit
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh-keygen -t ed25519 -C "gitea-deploy" -f ~/.ssh/gitea_deploy -N ""
|
||||||
|
```
|
||||||
|
|
||||||
|
Es ist wichtig, das `DEPLOY_SUBDIR` zu definieren, hierbei handelt es sich
|
||||||
|
dann per `rrsync`-Beschränkung um ein Unterverzeichnis von `/var/docker-data/nginx/www`.
|
||||||
|
|
||||||
|
## Action trigger
|
||||||
|
|
||||||
|
Die Gitea Action wird bei jedem Push auf Main
|
||||||
|
ausgelöst sowie jeden Tag um Mitternach deutscher
|
||||||
|
Zeit und auf Knopfdruck in der Gitea-Oberfläche (durch
|
||||||
|
den Trigger `workflow_dispatch`)
|
||||||
|
|
||||||
[hermit-v2]: https://github.com/1bl4z3r/hermit-V2
|
[hermit-v2]: https://github.com/1bl4z3r/hermit-V2
|
||||||
[Hugo]: https:/gohugo.io
|
[Hugo]: https:/gohugo.io
|
||||||
Reference in New Issue
Block a user