diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..92220ee --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,85 @@ +name: Validate and deploy Quay + +on: + push: + paths: + - quay.yaml + - .gitea/workflows/deploy.yml + pull_request: + paths: + - quay.yaml + - .gitea/workflows/deploy.yml + +env: + KUBECTL_VERSION: v1.36.3 + KUBERNETES_API: https://host.containers.internal:6443 + KUBERNETES_TLS_SERVER_NAME: 192.168.0.2 + NAMESPACE: default + +jobs: + validate: + name: Validate manifest + runs-on: ubuntu-latest + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Validate scripts and Kubernetes resources + run: bash test.sh + + deploy: + name: Downtime deployment + if: gitea.ref == 'refs/heads/main' + needs: validate + runs-on: ubuntu-latest + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Install kubectl + run: | + curl --fail --silent --show-error --location \ + --output "${RUNNER_TEMP}/kubectl" \ + "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" + curl --fail --silent --show-error --location \ + --output "${RUNNER_TEMP}/kubectl.sha256" \ + "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl.sha256" + printf '%s %s\n' "$(cat "${RUNNER_TEMP}/kubectl.sha256")" "${RUNNER_TEMP}/kubectl" | sha256sum --check + chmod 0700 "${RUNNER_TEMP}/kubectl" + + - name: Configure Kubernetes access + env: + KUBE_CONFIG_BASE64: ${{ secrets.KUBE_CONFIG_BASE64 }} + run: | + test -n "${KUBE_CONFIG_BASE64}" + printf '%s' "${KUBE_CONFIG_BASE64}" | base64 --decode > "${RUNNER_TEMP}/kubeconfig" + chmod 0600 "${RUNNER_TEMP}/kubeconfig" + export KUBECONFIG="${RUNNER_TEMP}/kubeconfig" + "${RUNNER_TEMP}/kubectl" config set-cluster cluster \ + --server="${KUBERNETES_API}" \ + --tls-server-name="${KUBERNETES_TLS_SERVER_NAME}" + + - name: Validate desired state on the server + run: | + export KUBECONFIG="${RUNNER_TEMP}/kubeconfig" + "${RUNNER_TEMP}/kubectl" apply \ + --dry-run=server \ + --validate=false \ + --filename quay.yaml + + - name: Apply and verify + run: | + export KUBECONFIG="${RUNNER_TEMP}/kubeconfig" + "${RUNNER_TEMP}/kubectl" apply \ + --validate=false \ + --filename quay.yaml + + for deployment in quay quay-repomirror; do + "${RUNNER_TEMP}/kubectl" --namespace "${NAMESPACE}" rollout status \ + "deployment/${deployment}" \ + --timeout=15m + done + + curl --fail --silent --show-error \ + --max-time 15 \ + https://registry.brunner.ninja/health/endtoend >/dev/null diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be56e69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +config.yaml +*.kubeconfig +.env diff --git a/README.md b/README.md index 027d229..03a5018 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,124 @@ -# quay-kubernetes +# Quay on Kubernetes -Config files to run quay in kubernetes \ No newline at end of file +Plain Kubernetes deployment for `https://registry.brunner.ninja` in the +`default` namespace. Quay updates are deliberately simple: change both matching +`quay.io/projectquay/quay` image references in `quay.yaml`, commit, and push to +`main`. Gitea Actions performs the Kubernetes update. + +The deployment uses plain YAML. There is no Helm chart, Operator, Kustomize, +Argo CD, or custom container build. + +## Persistent data + +Quay itself has no persistent volume. Durable state remains in existing +external services: + +- metadata, users, permissions, and tags: PostgreSQL database `quay` through + `postgresql.default.svc.cluster.local`; +- image layers and artifacts: Rook Ceph RGW bucket `quay`; +- events and build logs: the existing Valkey service in `default`. + +Applying `quay.yaml` does not recreate or delete the PostgreSQL database or RGW +bucket. The `CephObjectStoreUser` declaration is kept separately in +`ceph-object-user.yaml` and is not managed by CI. + +## Configuration Secret + +The historical manifest stored the complete private Quay configuration in a +ConfigMap. The Deployment now mounts `default/secret/quay-config` instead. + +On its first run, `install.sh` copies the existing ConfigMap directly into that +Secret without printing the configuration. After the new pods are healthy, the +script prints the command that can be used to remove the legacy plaintext +ConfigMap. It does not delete it automatically. + +For future configuration changes, copy `config.yaml.example` to the ignored +`config.yaml`, fill every placeholder, and run `./install.sh`. Preserve the +existing `SECRET_KEY` and `DATABASE_SECRET_KEY`; they are persistent Quay +cryptographic keys and should not be regenerated during normal updates. + +An exported Kubernetes Secret YAML is not a safe public backup because its +values are merely base64 encoded. Keep an encrypted off-cluster copy of the +actual configuration in addition to PostgreSQL and RGW backups. + +## Initial installation + +With an administrator kubeconfig active, run: + +```sh +./install.sh +``` + +This creates the configuration Secret when necessary, applies the existing +Rook object user and all Quay resources, and waits for both Deployments. + +The registry Deployment has startup, readiness, and liveness probes. Both +Deployments use `Recreate`, accepting downtime and ensuring old and new Quay +versions do not access PostgreSQL concurrently. + +## Automatic tag updates + +To update Quay, change both identical `image:` fields in `quay.yaml`, for +example from a 3.8 image to the selected 3.9 image, then commit and push: + +```sh +git add quay.yaml +git commit -m "Update Quay to 3.9.x" +git push origin main +``` + +The workflow triggered by a `quay.yaml` change validates the manifest, performs +a server-side dry run, applies the complete file, waits for both Deployments, +and checks the public `/health/endtoend` endpoint. + +Kubernetes handles pod replacement through each Deployment's native `Recreate` +strategy. If the pod template did not change, applying the file does not restart +the pods. When an image reference or another pod-template field changes, +Kubernetes stops that Deployment's old pod before starting its replacement. + +If the new registry cannot migrate or become healthy, CI fails and leaves the +registry stopped or unhealthy for investigation. It does not automatically +start the old image because a completed database migration might not be +backwards compatible. + +Quay requires supported intermediate database migrations. Reach a distant +target using successive supported-version commits rather than skipping from +3.8 directly to 3.18. Kubernetes actions require no manual intervention, but a +Git commit cannot make an unsupported database-version jump safe. + +The workflow runs only when `quay.yaml` or the workflow itself changes, so a +README-only commit does not restart the registry. + +## Gitea Actions bootstrap + +CI requires one repository Actions secret: + +- `KUBE_CONFIG_BASE64`: restricted Quay deployment kubeconfig. + +After `./install.sh` has created all application resources, run once: + +```sh +./create-ci-kubeconfig.sh +``` + +Store its final base64 line as the Gitea Actions secret +`KUBE_CONFIG_BASE64`. After that bootstrap, tag updates are Git-only. + +The deployment identity can update only the existing Deployments `quay` and +`quay-repomirror`, Service `quay`, and Ingress `quay` in `default`. It cannot +read or modify Secrets, PostgreSQL, Valkey, Ceph resources, or the RGW bucket. + +The workflow matches the existing brunner.ninja runner: Kubernetes API URL +`https://host.containers.internal:6443`, with TLS server name `192.168.0.2`. + +## Local validation + +Run: + +```sh +./test.sh +``` + +The test checks shell syntax, requires both Deployments to use one identical +non-`latest` image reference, and validates the Kubernetes manifests with +kubeconform. diff --git a/ceph-object-user.yaml b/ceph-object-user.yaml new file mode 100644 index 0000000..6683b26 --- /dev/null +++ b/ceph-object-user.yaml @@ -0,0 +1,9 @@ +# This is a cluster prerequisite, not part of automated Quay deployments. +# Reapplying it does not recreate or delete the existing RGW bucket. +apiVersion: ceph.rook.io/v1 +kind: CephObjectStoreUser +metadata: + name: quay + namespace: rook-ceph +spec: + store: my-store diff --git a/ci-deployer.yaml b/ci-deployer.yaml new file mode 100644 index 0000000..d9ceb3b --- /dev/null +++ b/ci-deployer.yaml @@ -0,0 +1,70 @@ +# Bootstrap once with an administrator identity. CI can update only the +# existing public Quay resources and cannot access Kubernetes Secrets. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: quay-deployer + namespace: default +automountServiceAccountToken: false +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: quay-deployer + namespace: default +rules: + - apiGroups: + - "" + resources: + - services + resourceNames: + - quay + verbs: + - get + - patch + - update + - apiGroups: + - apps + resources: + - deployments + resourceNames: + - quay + - quay-repomirror + verbs: + - get + - patch + - update + - watch + - apiGroups: + - networking.k8s.io + resources: + - ingresses + resourceNames: + - quay + verbs: + - get + - patch + - update +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: quay-deployer + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: quay-deployer +subjects: + - kind: ServiceAccount + name: quay-deployer + namespace: default +--- +apiVersion: v1 +kind: Secret +metadata: + name: quay-deployer-token + namespace: default + annotations: + kubernetes.io/service-account.name: quay-deployer +type: kubernetes.io/service-account-token diff --git a/config.yaml.example b/config.yaml.example new file mode 100644 index 0000000..98fd3ea --- /dev/null +++ b/config.yaml.example @@ -0,0 +1,121 @@ +# Copy this file to config.yaml and replace every REPLACE_WITH_* value. +# config.yaml is ignored by Git and is installed as the quay/quay-config Secret. +ALLOW_PULLS_WITHOUT_STRICT_LOGGING: true +ALLOWED_OCI_ARTIFACT_TYPES: + application/vnd.oci.image.config.v1+json: + - application/vnd.oci.image.layer.v1.tar+zstd + application/vnd.sylabs.sif.config.v1+json: + - application/vnd.sylabs.sif.layer.v1+tar +AUTHENTICATION_TYPE: Database +AVATAR_KIND: local +BUILDLOGS_REDIS: + host: valkey-primary.default.svc.cluster.local + password: REPLACE_WITH_VALKEY_PASSWORD + port: 6379 +CONTACT_INFO: + - https://brunner.ninja +DATABASE_SECRET_KEY: REPLACE_WITH_PERSISTENT_RANDOM_DATABASE_SECRET_KEY +DB_URI: postgresql://quay:REPLACE_WITH_QUAY_DATABASE_PASSWORD@postgresql.default.svc.cluster.local/quay +DEFAULT_TAG_EXPIRATION: 2w +DISTRIBUTED_STORAGE_CONFIG: + default: + - RadosGWStorage + - access_key: REPLACE_WITH_ROOK_RGW_ACCESS_KEY + bucket_name: quay + hostname: rook-ceph-rgw-my-store.rook-ceph.svc.cluster.local + is_secure: false + secret_key: REPLACE_WITH_ROOK_RGW_SECRET_KEY + storage_path: / +DISTRIBUTED_STORAGE_DEFAULT_LOCATIONS: [] +DISTRIBUTED_STORAGE_PREFERENCE: + - default +EXTERNAL_TLS_TERMINATION: true +FEATURE_ACI_CONVERSION: false +FEATURE_ACTION_LOG_ROTATION: false +FEATURE_ANONYMOUS_ACCESS: true +FEATURE_APP_REGISTRY: true +FEATURE_APP_SPECIFIC_TOKENS: true +FEATURE_BITBUCKET_BUILD: false +FEATURE_BLACKLISTED_EMAILS: false +FEATURE_BUILD_SUPPORT: true +FEATURE_CHANGE_TAG_EXPIRATION: true +FEATURE_DIRECT_LOGIN: true +FEATURE_EXTENDED_REPOSITORY_NAMES: true +FEATURE_FIPS: false +FEATURE_GITHUB_BUILD: false +FEATURE_GITHUB_LOGIN: false +FEATURE_GITLAB_BUILD: false +FEATURE_GOOGLE_LOGIN: false +FEATURE_INVITE_ONLY_USER_CREATION: false +FEATURE_MAILING: true +FEATURE_NONSUPERUSER_TEAM_SYNCING_SETUP: false +FEATURE_PARTIAL_USER_AUTOCOMPLETE: true +FEATURE_PROXY_STORAGE: true +FEATURE_REPO_MIRROR: true +FEATURE_REQUIRE_TEAM_INVITE: true +FEATURE_RESTRICTED_V1_PUSH: true +FEATURE_SECURITY_NOTIFICATIONS: false +FEATURE_SECURITY_SCANNER: false +FEATURE_STORAGE_REPLICATION: false +FEATURE_TEAM_SYNCING: false +FEATURE_USER_CREATION: true +FEATURE_USER_LAST_ACCESSED: true +FEATURE_USER_LOG_ACCESS: false +FEATURE_USER_METADATA: false +FEATURE_USER_RENAME: false +FEATURE_USERNAME_CONFIRMATION: true +FRESH_LOGIN_TIMEOUT: 10m +GITHUB_LOGIN_CONFIG: {} +GITHUB_TRIGGER_CONFIG: {} +GITLAB_TRIGGER_KIND: {} +LDAP_ALLOW_INSECURE_FALLBACK: false +LDAP_EMAIL_ATTR: mail +LDAP_UID_ATTR: uid +LDAP_URI: ldap://localhost +LOG_ARCHIVE_LOCATION: default +LOGS_MODEL: database +LOGS_MODEL_CONFIG: {} +MAIL_DEFAULT_SENDER: brunner.ninja Registry +MAIL_PORT: 587 +MAIL_SERVER: smtp-relay.gmail.com +MAIL_USE_AUTH: false +MAIL_USE_TLS: false +PREFERRED_URL_SCHEME: https +REGISTRY_LOGIN_CONFIG: + CLIENT_ID: REPLACE_WITH_OIDC_CLIENT_ID + CLIENT_SECRET: REPLACE_WITH_OIDC_CLIENT_SECRET + LOGIN_SCOPES: + - openid + - email + OIDC_SERVER: https://auth.brunner.ninja/application/o/registry/ + SERVICE_ICON: https://s3.brunner.ninja/authentik/media/public/auth-favicon.png + SERVICE_NAME: brunner.ninja Auth + VERIFIED_EMAIL_CLAIM_NAME: email + OIDC_DISABLE_USER_ENDPOINT: true +REGISTRY_TITLE: brunner.ninja Registry +REGISTRY_TITLE_SHORT: brunner.ninja Registry +REPO_MIRROR_INTERVAL: 30 +REPO_MIRROR_TLS_VERIFY: true +SEARCH_MAX_RESULT_PAGE_COUNT: 10 +SEARCH_RESULTS_PER_PAGE: 10 +SECRET_KEY: REPLACE_WITH_PERSISTENT_RANDOM_SECRET_KEY +SECURITY_SCANNER_INDEXING_INTERVAL: 30 +SERVER_HOSTNAME: registry.brunner.ninja +SETUP_COMPLETE: true +SUPER_USERS: + - REPLACE_WITH_QUAY_SUPERUSER +TAG_EXPIRATION_OPTIONS: + - 0s + - 1d + - 1w + - 2w + - 4w +TEAM_RESYNC_STALE_TIME: 30m +TESTING: false +USE_CDN: false +USER_EVENTS_REDIS: + host: valkey-primary.default.svc.cluster.local + password: REPLACE_WITH_VALKEY_PASSWORD + port: 6379 +USER_RECOVERY_TOKEN_LIFETIME: 30m +USERFILES_LOCATION: default diff --git a/create-ci-kubeconfig.sh b/create-ci-kubeconfig.sh new file mode 100755 index 0000000..d930e6f --- /dev/null +++ b/create-ci-kubeconfig.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -euo pipefail + +project_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +namespace=${NAMESPACE:-default} +service_account=${SERVICE_ACCOUNT:-quay-deployer} +secret=${TOKEN_SECRET:-quay-deployer-token} + +kubectl apply --filename "${project_dir}/ci-deployer.yaml" >&2 + +for attempt in {1..30}; do + if kubectl --namespace "${namespace}" get secret "${secret}" \ + --output=jsonpath='{.data.token}' 2>/dev/null | grep -q .; then + break + fi + if [[ "${attempt}" == 30 ]]; then + echo "Timed out waiting for the service-account token" >&2 + exit 1 + fi + sleep 1 +done + +workdir=$(mktemp --directory) +trap 'rm -rf "${workdir}"' EXIT + +server=$(kubectl config view --minify --output=jsonpath='{.clusters[0].cluster.server}') +kubectl --namespace "${namespace}" get secret "${secret}" \ + --output=jsonpath='{.data.ca\.crt}' | base64 --decode > "${workdir}/ca.crt" +token=$(kubectl --namespace "${namespace}" get secret "${secret}" \ + --output=jsonpath='{.data.token}' | base64 --decode) + +export KUBECONFIG="${workdir}/config" +kubectl config set-cluster cluster \ + --server="${server}" \ + --certificate-authority="${workdir}/ca.crt" \ + --embed-certs=true >/dev/null +kubectl config set-credentials "${service_account}" --token="${token}" >/dev/null +kubectl config set-context quay \ + --cluster=cluster \ + --user="${service_account}" \ + --namespace="${namespace}" >/dev/null +kubectl config use-context quay >/dev/null + +echo "Store the following single line as the Gitea Actions secret KUBE_CONFIG_BASE64." >&2 +echo "Treat it as a password; do not commit it." >&2 +base64 --wrap=0 "${KUBECONFIG}" +printf '\n' diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8d5d31d --- /dev/null +++ b/install.sh @@ -0,0 +1,75 @@ +#!/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 diff --git a/quay.yaml b/quay.yaml new file mode 100644 index 0000000..79dcbde --- /dev/null +++ b/quay.yaml @@ -0,0 +1,150 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: quay + namespace: default + labels: + app: quay + app.kubernetes.io/name: quay + app.kubernetes.io/component: registry +spec: + replicas: 1 + progressDeadlineSeconds: 900 + strategy: + # Version changes deliberately accept downtime so two Quay versions never + # access the database concurrently. + type: Recreate + selector: + matchLabels: + app: quay + template: + metadata: + labels: + app: quay + app.kubernetes.io/name: quay + app.kubernetes.io/component: registry + spec: + containers: + - name: quay + # Quay 3.8.1 is the currently running database-compatible version. + # Upgrade one supported minor version at a time; do not jump to 3.18. + image: quay.io/projectquay/quay@sha256:ab121a815bfe97d5d28f4ad7eaefd62fa52dcd271ca0fd70163d599e1bbb2236 + env: + - name: DEBUGLOG + value: "true" + ports: + - name: http + containerPort: 8080 + protocol: TCP + startupProbe: + httpGet: + path: /health/instance + port: http + failureThreshold: 60 + periodSeconds: 5 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /health/endtoend + port: http + failureThreshold: 3 + periodSeconds: 10 + timeoutSeconds: 5 + livenessProbe: + httpGet: + path: /health/instance + port: http + failureThreshold: 3 + periodSeconds: 30 + timeoutSeconds: 5 + volumeMounts: + - name: quay-config + mountPath: /conf/stack/config.yaml + subPath: config.yaml + readOnly: true + volumes: + - name: quay-config + secret: + secretName: quay-config + defaultMode: 0440 + imagePullSecrets: + - name: quay-pull-secret +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: quay-repomirror + namespace: default + labels: + app: quay-repomirror + app.kubernetes.io/name: quay + app.kubernetes.io/component: repository-mirror +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: quay-repomirror + template: + metadata: + labels: + app: quay-repomirror + app.kubernetes.io/name: quay + app.kubernetes.io/component: repository-mirror + spec: + containers: + - name: quay-repomirror + image: quay.io/projectquay/quay@sha256:ab121a815bfe97d5d28f4ad7eaefd62fa52dcd271ca0fd70163d599e1bbb2236 + args: + - repomirror + env: + - name: DEBUGLOG + value: "true" + volumeMounts: + - name: quay-config + mountPath: /conf/stack/config.yaml + subPath: config.yaml + readOnly: true + volumes: + - name: quay-config + secret: + secretName: quay-config + defaultMode: 0440 + imagePullSecrets: + - name: quay-pull-secret +--- +apiVersion: v1 +kind: Service +metadata: + name: quay + namespace: default +spec: + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: quay +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: quay + namespace: default + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure +spec: + ingressClassName: traefik + rules: + - host: registry.brunner.ninja + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: quay + port: + name: http diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..d0366be --- /dev/null +++ b/test.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +project_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) + +sh -n "${project_dir}/install.sh" +bash -n "${project_dir}/create-ci-kubeconfig.sh" + +mapfile -t quay_images < <( + sed -n 's|^[[:space:]]*image: \(quay.io/projectquay/quay[^[:space:]]*\)$|\1|p' \ + "${project_dir}/quay.yaml" | sort --unique +) +if [[ "${#quay_images[@]}" != 1 ]]; then + echo "Both Quay Deployments must use the same single image reference." >&2 + exit 1 +fi +if [[ "${quay_images[0]}" == *:latest ]]; then + echo "The mutable latest tag is not allowed." >&2 + exit 1 +fi + +validate_file() { + local manifest=$1 + + if command -v kubeconform >/dev/null 2>&1; then + kubeconform -strict -ignore-missing-schemas -summary "${manifest}" + elif command -v docker >/dev/null 2>&1; then + docker run --rm --interactive \ + ghcr.io/yannh/kubeconform:v0.7.0@sha256:85dbef6b4b312b99133decc9c6fc9495e9fc5f92293d4ff3b7e1b30f5611823c \ + -strict -ignore-missing-schemas -summary < "${manifest}" + else + echo "Required command not found: install kubeconform or Docker" >&2 + exit 1 + fi +} + +validate_file "${project_dir}/quay.yaml" +validate_file "${project_dir}/ceph-object-user.yaml" +validate_file "${project_dir}/ci-deployer.yaml" + +echo "Quay scripts and Kubernetes resources are valid for ${quay_images[0]}."