Compare commits
4 Commits
bot/anno-1
...
chore/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d5b790e52 | |||
| 4dec9e182b | |||
| 9b4584f70a | |||
| 7b64fb7401 |
@@ -37,48 +37,67 @@ jobs:
|
|||||||
node --version
|
node --version
|
||||||
npm --version
|
npm --version
|
||||||
|
|
||||||
- name: Checkout (from event.json, no external actions)
|
- name: Checkout (push or workflow_dispatch, no external actions)
|
||||||
|
env:
|
||||||
|
EVENT_JSON: /var/run/act/workflow/event.json
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
export EVENT_JSON="/var/run/act/workflow/event.json"
|
|
||||||
test -f "$EVENT_JSON" || { echo "❌ Missing $EVENT_JSON"; exit 1; }
|
test -f "$EVENT_JSON" || { echo "❌ Missing $EVENT_JSON"; exit 1; }
|
||||||
|
|
||||||
eval "$(node --input-type=module -e 'import fs from "node:fs";
|
node --input-type=module <<'NODE'
|
||||||
const ev = JSON.parse(fs.readFileSync(process.env.EVENT_JSON,"utf8"));
|
import fs from "node:fs";
|
||||||
const repo =
|
const ev = JSON.parse(fs.readFileSync(process.env.EVENT_JSON, "utf8"));
|
||||||
ev?.repository?.clone_url ||
|
const repoObj = ev?.repository || {};
|
||||||
(ev?.repository?.html_url ? (ev.repository.html_url.replace(/\/$/,"") + ".git") : "");
|
const cloneUrl =
|
||||||
const sha =
|
repoObj?.clone_url ||
|
||||||
ev?.after ||
|
(repoObj?.html_url ? (repoObj.html_url.replace(/\/$/,"") + ".git") : "");
|
||||||
ev?.pull_request?.head?.sha ||
|
if (!cloneUrl) throw new Error("No repository clone_url/html_url in event.json");
|
||||||
ev?.head_commit?.id ||
|
|
||||||
ev?.sha ||
|
|
||||||
"";
|
|
||||||
if (!repo) throw new Error("No repository url in event.json");
|
|
||||||
if (!sha) throw new Error("No sha in event.json");
|
|
||||||
process.stdout.write(`REPO_URL=${JSON.stringify(repo)}\nSHA=${JSON.stringify(sha)}\n`);
|
|
||||||
')"
|
|
||||||
|
|
||||||
echo "Repo URL: $REPO_URL"
|
const defaultBranch = repoObj?.default_branch || "main";
|
||||||
echo "SHA: $SHA"
|
const sha =
|
||||||
|
(process.env.GITHUB_SHA && String(process.env.GITHUB_SHA).trim()) ||
|
||||||
|
ev?.after ||
|
||||||
|
ev?.sha ||
|
||||||
|
ev?.head_commit?.id ||
|
||||||
|
ev?.pull_request?.head?.sha ||
|
||||||
|
"";
|
||||||
|
|
||||||
|
const shq = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'";
|
||||||
|
fs.writeFileSync("/tmp/deploy.env", [
|
||||||
|
`REPO_URL=${shq(cloneUrl)}`,
|
||||||
|
`DEFAULT_BRANCH=${shq(defaultBranch)}`,
|
||||||
|
`SHA=${shq(sha)}`
|
||||||
|
].join("\n") + "\n");
|
||||||
|
NODE
|
||||||
|
|
||||||
|
source /tmp/deploy.env
|
||||||
|
echo "Repo URL: $REPO_URL"
|
||||||
|
echo "Default branch: $DEFAULT_BRANCH"
|
||||||
|
echo "SHA: ${SHA:-<empty>}"
|
||||||
|
|
||||||
rm -rf .git
|
rm -rf .git
|
||||||
git init -q
|
git init -q
|
||||||
git remote add origin "$REPO_URL"
|
git remote add origin "$REPO_URL"
|
||||||
git fetch --depth 1 origin "$SHA"
|
|
||||||
git -c advice.detachedHead=false checkout -q FETCH_HEAD
|
|
||||||
git log -1 --oneline
|
|
||||||
|
|
||||||
echo "SHA=$SHA" >> /tmp/deploy.env
|
if [[ -n "${SHA:-}" ]]; then
|
||||||
echo "REPO_URL=$REPO_URL" >> /tmp/deploy.env
|
git fetch --depth 1 origin "$SHA"
|
||||||
|
git -c advice.detachedHead=false checkout -q FETCH_HEAD
|
||||||
|
else
|
||||||
|
git fetch --depth 1 origin "$DEFAULT_BRANCH"
|
||||||
|
git -c advice.detachedHead=false checkout -q "origin/$DEFAULT_BRANCH"
|
||||||
|
SHA="$(git rev-parse HEAD)"
|
||||||
|
echo "SHA='$SHA'" >> /tmp/deploy.env
|
||||||
|
echo "Resolved SHA: $SHA"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git log -1 --oneline
|
||||||
|
|
||||||
- name: Gate — auto deploy only on annotations/media changes
|
- name: Gate — auto deploy only on annotations/media changes
|
||||||
env:
|
env:
|
||||||
INPUT_FORCE: ${{ inputs.force }}
|
INPUT_FORCE: ${{ inputs.force }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
source /tmp/deploy.env
|
||||||
source /tmp/deploy.env 2>/dev/null || true
|
|
||||||
|
|
||||||
FORCE="${INPUT_FORCE:-0}"
|
FORCE="${INPUT_FORCE:-0}"
|
||||||
if [[ "$FORCE" == "1" ]]; then
|
if [[ "$FORCE" == "1" ]]; then
|
||||||
@@ -87,22 +106,18 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# fichiers touchés par CE commit (⚠️ merge commits -> utiliser -m)
|
CHANGED="$(git show --name-only --pretty="" "$SHA" | sed '/^$/d' || true)"
|
||||||
CHANGED="$(git diff-tree -m --no-commit-id --name-only -r "$SHA" || true)"
|
|
||||||
echo "== changed files =="
|
echo "== changed files =="
|
||||||
echo "$CHANGED" | sed -n '1,200p'
|
echo "$CHANGED" | sed -n '1,240p'
|
||||||
|
|
||||||
# Gate strict : uniquement annotations + media
|
|
||||||
if echo "$CHANGED" | grep -qE '^(src/annotations/|public/media/)'; then
|
if echo "$CHANGED" | grep -qE '^(src/annotations/|public/media/)'; then
|
||||||
echo "GO=1" >> /tmp/deploy.env
|
echo "GO=1" >> /tmp/deploy.env
|
||||||
echo "✅ deploy allowed (annotations/media change detected)"
|
echo "✅ deploy allowed (annotations/media change detected)"
|
||||||
exit 0
|
else
|
||||||
|
echo "GO=0" >> /tmp/deploy.env
|
||||||
|
echo "ℹ️ no annotations/media change -> skip deploy"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "GO=0" >> /tmp/deploy.env
|
|
||||||
echo "ℹ️ no annotations/media change -> skip deploy"
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
- name: Install docker client + docker compose plugin (v2)
|
- name: Install docker client + docker compose plugin (v2)
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -122,6 +137,15 @@ jobs:
|
|||||||
docker version
|
docker version
|
||||||
docker compose version
|
docker compose version
|
||||||
|
|
||||||
|
# 🔥 KEY FIX: reuse existing compose project name if containers already exist
|
||||||
|
PROJ="$(docker inspect archicratie-web-blue --format '{{ index .Config.Labels "com.docker.compose.project" }}' 2>/dev/null || true)"
|
||||||
|
if [[ -z "${PROJ:-}" ]]; then
|
||||||
|
PROJ="$(docker inspect archicratie-web-green --format '{{ index .Config.Labels "com.docker.compose.project" }}' 2>/dev/null || true)"
|
||||||
|
fi
|
||||||
|
if [[ -z "${PROJ:-}" ]]; then PROJ="archicratie-web"; fi
|
||||||
|
echo "COMPOSE_PROJECT_NAME='$PROJ'" >> /tmp/deploy.env
|
||||||
|
echo "✅ Using COMPOSE_PROJECT_NAME=$PROJ"
|
||||||
|
|
||||||
- name: Assert required vars (PUBLIC_GITEA_*)
|
- name: Assert required vars (PUBLIC_GITEA_*)
|
||||||
env:
|
env:
|
||||||
PUBLIC_GITEA_BASE: ${{ vars.PUBLIC_GITEA_BASE }}
|
PUBLIC_GITEA_BASE: ${{ vars.PUBLIC_GITEA_BASE }}
|
||||||
@@ -157,18 +181,21 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
source /tmp/deploy.env
|
source /tmp/deploy.env
|
||||||
[[ "${GO:-0}" == "1" ]] || { echo "ℹ️ skipped"; exit 0; }
|
[[ "${GO:-0}" == "1" ]] || { echo "ℹ️ skipped"; exit 0; }
|
||||||
|
PROJ="${COMPOSE_PROJECT_NAME:-archicratie-web}"
|
||||||
|
|
||||||
# backup tags (best effort)
|
|
||||||
TS="$(date -u +%Y%m%d-%H%M%S)"
|
TS="$(date -u +%Y%m%d-%H%M%S)"
|
||||||
echo "TS=$TS" >> /tmp/deploy.env
|
echo "TS='$TS'" >> /tmp/deploy.env
|
||||||
docker image tag archicratie-web:blue "archicratie-web:blue.BAK.${TS}" || true
|
docker image tag archicratie-web:blue "archicratie-web:blue.BAK.${TS}" || true
|
||||||
docker image tag archicratie-web:green "archicratie-web:green.BAK.${TS}" || true
|
docker image tag archicratie-web:green "archicratie-web:green.BAK.${TS}" || true
|
||||||
|
|
||||||
# build + restart staging (blue=8081)
|
# ✅ use cache (DO NOT --no-cache)
|
||||||
docker compose build --no-cache web_blue
|
docker compose -p "$PROJ" -f docker-compose.yml build web_blue
|
||||||
docker compose up -d --force-recreate web_blue
|
|
||||||
|
# ✅ hard fix: remove existing container if name conflicts
|
||||||
|
docker rm -f archicratie-web-blue || true
|
||||||
|
|
||||||
|
docker compose -p "$PROJ" -f docker-compose.yml up -d --force-recreate --remove-orphans web_blue
|
||||||
|
|
||||||
# smoke staging (local port)
|
|
||||||
curl -fsS "http://127.0.0.1:8081/para-index.json" >/dev/null
|
curl -fsS "http://127.0.0.1:8081/para-index.json" >/dev/null
|
||||||
curl -fsS "http://127.0.0.1:8081/annotations-index.json" >/dev/null
|
curl -fsS "http://127.0.0.1:8081/annotations-index.json" >/dev/null
|
||||||
curl -fsS "http://127.0.0.1:8081/pagefind/pagefind.js" >/dev/null
|
curl -fsS "http://127.0.0.1:8081/pagefind/pagefind.js" >/dev/null
|
||||||
@@ -190,18 +217,21 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
source /tmp/deploy.env
|
source /tmp/deploy.env
|
||||||
[[ "${GO:-0}" == "1" ]] || { echo "ℹ️ skipped"; exit 0; }
|
[[ "${GO:-0}" == "1" ]] || { echo "ℹ️ skipped"; exit 0; }
|
||||||
|
PROJ="${COMPOSE_PROJECT_NAME:-archicratie-web}"
|
||||||
TS="${TS:-$(date -u +%Y%m%d-%H%M%S)}"
|
TS="${TS:-$(date -u +%Y%m%d-%H%M%S)}"
|
||||||
|
|
||||||
rollback() {
|
rollback() {
|
||||||
echo "⚠️ rollback green -> previous image tag (best effort)"
|
echo "⚠️ rollback green -> previous image tag (best effort)"
|
||||||
docker image tag "archicratie-web:green.BAK.${TS}" archicratie-web:green || true
|
docker image tag "archicratie-web:green.BAK.${TS}" archicratie-web:green || true
|
||||||
docker compose up -d --force-recreate web_green || true
|
docker rm -f archicratie-web-green || true
|
||||||
|
docker compose -p "$PROJ" -f docker-compose.yml up -d --force-recreate --remove-orphans web_green || true
|
||||||
}
|
}
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
docker compose build --no-cache web_green
|
docker compose -p "$PROJ" -f docker-compose.yml build web_green
|
||||||
docker compose up -d --force-recreate web_green
|
|
||||||
|
docker rm -f archicratie-web-green || true
|
||||||
|
docker compose -p "$PROJ" -f docker-compose.yml up -d --force-recreate --remove-orphans web_green
|
||||||
|
|
||||||
curl -fsS "http://127.0.0.1:8082/para-index.json" >/dev/null
|
curl -fsS "http://127.0.0.1:8082/para-index.json" >/dev/null
|
||||||
curl -fsS "http://127.0.0.1:8082/annotations-index.json" >/dev/null
|
curl -fsS "http://127.0.0.1:8082/annotations-index.json" >/dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user