Adds utility script for pushing container images to Gitea Docker registry at git.knownelement.com/knel/knel-aimiddleware. Commands: list, tag, tag-all, push, push-all. Includes shellcheck compliance fixes. Assisted-by: GLM-5 via Crush <crush@charm.land>
173 lines
4.1 KiB
Bash
Executable File
173 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# KNEL-AIMiddleware Docker Registry Management Script
|
|
# Push container images to Gitea Docker registry at git.knownelement.com
|
|
|
|
set -e
|
|
|
|
REGISTRY="git.knownelement.com"
|
|
REGISTRY_ORG="knel"
|
|
REGISTRY_REPO="knel-aimiddleware"
|
|
PREFIX="kneldevstack-aimiddleware-"
|
|
|
|
usage() {
|
|
echo "KNEL-AIMiddleware Docker Registry Management"
|
|
echo ""
|
|
echo "Usage: $0 <command> [options]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " list List all built images ready to push"
|
|
echo " tag <service> Tag a specific service image for registry"
|
|
echo " tag-all Tag all built images for registry"
|
|
echo " push <service> Push a specific service image to registry"
|
|
echo " push-all Push all built images to registry"
|
|
echo " help Show this help message"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 list"
|
|
echo " $0 tag docker-mcp"
|
|
echo " $0 push docker-mcp"
|
|
echo " $0 push-all"
|
|
echo ""
|
|
echo "Registry: ${REGISTRY}/${REGISTRY_ORG}/${REGISTRY_REPO}"
|
|
exit 1
|
|
}
|
|
|
|
get_built_images() {
|
|
docker images --format '{{.Repository}}' | grep "^${PREFIX}" | sort -u || true
|
|
}
|
|
|
|
get_registry_tag() {
|
|
local service="$1"
|
|
echo "${REGISTRY}/${REGISTRY_ORG}/${REGISTRY_REPO}/${service}:latest"
|
|
}
|
|
|
|
cmd_list() {
|
|
echo "Built images ready to push:"
|
|
echo ""
|
|
for image in $(get_built_images); do
|
|
service="${image#"${PREFIX}"}"
|
|
registry_tag=$(get_registry_tag "$service")
|
|
echo " $image"
|
|
echo " -> $registry_tag"
|
|
done
|
|
echo ""
|
|
}
|
|
|
|
cmd_tag() {
|
|
local service="$1"
|
|
if [ -z "$service" ]; then
|
|
echo "Error: Service name required"
|
|
usage
|
|
fi
|
|
|
|
local local_image="${PREFIX}${service}"
|
|
local registry_tag
|
|
registry_tag=$(get_registry_tag "$service")
|
|
|
|
if ! docker image inspect "$local_image" &>/dev/null; then
|
|
echo "Error: Image $local_image not found. Build it first with: docker compose build $service"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Tagging: $local_image -> $registry_tag"
|
|
docker tag "$local_image" "$registry_tag"
|
|
echo "Done."
|
|
}
|
|
|
|
cmd_tag_all() {
|
|
echo "Tagging all built images..."
|
|
echo ""
|
|
|
|
for image in $(get_built_images); do
|
|
service="${image#"${PREFIX}"}"
|
|
registry_tag=$(get_registry_tag "$service")
|
|
echo "Tagging: $image -> $registry_tag"
|
|
docker tag "$image" "$registry_tag"
|
|
done
|
|
|
|
echo ""
|
|
echo "All images tagged."
|
|
}
|
|
|
|
cmd_push() {
|
|
local service="$1"
|
|
if [ -z "$service" ]; then
|
|
echo "Error: Service name required"
|
|
usage
|
|
fi
|
|
|
|
local local_image="${PREFIX}${service}"
|
|
local registry_tag
|
|
registry_tag=$(get_registry_tag "$service")
|
|
|
|
if ! docker image inspect "$local_image" &>/dev/null; then
|
|
echo "Error: Image $local_image not found. Build it first with: docker compose build $service"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Tagging: $local_image -> $registry_tag"
|
|
docker tag "$local_image" "$registry_tag"
|
|
|
|
echo "Pushing: $registry_tag"
|
|
docker push "$registry_tag"
|
|
|
|
echo "Done."
|
|
}
|
|
|
|
cmd_push_all() {
|
|
echo "Pushing all built images to ${REGISTRY}/${REGISTRY_ORG}/${REGISTRY_REPO}"
|
|
echo ""
|
|
|
|
local count=0
|
|
local failed=0
|
|
|
|
for image in $(get_built_images); do
|
|
service="${image#"${PREFIX}"}"
|
|
registry_tag=$(get_registry_tag "$service")
|
|
|
|
count=$((count + 1))
|
|
echo "[${count}] Processing: $service"
|
|
echo " Tagging: $image -> $registry_tag"
|
|
docker tag "$image" "$registry_tag"
|
|
|
|
echo " Pushing: $registry_tag"
|
|
if docker push "$registry_tag"; then
|
|
echo " Success"
|
|
else
|
|
echo " Failed"
|
|
failed=$((failed + 1))
|
|
fi
|
|
|
|
echo ""
|
|
done
|
|
|
|
echo "================================"
|
|
echo "Push complete: $count images processed, $failed failed"
|
|
}
|
|
|
|
case "${1:-help}" in
|
|
list)
|
|
cmd_list
|
|
;;
|
|
tag)
|
|
cmd_tag "$2"
|
|
;;
|
|
tag-all)
|
|
cmd_tag_all
|
|
;;
|
|
push)
|
|
cmd_push "$2"
|
|
;;
|
|
push-all)
|
|
cmd_push_all
|
|
;;
|
|
help|--help|-h)
|
|
usage
|
|
;;
|
|
*)
|
|
echo "Unknown command: $1"
|
|
usage
|
|
;;
|
|
esac
|