Some checks failed
CICD Start / Sanity and Base Decision (pull_request) Failing after 1m4s
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
414 lines
15 KiB
YAML
414 lines
15 KiB
YAML
name: Docker Build Base
|
||
|
||
on:
|
||
workflow_dispatch:
|
||
inputs:
|
||
force_rebuild:
|
||
description: Force a rebuild even when the immutable base tag already exists
|
||
required: false
|
||
default: "false"
|
||
head_sha:
|
||
description: Commit SHA to process
|
||
required: false
|
||
source_workflow:
|
||
description: Upstream workflow name
|
||
required: false
|
||
|
||
concurrency:
|
||
group: base-${{ github.sha }}
|
||
cancel-in-progress: true
|
||
|
||
env:
|
||
GITEA_SSH_HOST: kankali.darkhelm.lan
|
||
GITEA_SSH_PORT: "2222"
|
||
GITEA_REPO_SSH_URL: ssh://git@kankali.darkhelm.lan:2222/DarkHelm.org/plex-playlist.git
|
||
GITEA_REGISTRY: kankali.darkhelm.lan:3001
|
||
GITEA_REGISTRY_IP: 10.18.75.2
|
||
GITEA_REGISTRY_HOST: kankali.darkhelm.lan
|
||
|
||
jobs:
|
||
registry-preflight:
|
||
name: Registry Push Preflight
|
||
runs-on: ubuntu-act
|
||
|
||
steps:
|
||
- name: Audit trigger context
|
||
env:
|
||
EVENT_NAME: ${{ github.event_name }}
|
||
SOURCE_WORKFLOW: ${{ github.event.inputs.source_workflow }}
|
||
HEAD_SHA: ${{ github.sha }}
|
||
REF: ${{ github.ref }}
|
||
REF_NAME: ${{ github.ref_name }}
|
||
HEAD_REF: ${{ github.head_ref }}
|
||
FORCE_REBUILD: ${{ github.event.inputs.force_rebuild }}
|
||
run: |
|
||
echo "=== Dispatch Audit: CICD Base Image ==="
|
||
echo "event_name=${EVENT_NAME}"
|
||
echo "source_workflow=${SOURCE_WORKFLOW}"
|
||
echo "head_sha=${HEAD_SHA}"
|
||
echo "ref=${REF}"
|
||
echo "ref_name=${REF_NAME}"
|
||
echo "head_ref=${HEAD_REF}"
|
||
echo "force_rebuild=${FORCE_REBUILD}"
|
||
|
||
- &write_registry_push_helpers
|
||
name: Write registry push helpers
|
||
run: |
|
||
cat > /tmp/registry-push-helpers.sh <<'EOF'
|
||
#!/bin/bash
|
||
|
||
ensure_skopeo() {
|
||
if command -v skopeo >/dev/null 2>&1; then
|
||
return 0
|
||
fi
|
||
|
||
if command -v apt-get >/dev/null 2>&1; then
|
||
apt-get update && apt-get install -y skopeo
|
||
elif command -v apk >/dev/null 2>&1; then
|
||
apk add --no-cache skopeo
|
||
fi
|
||
|
||
if ! command -v skopeo >/dev/null 2>&1; then
|
||
echo "❌ skopeo not available for fallback push"
|
||
return 1
|
||
fi
|
||
}
|
||
|
||
push_ref_with_fallback() {
|
||
ref="$1"
|
||
local_image="$2"
|
||
archive_path="$3"
|
||
registry_user="$4"
|
||
package_access_token="$5"
|
||
|
||
for i in 1 2 3; do
|
||
echo "Docker push attempt ${i}/3 for ${ref}..."
|
||
if docker push "${ref}"; then
|
||
echo "✓ Docker push succeeded for ${ref}"
|
||
return 0
|
||
fi
|
||
|
||
if [ "${i}" -lt 3 ]; then
|
||
sleep 10
|
||
fi
|
||
done
|
||
|
||
echo "⚠ Docker push failed for ${ref}; trying skopeo fallback"
|
||
|
||
if ! ensure_skopeo; then
|
||
return 1
|
||
fi
|
||
|
||
if [ ! -f "${archive_path}" ]; then
|
||
echo "Creating local image archive for fallback push..."
|
||
if ! docker save "${local_image}" -o "${archive_path}"; then
|
||
echo "❌ Failed to create docker archive for fallback push"
|
||
return 1
|
||
fi
|
||
fi
|
||
|
||
if skopeo copy \
|
||
--dest-creds "${registry_user}:${package_access_token}" \
|
||
--dest-tls-verify=false \
|
||
"docker-archive:${archive_path}" \
|
||
"docker://${ref}"; then
|
||
echo "✓ Skopeo fallback push succeeded for ${ref}"
|
||
return 0
|
||
fi
|
||
|
||
echo "❌ Skopeo fallback push failed for ${ref}"
|
||
return 1
|
||
}
|
||
EOF
|
||
|
||
chmod 700 /tmp/registry-push-helpers.sh
|
||
|
||
- name: Verify registry login and minimal push
|
||
env:
|
||
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
||
REGISTRY_USER: ${{ github.actor }}
|
||
GITHUB_SHA: ${{ github.sha }}
|
||
run: |
|
||
echo "=== Registry Push Preflight ==="
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
if ! echo "${PACKAGE_ACCESS_TOKEN}" | docker login "http://${GITEA_REGISTRY}" -u "${REGISTRY_USER}" --password-stdin; then
|
||
echo "❌ Registry login failed during preflight"
|
||
exit 1
|
||
fi
|
||
|
||
PREFLIGHT_TAG="${GITHUB_SHA:-manual}"
|
||
PREFLIGHT_REF="${GITEA_REGISTRY}/darkhelm.org/plex-playlist-ci-preflight:${PREFLIGHT_TAG}"
|
||
|
||
cat <<'EOF' > /tmp/Dockerfile.preflight
|
||
FROM scratch
|
||
LABEL org.opencontainers.image.title="plex-playlist registry preflight"
|
||
LABEL org.opencontainers.image.description="Minimal image used to verify registry push access before expensive CI steps"
|
||
EOF
|
||
|
||
if ! docker build -f /tmp/Dockerfile.preflight -t registry-preflight:latest /tmp; then
|
||
echo "❌ Failed to build minimal preflight image"
|
||
exit 1
|
||
fi
|
||
|
||
docker tag registry-preflight:latest "${PREFLIGHT_REF}"
|
||
|
||
ARCHIVE_PATH="/tmp/registry-preflight.tar"
|
||
source /tmp/registry-push-helpers.sh
|
||
|
||
if push_ref_with_fallback "${PREFLIGHT_REF}" "registry-preflight:latest" "${ARCHIVE_PATH}" "${REGISTRY_USER}" "${PACKAGE_ACCESS_TOKEN}"; then
|
||
echo "✓ Registry preflight push succeeded: ${PREFLIGHT_REF}"
|
||
else
|
||
echo "❌ Registry preflight push failed: ${PREFLIGHT_REF}"
|
||
exit 1
|
||
fi
|
||
|
||
publish-base:
|
||
name: Build and Publish CICD Base Image
|
||
runs-on: ubuntu-act-8gb
|
||
needs: registry-preflight
|
||
outputs:
|
||
base_hash: ${{ steps.base-state.outputs.base_hash }}
|
||
head_sha: ${{ steps.meta.outputs.head_sha }}
|
||
|
||
steps:
|
||
- name: Resolve head SHA
|
||
id: meta
|
||
env:
|
||
HEAD_SHA: ${{ github.sha }}
|
||
run: |
|
||
echo "head_sha=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Minimal checkout for base inputs
|
||
env:
|
||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||
GITHUB_SHA: ${{ steps.meta.outputs.head_sha }}
|
||
run: |
|
||
umask 077
|
||
trap 'rm -f ~/.ssh/id_rsa' EXIT
|
||
echo "=== Minimal Repository Checkout for Base Inputs ==="
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
if [ -n "${SSH_PRIVATE_KEY}" ]; then
|
||
mkdir -p ~/.ssh
|
||
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||
chmod 600 ~/.ssh/id_rsa
|
||
echo "Loaded SSH key fingerprint: $(ssh-keygen -lf ~/.ssh/id_rsa | awk '{print $2}')"
|
||
ssh-keyscan -p "${GITEA_SSH_PORT}" "${GITEA_SSH_HOST}" >> ~/.ssh/known_hosts 2>/dev/null
|
||
else
|
||
echo "❌ SSH_PRIVATE_KEY is empty"
|
||
exit 1
|
||
fi
|
||
|
||
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o StrictHostKeyChecking=no" \
|
||
git clone --depth 1 --no-checkout \
|
||
"${GITEA_REPO_SSH_URL}" .
|
||
|
||
if [ -n "${GITHUB_SHA}" ] && \
|
||
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o StrictHostKeyChecking=no" \
|
||
git fetch --depth 1 origin "${GITHUB_SHA}" >/dev/null 2>&1; then
|
||
git checkout FETCH_HEAD -- Dockerfile.cicd-base .dockerignore scripts/compute-cicd-base-hash.sh
|
||
echo "✓ Checked out base inputs from commit ${GITHUB_SHA}"
|
||
else
|
||
git checkout HEAD -- Dockerfile.cicd-base .dockerignore scripts/compute-cicd-base-hash.sh
|
||
echo "⚠ Falling back to default branch HEAD for base inputs checkout"
|
||
fi
|
||
|
||
chmod +x scripts/compute-cicd-base-hash.sh
|
||
rm -f ~/.ssh/id_rsa
|
||
|
||
- name: Compute base hash and inspect registry
|
||
id: base-state
|
||
env:
|
||
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
||
REGISTRY_USER: ${{ github.actor }}
|
||
FORCE_REBUILD: ${{ github.event.inputs.force_rebuild }}
|
||
run: |
|
||
echo "=== Computing CICD Base Image Hash ==="
|
||
|
||
BASE_HASH=$(./scripts/compute-cicd-base-hash.sh)
|
||
BASE_REF_HASH="${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd-base:${BASE_HASH}"
|
||
BASE_REF_LATEST="${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd-base:latest"
|
||
|
||
echo "Base hash: ${BASE_HASH}"
|
||
echo "base_hash=${BASE_HASH}" >> $GITHUB_OUTPUT
|
||
echo "base_ref_hash=${BASE_REF_HASH}" >> $GITHUB_OUTPUT
|
||
echo "base_ref_latest=${BASE_REF_LATEST}" >> $GITHUB_OUTPUT
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
if ! echo "${PACKAGE_ACCESS_TOKEN}" | docker login "http://${GITEA_REGISTRY}" -u "${REGISTRY_USER}" --password-stdin >/dev/null 2>&1; then
|
||
echo "❌ Registry login failed during base inspection"
|
||
exit 1
|
||
fi
|
||
|
||
if [ "${FORCE_REBUILD}" = "true" ]; then
|
||
echo "Manual force rebuild requested"
|
||
echo "needs_build=true" >> $GITHUB_OUTPUT
|
||
exit 0
|
||
fi
|
||
|
||
for i in 1 2 3; do
|
||
echo "Existing base check ${i}/3 for ${BASE_REF_HASH}..."
|
||
# Manifest inspect is unreliable on some runners; use pull as truth.
|
||
if timeout 900 docker pull "${BASE_REF_HASH}" >/tmp/base-state-pull.log 2>&1; then
|
||
echo "✓ Immutable base image already exists and is pullable: ${BASE_REF_HASH}"
|
||
echo "needs_build=false" >> $GITHUB_OUTPUT
|
||
exit 0
|
||
else
|
||
pull_exit=$?
|
||
echo "Existing base pull check failed with exit code ${pull_exit}"
|
||
if [ "${pull_exit}" -eq 124 ]; then
|
||
echo "Existing base pull timed out after 900s"
|
||
fi
|
||
if [ -s /tmp/base-state-pull.log ]; then
|
||
tail -n 20 /tmp/base-state-pull.log || true
|
||
fi
|
||
fi
|
||
|
||
if [ "${i}" -lt 3 ]; then
|
||
sleep 10
|
||
fi
|
||
done
|
||
|
||
echo "ℹ Immutable base image missing or not yet pullable: ${BASE_REF_HASH}"
|
||
echo "needs_build=true" >> $GITHUB_OUTPUT
|
||
|
||
- *write_registry_push_helpers
|
||
|
||
- name: Build and push base image
|
||
if: steps.base-state.outputs.needs_build == 'true'
|
||
env:
|
||
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
||
REGISTRY_USER: ${{ github.actor }}
|
||
BASE_HASH: ${{ steps.base-state.outputs.base_hash }}
|
||
BASE_REF_HASH: ${{ steps.base-state.outputs.base_ref_hash }}
|
||
BASE_REF_LATEST: ${{ steps.base-state.outputs.base_ref_latest }}
|
||
run: |
|
||
echo "=== Building CICD Base Image ==="
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
export DOCKER_BUILDKIT=1
|
||
|
||
docker build -f Dockerfile.cicd-base \
|
||
--build-arg BASE_IMAGE_VERSION="v1.0.0-${BASE_HASH}" \
|
||
--build-arg BASE_IMAGE_HASH="${BASE_HASH}" \
|
||
-t cicd-base:latest .
|
||
|
||
ARCHIVE_PATH="/tmp/cicd-base.tar"
|
||
source /tmp/registry-push-helpers.sh
|
||
|
||
echo "${PACKAGE_ACCESS_TOKEN}" | docker login "http://${GITEA_REGISTRY}" -u "${REGISTRY_USER}" --password-stdin
|
||
|
||
docker tag cicd-base:latest "${BASE_REF_HASH}"
|
||
docker tag cicd-base:latest "${BASE_REF_LATEST}"
|
||
|
||
push_ref_with_fallback "${BASE_REF_HASH}" "cicd-base:latest" "${ARCHIVE_PATH}" "${REGISTRY_USER}" "${PACKAGE_ACCESS_TOKEN}"
|
||
push_ref_with_fallback "${BASE_REF_LATEST}" "cicd-base:latest" "${ARCHIVE_PATH}" "${REGISTRY_USER}" "${PACKAGE_ACCESS_TOKEN}"
|
||
|
||
- name: Verify published base image
|
||
env:
|
||
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
||
REGISTRY_USER: ${{ github.actor }}
|
||
BASE_REF_HASH: ${{ steps.base-state.outputs.base_ref_hash }}
|
||
run: |
|
||
echo "=== Verifying Published CICD Base Image ==="
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
if ! echo "${PACKAGE_ACCESS_TOKEN}" | docker login "http://${GITEA_REGISTRY}" -u "${REGISTRY_USER}" --password-stdin; then
|
||
echo "❌ Registry login failed during verification"
|
||
exit 1
|
||
fi
|
||
|
||
for i in 1 2 3 4 5 6; do
|
||
echo "Verification attempt ${i}/6 for ${BASE_REF_HASH}..."
|
||
|
||
if docker pull "${BASE_REF_HASH}"; then
|
||
echo "✓ Published base image is pullable: ${BASE_REF_HASH}"
|
||
exit 0
|
||
fi
|
||
|
||
if [ "${i}" -lt 6 ]; then
|
||
echo "⚠ Pull failed; waiting 20s before retry"
|
||
sleep 20
|
||
fi
|
||
done
|
||
|
||
echo "❌ Published base image could not be pulled after 6 attempts: ${BASE_REF_HASH}"
|
||
exit 1
|
||
|
||
dispatch-main-build:
|
||
name: Dispatch CICD Main Build
|
||
runs-on: ubuntu-act
|
||
needs: publish-base
|
||
if: needs.publish-base.result == 'success'
|
||
steps:
|
||
- name: Dispatch main build workflow
|
||
env:
|
||
DISPATCH_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
||
HEAD_SHA: ${{ needs.publish-base.outputs.head_sha }}
|
||
BASE_HASH: ${{ needs.publish-base.outputs.base_hash }}
|
||
REPO_FULL: ${{ github.repository }}
|
||
HEAD_REF: ${{ github.head_ref }}
|
||
REF_NAME: ${{ github.ref_name }}
|
||
run: |
|
||
set -e
|
||
|
||
if [ -z "${DISPATCH_TOKEN}" ]; then
|
||
echo "❌ Missing dispatch token. Set ACTIONS_TRIGGER_TOKEN (repo write scope) or ensure PACKAGE_ACCESS_TOKEN has Actions workflow-dispatch permissions."
|
||
exit 1
|
||
fi
|
||
|
||
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
||
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
||
fi
|
||
|
||
API_BASE="http://${GITEA_REGISTRY_IP}:3001/api/v1"
|
||
REPO_OWNER="${REPO_FULL%/*}"
|
||
REPO_NAME="${REPO_FULL#*/}"
|
||
TARGET_REF="${HEAD_REF:-${REF_NAME}}"
|
||
|
||
payload=$(cat <<EOF
|
||
{
|
||
"ref": "${TARGET_REF}",
|
||
"inputs": {
|
||
"head_sha": "${HEAD_SHA}",
|
||
"base_hash": "${BASE_HASH}",
|
||
"source_workflow": "CICD Base Image",
|
||
"base_needed": "true"
|
||
}
|
||
}
|
||
EOF
|
||
)
|
||
|
||
DISPATCH_URL="${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/docker-build-main.yaml/dispatches"
|
||
RESPONSE_FILE="/tmp/dispatch-response.txt"
|
||
: > "${RESPONSE_FILE}"
|
||
HTTP_CODE=$(curl -sS -o "${RESPONSE_FILE}" -w "%{http_code}" -X POST \
|
||
-H "Authorization: token ${DISPATCH_TOKEN}" \
|
||
-H "Content-Type: application/json" \
|
||
"${DISPATCH_URL}" \
|
||
-d "${payload}" || true)
|
||
|
||
if [ "${HTTP_CODE}" -lt 200 ] || [ "${HTTP_CODE}" -ge 300 ]; then
|
||
echo "❌ Dispatch failed with HTTP ${HTTP_CODE}"
|
||
echo "Dispatch URL: ${DISPATCH_URL}"
|
||
echo "Response body:"
|
||
cat "${RESPONSE_FILE}" || true
|
||
exit 1
|
||
fi
|