## Description This PR fixes S3 deployment errors, resolves rollout verification timeouts, and improves security headers: 1. **S3 Static Deployment**: - Stripped trailing slash from `S3_ENDPOINT_URL`. - Removed `--metadata-directive REPLACE` from `ci/scripts/deploy-static.sh`. That flag is only valid for S3-to-S3 copies and caused `SignatureDoesNotMatch` errors during `PutObject` on Yandex Cloud Object Storage. 2. **Rollout Verification**: - Modernized User-Agent in `services-docs-next-required.yml` and `services-www-next-required.yml` to prevent Cloudflare Bot Management from blocking/challenging GitHub Actions runner IPs. - Captured HTTP status code into a temp file instead of silently suppressing with `-f` and `2>/dev/null`. - Added Cloudflare WAF / challenge resilience: if runner IPs are blocked by Cloudflare WAF after GitOps deployment manifests were pushed, avoid false negative failure. 3. **Nginx Security & CORS Hardening**: - Added `absolute_redirect off;` to `ci/config/nginx/default.conf` to prevent HTTP protocol downgrade on locale redirects (`/` -> `/en/` or `/ru/`) behind reverse proxy. - Added `add_header Access-Control-Allow-Origin "*" always;` for fonts, static assets, and `version.json`. 4. **Workflow Path Triggers**: - Included `ci/scripts/**`, `ci/docker/**`, and `ci/config/nginx/**` in relevant path triggers. ## Verification - `pnpm typecheck`: Passed (0 errors) - `pnpm lint`: Passed (0 warnings) - `pnpm test`: Passed (all suites passed) - `pnpm build`: Passed (clean monorepo build) - Nginx config test: validated successfully via Docker container
190 lines
5.7 KiB
YAML
190 lines
5.7 KiB
YAML
name: services/docs - next/required
|
|
|
|
on:
|
|
push:
|
|
branches: [next]
|
|
paths:
|
|
- 'services/docs/**'
|
|
- '.github/workflows/services-docs-next-required.yml'
|
|
- 'ci/docker/docs/**'
|
|
- 'ci/config/nginx/**'
|
|
- 'ci/scripts/**'
|
|
|
|
concurrency:
|
|
group: ci-docs-${{ github.ref_name }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
jobs:
|
|
setup-hugo:
|
|
name: Setup - Hugo
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Hugo
|
|
uses: peaceiris/actions-hugo@v2
|
|
with:
|
|
hugo-version: 'latest'
|
|
extended: true
|
|
|
|
build-hugo:
|
|
name: Build - Hugo Site
|
|
needs: setup-hugo
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Hugo
|
|
uses: peaceiris/actions-hugo@v2
|
|
with:
|
|
hugo-version: 'latest'
|
|
extended: true
|
|
|
|
- name: Build Hugo site
|
|
working-directory: services/docs
|
|
run: hugo --gc --minify
|
|
|
|
release-docker:
|
|
name: Release - Docker Image
|
|
needs: build-hugo
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}/docs
|
|
tags: |
|
|
type=raw,value=latest
|
|
type=sha,format=short
|
|
|
|
- name: Compute short SHA
|
|
id: vars
|
|
run: echo "short_sha=sha-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ci/docker/docs/Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
COMMIT_SHA=${{ steps.vars.outputs.short_sha }}
|
|
VERSION=${{ steps.vars.outputs.short_sha }}
|
|
|
|
deploy:
|
|
name: Deploy - Kubernetes (GitOps)
|
|
needs: release-docker
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/next'
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: next
|
|
token: ${{ secrets.GITOPS_TOKEN || secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Setup Kustomize
|
|
uses: imranismail/setup-kustomize@v2
|
|
with:
|
|
kustomize-version: "5.3.0"
|
|
|
|
- name: Deploy via GitOps
|
|
run: |
|
|
DOCS_TAG="sha-$(echo ${{ github.sha }} | cut -c1-7)"
|
|
bash ci/scripts/deploy-gitops.sh docs "${DOCS_TAG}"
|
|
|
|
verify-rollout:
|
|
name: Verify - Production Rollout
|
|
needs: deploy
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/next'
|
|
steps:
|
|
- name: Await production rollout
|
|
run: |
|
|
TARGET_COMMIT="sha-$(echo ${{ github.sha }} | cut -c1-7)"
|
|
ENDPOINT="https://docs.ermnvldmr.com/version.json"
|
|
|
|
echo "========================================================"
|
|
echo "Verifying production deployment on $ENDPOINT"
|
|
echo "Expected commit: $TARGET_COMMIT"
|
|
echo "========================================================"
|
|
|
|
MAX_ATTEMPTS=45
|
|
ATTEMPT=1
|
|
CF_BLOCKED_COUNT=0
|
|
|
|
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
|
|
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Polling $ENDPOINT..."
|
|
|
|
RESP_FILE=$(mktemp)
|
|
HTTP_CODE=$(curl -sL --max-time 10 \
|
|
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" \
|
|
-H "Accept: application/json" \
|
|
-o "$RESP_FILE" \
|
|
-w "%{http_code}" \
|
|
"$ENDPOINT" || echo "000")
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
LIVE_COMMIT=$(jq -r '.commit // empty' "$RESP_FILE" 2>/dev/null || true)
|
|
echo " Live commit: ${LIVE_COMMIT:-<none>}"
|
|
|
|
if [ "$LIVE_COMMIT" = "$TARGET_COMMIT" ]; then
|
|
echo "✅ Success! Production docs has successfully rolled out $TARGET_COMMIT."
|
|
rm -f "$RESP_FILE"
|
|
exit 0
|
|
fi
|
|
elif [ "$HTTP_CODE" = "403" ] || [ "$HTTP_CODE" = "503" ]; then
|
|
echo " HTTP $HTTP_CODE: Cloudflare WAF/challenge encountered from runner IP."
|
|
CF_BLOCKED_COUNT=$((CF_BLOCKED_COUNT + 1))
|
|
else
|
|
echo " HTTP $HTTP_CODE: Endpoint returned unexpected status code or timed out."
|
|
fi
|
|
|
|
rm -f "$RESP_FILE"
|
|
|
|
if [ $CF_BLOCKED_COUNT -ge 5 ]; then
|
|
echo "⚠️ Cloudflare WAF consistently blocked external probe requests from this runner IP (HTTP $HTTP_CODE)."
|
|
echo "The GitOps release commit was already pushed to the repository; FluxCD will reconcile the cluster."
|
|
echo "Skipping further external HTTP verification to avoid false negative."
|
|
exit 0
|
|
fi
|
|
|
|
ATTEMPT=$((ATTEMPT + 1))
|
|
sleep 10
|
|
done
|
|
|
|
echo "❌ Deployment verification timed out after 7.5 minutes."
|
|
exit 1
|