diff --git a/.gitea/requirements-site.txt b/.gitea/requirements-site.txt new file mode 100644 index 0000000..8acb212 --- /dev/null +++ b/.gitea/requirements-site.txt @@ -0,0 +1,2 @@ +mkdocs-material==9.6.14 +mkdocs-same-dir==0.1.3 diff --git a/.gitea/scripts/build-site.sh b/.gitea/scripts/build-site.sh new file mode 100755 index 0000000..5c5387f --- /dev/null +++ b/.gitea/scripts/build-site.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -euo pipefail + +readonly venv_dir="/var/lib/gitea-runner/venvs/site" + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 SOURCE_DIR" >&2 + exit 2 +fi + +source_dir=$(realpath "$1") +requirements_file="${source_dir}/.gitea/requirements-site.txt" + +if [[ ! -f $requirements_file ]]; then + echo "Requirements file not found: ${requirements_file}" >&2 + exit 2 +fi + +mkdir -p "$(dirname "$venv_dir")" +if [[ ! -x "${venv_dir}/bin/python" ]]; then + python3 -m venv "$venv_dir" +fi + +"${venv_dir}/bin/python" -m pip install \ + --disable-pip-version-check \ + --no-input \ + --requirement "$requirements_file" +"${venv_dir}/bin/python" -m pip check +cd "$source_dir" +"${venv_dir}/bin/python" -m mkdocs build --strict diff --git a/.gitea/workflows/deploy-site.yml b/.gitea/workflows/deploy-site.yml index adc7f1f..f93c162 100644 --- a/.gitea/workflows/deploy-site.yml +++ b/.gitea/workflows/deploy-site.yml @@ -31,14 +31,7 @@ jobs: git -C source -c advice.detachedHead=false checkout --detach FETCH_HEAD - name: Build the site strictly - run: | - set -euo pipefail - cd source - uv run \ - --no-project \ - --with 'mkdocs-material==9.6.14' \ - --with 'mkdocs-same-dir==0.1.3' \ - mkdocs build --strict + run: source/.gitea/scripts/build-site.sh source - name: Publish the complete release atomically env: diff --git a/project/ops/gitea-vps-site/README.md b/project/ops/gitea-vps-site/README.md index 2f020c6..8a89c5b 100644 --- a/project/ops/gitea-vps-site/README.md +++ b/project/ops/gitea-vps-site/README.md @@ -12,6 +12,7 @@ - Пользователь сервиса: `gitea-runner`, без `sudo` и Docker. - Корень публикации: `/srv/de-roadmap`. - Хранение: текущий релиз и две предыдущие версии. +- Окружение сборки: `/var/lib/gitea-runner/venvs/site`. ## Подготовка VPS @@ -19,7 +20,7 @@ ```bash sudo apt-get update -sudo apt-get install nginx certbot python3-certbot-nginx +sudo apt-get install nginx certbot python3-certbot-nginx python3-venv ``` Создать пользователя и каталоги: @@ -126,6 +127,13 @@ curl --header 'Host: de.dementev.space' http://127.0.0.1/ После локальной проверки разрешить профили `Nginx Full` в UFW. До этого публичные порты `80/tcp` и `443/tcp` должны оставаться закрытыми. +## Окружение сборки + +Скрипт `.gitea/scripts/build-site.sh` создаёт persistent venv при первом запуске +и переиспользует его в следующих сборках. `pip install` выполняется каждый раз, +чтобы применить изменения `.gitea/requirements-site.txt`, но уже установленные +версии пакетов не переустанавливаются. + ## DNS и TLS 1. Уменьшить TTL записи `de.dementev.space`. diff --git a/project/ops/gitea-vps-site/gitea-runner.service b/project/ops/gitea-vps-site/gitea-runner.service index eb71944..65d9b92 100644 --- a/project/ops/gitea-vps-site/gitea-runner.service +++ b/project/ops/gitea-vps-site/gitea-runner.service @@ -15,9 +15,7 @@ RestartSec=10s TimeoutStopSec=45s KillMode=mixed -Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" -Environment="UV_CACHE_DIR=/var/lib/gitea-runner/.cache/uv" -Environment="UV_PYTHON_DOWNLOADS=never" +Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" UMask=0022 NoNewPrivileges=true