Files
jukebox_maker/ops/push-image.sh
Michael Chus 2355d32766 ops: add registry prefix to build-image, add push-image script
build-image.sh теперь тегирует как git.mchus.pro/reanimator/jukebox-maker.
push-image.sh собирает мультиарч образ и пушит в Gitea registry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 21:41:14 +03:00

76 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Build a multi-arch Docker image and push it to a Gitea container registry.
#
# Usage:
# ./ops/push-image.sh [TAG]
#
# Environment variables:
# GITEA_REGISTRY registry host, e.g. git.mchus.pro (default: git.mchus.pro)
# GITEA_OWNER Gitea user or organisation (default: reanimator)
# IMAGE_NAME image name (default: jukebox-maker)
# PLATFORMS comma-separated platform list (default: linux/amd64,linux/arm64)
# PUSH_LATEST also tag and push :latest (default: true)
#
# Assumes docker is already logged in to GITEA_REGISTRY.
#
# Examples:
# ./ops/push-image.sh
# ./ops/push-image.sh v1.0
set -eu
ROOT_DIR=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
die() { echo "error: $*" >&2; exit 1; }
command -v docker >/dev/null 2>&1 || die "docker not found in PATH"
command -v git >/dev/null 2>&1 || die "git not found in PATH"
docker buildx version >/dev/null 2>&1 || die "docker buildx not available"
GITEA_REGISTRY="${GITEA_REGISTRY:-git.mchus.pro}"
GITEA_OWNER="${GITEA_OWNER:-reanimator}"
IMAGE_NAME="${IMAGE_NAME:-jukebox-maker}"
PLATFORMS="${PLATFORMS:-linux/amd64,linux/arm64}"
PUSH_LATEST="${PUSH_LATEST:-true}"
DEFAULT_TAG=$(git -C "${ROOT_DIR}" rev-parse --short HEAD 2>/dev/null || echo dev)
IMAGE_TAG="${1:-${IMAGE_TAG:-${DEFAULT_TAG}}}"
FULL_IMAGE="${GITEA_REGISTRY}/${GITEA_OWNER}/${IMAGE_NAME}"
echo "registry : ${GITEA_REGISTRY}"
echo "image : ${FULL_IMAGE}"
echo "tag : ${IMAGE_TAG}"
echo "platforms: ${PLATFORMS}"
BUILDER_NAME="jukebox-multiarch"
if ! docker buildx inspect "${BUILDER_NAME}" >/dev/null 2>&1; then
echo "creating buildx builder: ${BUILDER_NAME}"
docker buildx create \
--name "${BUILDER_NAME}" \
--driver docker-container \
--bootstrap
fi
docker buildx use "${BUILDER_NAME}"
TAGS="-t ${FULL_IMAGE}:${IMAGE_TAG}"
if [ "${PUSH_LATEST}" = "true" ]; then
TAGS="${TAGS} -t ${FULL_IMAGE}:latest"
fi
echo "building and pushing..."
# shellcheck disable=SC2086
docker buildx build \
--platform "${PLATFORMS}" \
--file "${ROOT_DIR}/Dockerfile" \
${TAGS} \
--push \
"${ROOT_DIR}"
echo ""
echo "pushed:"
echo " ${FULL_IMAGE}:${IMAGE_TAG}"
if [ "${PUSH_LATEST}" = "true" ]; then
echo " ${FULL_IMAGE}:latest"
fi