feat: add deploy-static-site as a shared composite action
This commit is contained in:
3 files changed
+138
No files matched your search
@@ -10,6 +10,7 @@ przy pobieraniu akcji, patrz „Dostęp" niżej.
|
||||
| Akcja | Do czego |
|
||||
| --- | --- |
|
||||
| [`build-site-with-hugo`](build-site-with-hugo/) | Hugo w podanej wersji + build do `public/`, opcjonalny serwer dla bramek jakości |
|
||||
| [`deploy-static-site`](deploy-static-site/) | rsync zbudowanej strony do `releases/<id>/` i atomowe `activate` przez `deploy-static` |
|
||||
| [`pnpm-install`](pnpm-install/) | corepack + `pnpm install` z lockfile'a, opcjonalny cache store'a |
|
||||
| [`resolve-buildx-cache`](resolve-buildx-cache/) | `DOCKER_CACHE_*` z runnera → `driver-opts` i refy cache'a dla buildx |
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# deploy-static-site
|
||||
|
||||
Wgrywa zbudowaną stronę statyczną na serwer, na którym klucz CI ma wymuszone polecenie
|
||||
`deploy-static` (repo `prepare-server-for-multi-client`), i atomowo ją aktywuje.
|
||||
|
||||
```yaml
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]"
|
||||
|
||||
# ...
|
||||
- uses: https://git.cierzniak.it/gitea-runner/actions/build-site-with-hugo@v1
|
||||
with:
|
||||
version: ${{ env.HUGO_VERSION }}
|
||||
|
||||
- uses: https://git.cierzniak.it/gitea-runner/actions/deploy-static-site@v1
|
||||
with:
|
||||
ssh-key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
ssh-user: ${{ vars.DEPLOY_SSH_USER }}
|
||||
host: ${{ vars.DEPLOY_HOST }}
|
||||
known-hosts: ${{ vars.DEPLOY_KNOWN_HOSTS }}
|
||||
```
|
||||
|
||||
Kolejno:
|
||||
|
||||
1. Zapisuje klucz, przypięty `known_hosts` i alias `prod` w `~/.ssh`.
|
||||
2. Wpisuje identyfikator wydania do `<path>/version.txt`.
|
||||
3. `rsync` do `releases/<wydanie>/` na serwerze.
|
||||
4. `ssh prod activate <wydanie>` przełącza `current`, a serwer zostawia 3 ostatnie wydania.
|
||||
Potem `ssh prod list` wypisuje je do logu.
|
||||
|
||||
## Wejście
|
||||
|
||||
| Input | Wymagany | Domyślnie | Co to |
|
||||
| --- | --- | --- | --- |
|
||||
| `ssh-key` | tak | — | Klucz prywatny konta strony |
|
||||
| `ssh-user` | tak | — | Konto strony na serwerze (`www-*`) |
|
||||
| `host` | tak | — | Host serwera |
|
||||
| `known-hosts` | tak | — | Przypięta linia `known_hosts`. Nigdy `ssh-keyscan` w CI |
|
||||
| `release` | nie | nazwa refa (tag) | Identyfikator wydania: katalog na serwerze i treść `version.txt` |
|
||||
| `path` | nie | `public` | Katalog ze zbudowaną stroną |
|
||||
|
||||
Outputów nie ma. Pusty któryś z wymaganych inputów kończy krok błędem z jego nazwą. Runner
|
||||
nie egzekwuje `required`, a pusty sekret objawiłby się dopiero niejasnym błędem ssh.
|
||||
|
||||
`deploy-static` przyjmuje identyfikator `[A-Za-z0-9][A-Za-z0-9._-]{0,63}`, więc pasują
|
||||
i tagi CalVer (`2026.11.01`), i SHA. Wycofanie: `ssh … activate <starsze wydanie>`.
|
||||
|
||||
Obraz joba musi mieć `ssh` i `rsync`. Ma je `git.cierzniak.it/gitea-runner/deploy:latest`.
|
||||
|
||||
Bez `--delete` w rsync: ten sam identyfikator wypchnięty drugi raz, np. przepięty tag,
|
||||
dogra pliki do istniejącego katalogu i stare tam zostaną.
|
||||
@@ -0,0 +1,84 @@
|
||||
name: Deploy static site
|
||||
description: >-
|
||||
Ships a built static site to a host guarded by the deploy-static forced command: writes
|
||||
version.txt, rsyncs the files into releases/<release>/ and atomically activates them.
|
||||
|
||||
inputs:
|
||||
ssh-key:
|
||||
description: Private key of the site account; the server pins it to deploy-static.
|
||||
required: true
|
||||
ssh-user:
|
||||
description: Site account on the server (www-*).
|
||||
required: true
|
||||
host:
|
||||
description: Server host name.
|
||||
required: true
|
||||
known-hosts:
|
||||
description: Pinned known_hosts line for the host. Never generate it with ssh-keyscan in CI.
|
||||
required: true
|
||||
release:
|
||||
description: Release id - directory name on the server and content of version.txt. Empty means the pushed ref name (tag).
|
||||
required: false
|
||||
default: ''
|
||||
path:
|
||||
description: Directory with the built site.
|
||||
required: false
|
||||
default: public
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Configure SSH
|
||||
shell: sh
|
||||
env:
|
||||
DEPLOY_SSH_KEY: ${{ inputs.ssh-key }}
|
||||
DEPLOY_SSH_USER: ${{ inputs.ssh-user }}
|
||||
DEPLOY_HOST: ${{ inputs.host }}
|
||||
DEPLOY_KNOWN_HOSTS: ${{ inputs.known-hosts }}
|
||||
# The runner does not enforce `required`, and an empty secret would surface later as a
|
||||
# cryptic ssh error - name what is missing instead.
|
||||
run: |
|
||||
missing=""
|
||||
[ -n "$DEPLOY_SSH_KEY" ] || missing="$missing ssh-key"
|
||||
[ -n "$DEPLOY_SSH_USER" ] || missing="$missing ssh-user"
|
||||
[ -n "$DEPLOY_HOST" ] || missing="$missing host"
|
||||
[ -n "$DEPLOY_KNOWN_HOSTS" ] || missing="$missing known-hosts"
|
||||
if [ -n "$missing" ]; then
|
||||
echo "::error::deploy-static-site: empty inputs:$missing"
|
||||
exit 1
|
||||
fi
|
||||
install -d -m 700 ~/.ssh
|
||||
(umask 077 && printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy)
|
||||
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
||||
cat > ~/.ssh/config <<CONFIG
|
||||
Host prod
|
||||
HostName $DEPLOY_HOST
|
||||
User $DEPLOY_SSH_USER
|
||||
IdentityFile ~/.ssh/deploy
|
||||
IdentitiesOnly yes
|
||||
StrictHostKeyChecking yes
|
||||
CONFIG
|
||||
|
||||
- name: Write version.txt
|
||||
shell: sh
|
||||
env:
|
||||
RELEASE: ${{ inputs.release || github.ref_name }}
|
||||
SITE_PATH: ${{ inputs.path }}
|
||||
run: printf '%s\n' "$RELEASE" > "$SITE_PATH/version.txt"
|
||||
|
||||
# No --delete (the release directory is new) and no -p/-o/-g (activate sets permissions).
|
||||
- name: Upload release
|
||||
shell: sh
|
||||
env:
|
||||
RELEASE: ${{ inputs.release || github.ref_name }}
|
||||
SITE_PATH: ${{ inputs.path }}
|
||||
run: rsync -rlz "$SITE_PATH/" "prod:$RELEASE/"
|
||||
|
||||
- name: Activate release
|
||||
shell: sh
|
||||
env:
|
||||
RELEASE: ${{ inputs.release || github.ref_name }}
|
||||
run: |
|
||||
# shellcheck disable=SC2029 # the id is meant to expand on the CI side
|
||||
ssh prod activate "$RELEASE"
|
||||
ssh prod list
|
||||
Reference in new issue
Block a user