#!/bin/sh set -eu namespace=default script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) config_file=${QUAY_CONFIG_FILE:-$script_dir/config.yaml} config_updated=false for command in kubectl grep mktemp; do if ! command -v "$command" >/dev/null 2>&1; then echo "Required command not found: $command" >&2 exit 1 fi done install_config_secret() { source_file=$1 if grep -q 'REPLACE_WITH_' "$source_file"; then echo "Refusing to install a config containing REPLACE_WITH_ placeholders: $source_file" >&2 exit 1 fi kubectl create secret generic quay-config \ --namespace "$namespace" \ --from-file="config.yaml=$source_file" \ --dry-run=client \ --output=yaml | kubectl apply --filename=- config_updated=true } if [ -f "$config_file" ]; then install_config_secret "$config_file" echo "Updated $namespace/secret/quay-config from the private config file." elif kubectl get secret quay-config --namespace "$namespace" >/dev/null 2>&1; then echo "Keeping the existing $namespace/secret/quay-config." elif kubectl get configmap quay-config --namespace "$namespace" >/dev/null 2>&1; then temp_dir=$(mktemp -d) trap 'rm -rf "$temp_dir"' EXIT HUP INT TERM umask 077 kubectl get configmap quay-config \ --namespace "$namespace" \ --output=go-template='{{index .data "config.yaml"}}' > "$temp_dir/config.yaml" install_config_secret "$temp_dir/config.yaml" echo "Copied the legacy ConfigMap into $namespace/secret/quay-config without printing it." else echo "No private config file, Secret, or legacy ConfigMap was found." >&2 exit 1 fi kubectl apply --filename "$script_dir/ceph-object-user.yaml" kubectl apply --dry-run=server --filename "$script_dir/quay.yaml" kubectl apply --filename "$script_dir/quay.yaml" # The Secret is mounted with subPath, so an explicit Recreate rollout is needed # after a configuration update. if [ "$config_updated" = true ]; then kubectl rollout restart deployment/quay deployment/quay-repomirror \ --namespace "$namespace" fi kubectl rollout status deployment/quay \ --namespace "$namespace" \ --timeout=15m kubectl rollout status deployment/quay-repomirror \ --namespace "$namespace" \ --timeout=15m echo echo "Quay is available at https://registry.brunner.ninja." if kubectl get configmap quay-config --namespace "$namespace" >/dev/null 2>&1; then echo "After verifying the new pods, remove the legacy plaintext ConfigMap with:" echo "kubectl delete configmap quay-config --namespace $namespace" fi