#!/bin/sh set -eu REMOTE_DIR="${1:-/opt/caiwuxitong}" CONFIG_SOURCE="${2:-$REMOTE_DIR/registry-config.yml}" REGISTRY_CONFIG="/etc/docker/registry/config.yml" REGISTRY_REPOSITORY="127.0.0.1:5000/caiwuxitong/app" if [ "$(id -u)" -ne 0 ]; then echo "setup-incremental-registry.sh must run as root" >&2 exit 1 fi if [ ! -f "$CONFIG_SOURCE" ]; then echo "Missing registry config: $CONFIG_SOURCE" >&2 exit 1 fi if ! command -v docker-registry >/dev/null 2>&1; then export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y --no-install-recommends docker-registry fi install -d -m 755 "$(dirname "$REGISTRY_CONFIG")" install -m 644 "$CONFIG_SOURCE" "$REGISTRY_CONFIG" systemctl enable docker-registry >/dev/null systemctl restart docker-registry attempt=1 while [ "$attempt" -le 20 ]; do if curl -fsS -o /dev/null http://127.0.0.1:5000/v2/; then break fi sleep 1 attempt=$((attempt + 1)) done curl -fsS -o /dev/null http://127.0.0.1:5000/v2/ # Seed the registry from the image already on this server. This makes the first # incremental release reuse existing layers instead of uploading them again. CURRENT_IMAGE="$(docker inspect caiwu_app --format '{{.Config.Image}}' 2>/dev/null || true)" case "$CURRENT_IMAGE" in caiwu_akaunting:*) CURRENT_TAG="${CURRENT_IMAGE#*:}" docker tag "$CURRENT_IMAGE" "$REGISTRY_REPOSITORY:$CURRENT_TAG" docker push "$REGISTRY_REPOSITORY:$CURRENT_TAG" touch "$REMOTE_DIR/.registry-tags" if ! grep -Fxq "$CURRENT_TAG" "$REMOTE_DIR/.registry-tags"; then printf '%s\n' "$CURRENT_TAG" >> "$REMOTE_DIR/.registry-tags" fi ;; esac echo "REGISTRY_READY=127.0.0.1:5000"