fix(stage): route blog revalidation to Next and omit unrelated article media
Deploy Canina / deploy (push) Successful in 3m16s
Deploy Canina / deploy (push) Successful in 3m16s
This commit is contained in:
1 parent
85ef01d337
commit
55d11fa597
8 files changed
+106
-15
No files matched your search
@@ -0,0 +1,19 @@
|
||||
# Stage-only storefront repair; retain the deployed admin and nginx artifacts.
|
||||
ARG STAGE_BASE_IMAGE
|
||||
FROM node:20-alpine AS app-builder
|
||||
WORKDIR /app
|
||||
ARG NPM_REGISTRY=https://registry.parsaaghayi.ir/repository/npm/
|
||||
RUN npm config set registry "$NPM_REGISTRY" && npm config set strict-ssl false
|
||||
COPY frontend/application/package*.json ./
|
||||
RUN npm ci --include=dev --prefer-offline --no-audit
|
||||
COPY frontend/application ./
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV NEXT_PUBLIC_API_URL=https://stageapi.canina.ir/api
|
||||
ENV NEXT_PUBLIC_SITE_URL=https://stage.canina.ir
|
||||
ENV NEXT_PUBLIC_APP_ENV=staging
|
||||
RUN npm run build
|
||||
FROM ${STAGE_BASE_IMAGE}
|
||||
WORKDIR /app
|
||||
COPY --from=app-builder /app ./
|
||||
ENV NEXT_PUBLIC_SITE_URL=https://stage.canina.ir
|
||||
ENV NEXT_PUBLIC_APP_ENV=staging
|
||||
@@ -105,24 +105,36 @@ mkdir -p "$RELEASE_ROOT"
|
||||
TARGET_DIR=$(mktemp -d "$RELEASE_ROOT/$DEPLOY_SHA.corporate.XXXXXXXX")
|
||||
git archive "$DEPLOY_SHA" | tar -x -C "$TARGET_DIR"
|
||||
command -v python3 >/dev/null || apk add --no-cache python3
|
||||
export TARGET_DIR DEPLOY_SHA
|
||||
# Pin the existing frontend solely to retain operational nginx/admin artifacts.
|
||||
STAGE_BASE_IMAGE="canina-stage-blog-base:$DEPLOY_SHA"
|
||||
docker tag "$(docker inspect -f '{{.Image}}' canino_frontend_stage)" "$STAGE_BASE_IMAGE"
|
||||
export TARGET_DIR DEPLOY_SHA STAGE_BASE_IMAGE
|
||||
python3 - <<'PY'
|
||||
import json, os, hashlib
|
||||
from pathlib import Path
|
||||
root=Path(os.environ['TARGET_DIR']); sha=os.environ['DEPLOY_SHA']
|
||||
files={str(p.relative_to(root)):hashlib.sha256(p.read_bytes()).hexdigest() for p in sorted(root.rglob('*')) if p.is_file() and not p.is_symlink()}
|
||||
(root/'.release-manifest.json').write_text(json.dumps({'sha':sha,'files':files},sort_keys=True))
|
||||
# Only backend code is changed. Preserve every operational runtime/env file.
|
||||
# Preserve operational runtime/env files; override only the incorrect Stage route.
|
||||
service={'build':{'context':str(root/'backend'),'labels':{'org.opencontainers.image.revision':sha},'args':{'NPM_REGISTRY':'https://registry.parsaaghayi.ir/repository/npm/'}},'labels':{'ir.canina.release.sha':sha},'command':['node','dist/main.js']}
|
||||
(root/'release.override.json').write_text(json.dumps({'services':{'backend_stage':service}}))
|
||||
service['environment']={'FRONTEND_INTERNAL_URL':'http://frontend_stage:3000'}
|
||||
frontend={'build':{'context':str(root),'dockerfile':'scripts/Dockerfile.blog-stage','args':{'STAGE_BASE_IMAGE':os.environ['STAGE_BASE_IMAGE']},'labels':{'org.opencontainers.image.revision':sha}},'labels':{'ir.canina.release.sha':sha}}
|
||||
(root/'release.override.json').write_text(json.dumps({'services':{'backend_stage':service,'frontend_stage':frontend}}))
|
||||
PY
|
||||
compose=(docker compose -p stage --project-directory "$STAGE_DIR" -f "$STAGE_DIR/docker-compose.yml" -f "$TARGET_DIR/release.override.json")
|
||||
timeout --foreground --kill-after=2s 60 "${compose[@]}" config --quiet
|
||||
check_stage_lock
|
||||
timeout --foreground --kill-after=2s 1800 "${compose[@]}" --progress plain build backend_stage
|
||||
timeout --foreground --kill-after=2s 1800 "${compose[@]}" --progress plain build backend_stage frontend_stage
|
||||
check_stage_lock
|
||||
# No migrations, seed, DB/Redis/frontend/bot recreation or runtime config edits.
|
||||
timeout --foreground --kill-after=2s 120 "${compose[@]}" up -d --no-deps --force-recreate backend_stage
|
||||
# Fail closed without exposing either service's shared secret.
|
||||
python3 - <<'PY'
|
||||
import json, subprocess
|
||||
containers=json.loads(subprocess.check_output(['docker','inspect','canino_backend_stage','canino_frontend_stage']))
|
||||
envs=[dict(v.split('=',1) for v in c['Config']['Env']) for c in containers]
|
||||
assert envs[0].get('REVALIDATION_SECRET') and envs[0]['REVALIDATION_SECRET']==envs[1].get('REVALIDATION_SECRET'), 'Stage revalidation secret absent or mismatched'
|
||||
PY
|
||||
# No migrations, seed, DB/Redis/bot recreation or host runtime file edits.
|
||||
timeout --foreground --kill-after=2s 120 "${compose[@]}" up -d --no-deps --force-recreate backend_stage frontend_stage
|
||||
ready=false
|
||||
for attempt in {1..30}; do
|
||||
check_stage_lock
|
||||
@@ -137,6 +149,17 @@ done
|
||||
[[ $(timeout --foreground --kill-after=2s 10 docker inspect -f '{{index .Config.Labels "ir.canina.release.sha"}}' canino_backend_stage) == "$DEPLOY_SHA" ]]
|
||||
image=$(timeout --foreground --kill-after=2s 10 docker inspect -f '{{.Image}}' canino_backend_stage)
|
||||
[[ $(timeout --foreground --kill-after=2s 10 docker image inspect -f '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$image") == "$DEPLOY_SHA" ]]
|
||||
printf 'Corporate Stage backend release complete: %s image=%s (route guarded; authenticated acceptance separate)\n' "$DEPLOY_SHA" "$image"
|
||||
# Exercise the real consumer-to-Next route without resaving any article.
|
||||
for attempt in {1..30}; do
|
||||
if timeout --foreground --kill-after=2s 15 docker exec canino_backend_stage node -e '
|
||||
const {RevalidationService}=require("./dist/common/revalidation/revalidation.service");
|
||||
(async()=>{const s=new RevalidationService(); for(const tag of ["blogs","home-data","blog-senior-dog-l-carnitine-myocardial-energy-evidence"]) if(!await s.revalidateTag(tag)) process.exit(1); for(const path of ["/blog","/blog/senior-dog-l-carnitine-myocardial-energy-evidence"]) if(!await s.revalidatePath(path)) process.exit(1);})().catch(()=>process.exit(1));'; then break; fi
|
||||
[[ $attempt != 30 ]] || exit 1
|
||||
sleep 2
|
||||
done
|
||||
[[ $(docker inspect -f '{{index .Config.Labels "ir.canina.release.sha"}}' canino_frontend_stage) == "$DEPLOY_SHA" ]]
|
||||
frontend_image=$(docker inspect -f '{{.Image}}' canino_frontend_stage)
|
||||
[[ $(docker image inspect -f '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$frontend_image") == "$DEPLOY_SHA" ]]
|
||||
printf 'Stage blog/corporate release complete: %s backend=%s frontend=%s\n' "$DEPLOY_SHA" "$image" "$frontend_image"
|
||||
}
|
||||
supervise_release release_stage
|
||||
Reference in new issue
Block a user