Use dashboard deploy helper for multilingual audit
This commit is contained in:
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
@@ -16,11 +16,9 @@ pipeline {
|
|||||||
environment {
|
environment {
|
||||||
PYENVPIPELINE_VIRTUALENV = '1'
|
PYENVPIPELINE_VIRTUALENV = '1'
|
||||||
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
|
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
|
||||||
STAGING_AUDIT_HOST = 'root@49.12.204.96'
|
|
||||||
STAGING_AUDIT_PROJECT_NAME = 'mandelstudio'
|
STAGING_AUDIT_PROJECT_NAME = 'mandelstudio'
|
||||||
STAGING_AUDIT_PROJECT_DIR = '/home/www-mandelstudio/mandelstudio'
|
STAGING_AUDIT_PROJECT_DIR = '/home/www-mandelstudio/mandelstudio'
|
||||||
STAGING_AUDIT_MANAGE = '/var/lib/virtualenv/mandelstudio/bin/manage.py'
|
STAGING_AUDIT_MANAGE = '/var/lib/virtualenv/mandelstudio/bin/manage.py'
|
||||||
STAGING_AUDIT_SSH_CREDENTIALS_ID = 'staging-root-ssh'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
@@ -147,10 +145,7 @@ PY
|
|||||||
timeout(time: 10, unit: 'MINUTES')
|
timeout(time: 10, unit: 'MINUTES')
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
withCredentials([
|
withCredentials([sshUserPrivateKey(credentialsId: 'gitea-ssh', keyFileVariable: 'GIT_KEYFILE')]) {
|
||||||
sshUserPrivateKey(credentialsId: 'gitea-ssh', keyFileVariable: 'GIT_KEYFILE'),
|
|
||||||
sshUserPrivateKey(credentialsId: env.STAGING_AUDIT_SSH_CREDENTIALS_ID, keyFileVariable: 'STAGING_SSH_KEYFILE')
|
|
||||||
]) {
|
|
||||||
sh '''
|
sh '''
|
||||||
export GIT_SSH_COMMAND="ssh -i $GIT_KEYFILE -o StrictHostKeyChecking=accept-new"
|
export GIT_SSH_COMMAND="ssh -i $GIT_KEYFILE -o StrictHostKeyChecking=accept-new"
|
||||||
if [ -d .git ]; then
|
if [ -d .git ]; then
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ pipeline {
|
|||||||
skipDefaultCheckout(true)
|
skipDefaultCheckout(true)
|
||||||
}
|
}
|
||||||
environment {
|
environment {
|
||||||
STAGING_AUDIT_HOST = 'root@49.12.204.96'
|
STAGING_AUDIT_PROJECT_NAME = 'mandelstudio'
|
||||||
STAGING_AUDIT_PROJECT_DIR = '/home/www-mandelstudio/mandelstudio'
|
STAGING_AUDIT_PROJECT_DIR = '/home/www-mandelstudio/mandelstudio'
|
||||||
STAGING_AUDIT_MANAGE = '/var/lib/virtualenv/mandelstudio/bin/manage.py'
|
STAGING_AUDIT_MANAGE = '/var/lib/virtualenv/mandelstudio/bin/manage.py'
|
||||||
STAGING_AUDIT_SSH_CREDENTIALS_ID = 'staging-root-ssh'
|
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
@@ -45,9 +44,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'mkdir -p artifacts && [ -f artifacts/multilingual-audit.json ] && cp artifacts/multilingual-audit.json artifacts/previous-multilingual-audit.json || true'
|
sh 'mkdir -p artifacts && [ -f artifacts/multilingual-audit.json ] && cp artifacts/multilingual-audit.json artifacts/previous-multilingual-audit.json || true'
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: env.STAGING_AUDIT_SSH_CREDENTIALS_ID, keyFileVariable: 'STAGING_SSH_KEYFILE')]) {
|
sh './scripts/run_remote_multilingual_audit.sh'
|
||||||
sh './scripts/run_remote_multilingual_audit.sh'
|
|
||||||
}
|
|
||||||
script {
|
script {
|
||||||
int status = sh(script: 'python3 scripts/multilingual_audit_ci.py --json artifacts/multilingual-audit.json --previous-json artifacts/previous-multilingual-audit.json', returnStatus: true)
|
int status = sh(script: 'python3 scripts/multilingual_audit_ci.py --json artifacts/multilingual-audit.json --previous-json artifacts/previous-multilingual-audit.json', returnStatus: true)
|
||||||
if (status == 2) {
|
if (status == 2) {
|
||||||
|
|||||||
@@ -1,72 +1,67 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${STAGING_AUDIT_HOST:?STAGING_AUDIT_HOST is required}"
|
: "${STAGING_AUDIT_PROJECT_NAME:?STAGING_AUDIT_PROJECT_NAME is required}"
|
||||||
: "${STAGING_AUDIT_PROJECT_DIR:?STAGING_AUDIT_PROJECT_DIR is required}"
|
: "${STAGING_AUDIT_PROJECT_DIR:?STAGING_AUDIT_PROJECT_DIR is required}"
|
||||||
: "${STAGING_AUDIT_MANAGE:?STAGING_AUDIT_MANAGE is required}"
|
: "${STAGING_AUDIT_MANAGE:?STAGING_AUDIT_MANAGE is required}"
|
||||||
|
|
||||||
mkdir -p artifacts
|
|
||||||
SSH_OPTS=${SSH_OPTS:-"-o StrictHostKeyChecking=accept-new"}
|
|
||||||
if [[ -n "${STAGING_SSH_KEYFILE:-}" ]]; then
|
|
||||||
SSH_OPTS="$SSH_OPTS -i ${STAGING_SSH_KEYFILE}"
|
|
||||||
fi
|
|
||||||
AUDIT_TIMEOUT_SECONDS=${AUDIT_TIMEOUT_SECONDS:-300}
|
AUDIT_TIMEOUT_SECONDS=${AUDIT_TIMEOUT_SECONDS:-300}
|
||||||
OUT_FILE="artifacts/multilingual-audit.json"
|
ARTIFACT_DIR=${ARTIFACT_DIR:-artifacts}
|
||||||
TMP_FILE="${OUT_FILE}.tmp"
|
OUT_FILE="${ARTIFACT_DIR}/multilingual-audit.json"
|
||||||
|
mkdir -p "${ARTIFACT_DIR}"
|
||||||
write_failure_json() {
|
TMP_FILE=$(mktemp)
|
||||||
python3 - <<PY > "$OUT_FILE"
|
trap 'rm -f "$TMP_FILE"' EXIT
|
||||||
import json
|
|
||||||
print(json.dumps({
|
|
||||||
"run_id": None,
|
|
||||||
"total_urls_checked": 0,
|
|
||||||
"issues_found": 0,
|
|
||||||
"summary": {},
|
|
||||||
"issues": {},
|
|
||||||
"error": ${1@Q}
|
|
||||||
}, indent=2))
|
|
||||||
PY
|
|
||||||
}
|
|
||||||
|
|
||||||
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' audit_locales --format=json"
|
REMOTE_CMD="cd '${STAGING_AUDIT_PROJECT_DIR}' && '${STAGING_AUDIT_MANAGE}' audit_locales --format=json"
|
||||||
set +e
|
set +e
|
||||||
SSH_OPTS="$SSH_OPTS" STAGING_AUDIT_HOST="$STAGING_AUDIT_HOST" REMOTE_CMD="$REMOTE_CMD" AUDIT_TIMEOUT_SECONDS="$AUDIT_TIMEOUT_SECONDS" python3 - <<'PY' > "$TMP_FILE"
|
STAGING_AUDIT_PROJECT_NAME="$STAGING_AUDIT_PROJECT_NAME" REMOTE_CMD="$REMOTE_CMD" AUDIT_TIMEOUT_SECONDS="$AUDIT_TIMEOUT_SECONDS" python3 - <<'PY' > "$TMP_FILE"
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
ssh_opts = shlex.split(os.environ["SSH_OPTS"])
|
cmd = [
|
||||||
cmd = ["ssh", *ssh_opts, os.environ["STAGING_AUDIT_HOST"], os.environ["REMOTE_CMD"]]
|
"sudo", "-n", "-u", "mandel", "-g", "www-data",
|
||||||
|
"/srv/apps/mandel-dashboard/.venv/bin/python",
|
||||||
|
"/srv/apps/mandel-dashboard/bin/deploy_stg_from_jenkins.py",
|
||||||
|
os.environ["STAGING_AUDIT_PROJECT_NAME"],
|
||||||
|
"--command",
|
||||||
|
os.environ["REMOTE_CMD"],
|
||||||
|
]
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run(
|
proc = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
check=True,
|
check=False,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=int(os.environ["AUDIT_TIMEOUT_SECONDS"]),
|
timeout=int(os.environ["AUDIT_TIMEOUT_SECONDS"]),
|
||||||
)
|
)
|
||||||
sys.stdout.write(proc.stdout)
|
except subprocess.TimeoutExpired:
|
||||||
sys.stderr.write(proc.stderr)
|
print(json.dumps({
|
||||||
except subprocess.TimeoutExpired as exc:
|
"error": "audit_failed",
|
||||||
sys.stderr.write(exc.stderr or "")
|
"details": f"Audit command timed out after {os.environ['AUDIT_TIMEOUT_SECONDS']} seconds",
|
||||||
raise SystemExit(124)
|
"exit_code": 124,
|
||||||
except subprocess.CalledProcessError as exc:
|
}, indent=2))
|
||||||
sys.stdout.write(exc.stdout or "")
|
raise SystemExit(2)
|
||||||
sys.stderr.write(exc.stderr or "")
|
|
||||||
raise SystemExit(exc.returncode)
|
stdout = proc.stdout.strip()
|
||||||
|
stderr = proc.stderr.strip()
|
||||||
|
if proc.returncode != 0:
|
||||||
|
if stdout:
|
||||||
|
print(stdout)
|
||||||
|
else:
|
||||||
|
print(json.dumps({
|
||||||
|
"error": "audit_failed",
|
||||||
|
"details": stderr or f"Audit command failed with exit status {proc.returncode}",
|
||||||
|
"exit_code": proc.returncode,
|
||||||
|
}, indent=2))
|
||||||
|
raise SystemExit(2)
|
||||||
|
|
||||||
|
print(stdout)
|
||||||
PY
|
PY
|
||||||
rc=$?
|
rc=$?
|
||||||
set -e
|
set -e
|
||||||
if [[ $rc -eq 0 ]]; then
|
cp "$TMP_FILE" "$OUT_FILE"
|
||||||
mv "$TMP_FILE" "$OUT_FILE"
|
cat "$OUT_FILE"
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
rm -f "$TMP_FILE"
|
|
||||||
if [[ $rc -eq 124 ]]; then
|
|
||||||
write_failure_json "Remote multilingual audit timed out after ${AUDIT_TIMEOUT_SECONDS}s"
|
|
||||||
else
|
|
||||||
write_failure_json "Remote multilingual audit failed with exit status ${rc}"
|
|
||||||
fi
|
|
||||||
exit $rc
|
exit $rc
|
||||||
|
|||||||
Reference in New Issue
Block a user