Add deployment actor attribution
This commit is contained in:
@@ -19,6 +19,13 @@ DB_FILE="/opt/appfactory/data/appfactory/appfactory.db"
|
||||
SERVICE_DIR="$WORKSPACE_DIR/$SERVICE_NAME"
|
||||
DEPLOY_DIR="$APPFACTORY_DIR/deploy"
|
||||
|
||||
TRIGGER_SOURCE="${APPFACTORY_TRIGGER_SOURCE:-cli}"
|
||||
TRIGGERED_BY_USER_ID="${APPFACTORY_TRIGGERED_BY_USER_ID:-}"
|
||||
TRIGGERED_BY_USERNAME="${APPFACTORY_TRIGGERED_BY_USERNAME:-}"
|
||||
TRIGGERED_BY_DISPLAY_NAME="${APPFACTORY_TRIGGERED_BY_DISPLAY_NAME:-}"
|
||||
COMMIT_AUTHOR="${APPFACTORY_COMMIT_AUTHOR:-}"
|
||||
PUSHER="${APPFACTORY_PUSHER:-}"
|
||||
|
||||
if [ ! -d "$SERVICE_DIR" ]; then
|
||||
echo "Missing service directory: $SERVICE_DIR"
|
||||
exit 1
|
||||
@@ -29,12 +36,18 @@ if [ ! -f "$SERVICE_DIR/Dockerfile" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEPLOY_ID="$(python3 - "$DB_FILE" "$SERVICE_NAME" <<'PY'
|
||||
DEPLOY_ID="$(python3 - "$DB_FILE" "$SERVICE_NAME" "$TRIGGER_SOURCE" "$TRIGGERED_BY_USER_ID" "$TRIGGERED_BY_USERNAME" "$TRIGGERED_BY_DISPLAY_NAME" "$COMMIT_AUTHOR" "$PUSHER" <<'PY'
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
db_file = sys.argv[1]
|
||||
app_id = sys.argv[2]
|
||||
trigger_source = sys.argv[3]
|
||||
triggered_by_user_id = sys.argv[4] or None
|
||||
triggered_by_username = sys.argv[5] or None
|
||||
triggered_by_display_name = sys.argv[6] or None
|
||||
commit_author = sys.argv[7] or None
|
||||
pusher = sys.argv[8] or None
|
||||
|
||||
con = sqlite3.connect(db_file)
|
||||
|
||||
@@ -44,17 +57,31 @@ cur = con.execute(
|
||||
app_id,
|
||||
kind,
|
||||
status,
|
||||
started_at
|
||||
started_at,
|
||||
trigger_source,
|
||||
triggered_by_user_id,
|
||||
triggered_by_username,
|
||||
triggered_by_display_name,
|
||||
commit_author,
|
||||
pusher
|
||||
)
|
||||
VALUES (?, ?, ?, CURRENT_TIMESTAMP)
|
||||
VALUES (?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(app_id, "core", "running"),
|
||||
(
|
||||
app_id,
|
||||
"core",
|
||||
"running",
|
||||
trigger_source,
|
||||
triggered_by_user_id,
|
||||
triggered_by_username,
|
||||
triggered_by_display_name,
|
||||
commit_author,
|
||||
pusher,
|
||||
),
|
||||
)
|
||||
|
||||
con.commit()
|
||||
|
||||
print(cur.lastrowid)
|
||||
|
||||
con.close()
|
||||
PY
|
||||
)"
|
||||
@@ -63,6 +90,8 @@ TMP_DIR="$(mktemp -d)"
|
||||
STDOUT_FILE="$TMP_DIR/stdout.log"
|
||||
STDERR_FILE="$TMP_DIR/stderr.log"
|
||||
|
||||
touch "$STDOUT_FILE" "$STDERR_FILE"
|
||||
|
||||
finish_deploy() {
|
||||
local status="$1"
|
||||
local returncode="$2"
|
||||
@@ -76,7 +105,6 @@ db_file = sys.argv[1]
|
||||
deploy_id = sys.argv[2]
|
||||
status = sys.argv[3]
|
||||
returncode = int(sys.argv[4])
|
||||
|
||||
stdout_file = Path(sys.argv[5])
|
||||
stderr_file = Path(sys.argv[6])
|
||||
|
||||
@@ -101,8 +129,6 @@ con.execute(
|
||||
con.commit()
|
||||
con.close()
|
||||
PY
|
||||
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
|
||||
run_step() {
|
||||
@@ -172,5 +198,8 @@ else
|
||||
echo "FAILED"
|
||||
echo "Deployment ID: $DEPLOY_ID"
|
||||
|
||||
rm -rf "$TMP_DIR"
|
||||
exit "$RESULT"
|
||||
fi
|
||||
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
Reference in New Issue
Block a user