Авторизация: форма входа, cookie-сессия, защита /api/* (кроме health/login/me/logout)

This commit is contained in:
2026-08-26 00:38:23 +07:00
parent 5dcc4ce1ad
commit d9eccfb4b7
7 changed files with 482 additions and 17 deletions

View File

@@ -21,6 +21,9 @@ jobs:
env:
PORTAINER_URL: https://ptr.byte-mate.ru
PORTAINER_API_KEY: ${{ secrets.PORTAINER_API_KEY }}
# Секреты Gitea: Settings → Actions → Secrets → APP_USER / APP_PASSWORD
APP_USER: ${{ secrets.APP_USER }}
APP_PASSWORD: ${{ secrets.APP_PASSWORD }}
STACK_NAME: photo-editor
# Если не задано — берётся первый endpoint из /api/endpoints
ENDPOINT_ID: ${{ vars.PORTAINER_ENDPOINT_ID }}
@@ -35,6 +38,12 @@ jobs:
AUTH="X-API-Key: ${PORTAINER_API_KEY}"
# Параметры стека: пустые значения означают «дефолты на сервере»
ENV_JSON=$(jq -nc \
--arg u "${APP_USER:-}" \
--arg p "${APP_PASSWORD:-}" \
'[{name:"APP_USER",value:$u},{name:"APP_PASSWORD",value:$p}]')
# Определяем endpoint (окружение Docker), если не задан вручную
if [ -z "${ENDPOINT_ID:-}" ]; then
ENDPOINT_ID=$(curl -fsSk -H "$AUTH" "$PORTAINER_URL/api/endpoints" | jq -r '.[0].Id')
@@ -49,14 +58,19 @@ jobs:
if [ -n "${STACK_ID}" ]; then
echo "Обновляю стек ${STACK_NAME} (id=${STACK_ID})"
PAYLOAD=$(jq -nc \
--rawfile content deploy/docker-compose.yml \
--argjson env "$ENV_JSON" \
'{StackFileContent:$content, Env:$env, RepullImageAndRedeploy:true}')
curl -fsSk -X PUT -H "$AUTH" -H 'Content-Type: application/json' \
-d "{\"StackFileContent\": $(jq -Rs . deploy/docker-compose.yml), \"RepullImageAndRedeploy\": true}" \
-d "$PAYLOAD" \
"$PORTAINER_URL/api/stacks/${STACK_ID}?endpointId=${ENDPOINT_ID}" >/dev/null
else
echo "Создаю стек ${STACK_NAME}"
curl -fsSk -X POST -H "$AUTH" \
-F "Name=${STACK_NAME}" \
-F "file=@deploy/docker-compose.yml" \
-F "Env=${ENV_JSON}" \
"$PORTAINER_URL/api/stacks/create/standalone/file?endpointId=${ENDPOINT_ID}" >/dev/null
fi