Skip to content

Instantly share code, notes, and snippets.

@rthallisey
Last active February 24, 2020 17:12
Show Gist options
  • Save rthallisey/0a29d1ef0a90334a5557c88174973957 to your computer and use it in GitHub Desktop.
Save rthallisey/0a29d1ef0a90334a5557c88174973957 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
QUAY_USERNAME="${1:-}"
QUAY_PASSWORD="${2:-}"
APP_REGISTRY_NAMESPACE="${3:-redhat-operators-stage}"
if [ -z "${QUAY_USERNAME}" ]; then
echo "QUAY_USERNAME not set"
exit 1
fi
if [ -z "${QUAY_PASSWORD}" ]; then
echo "QUAY_PASSWORD not set"
exit 1
fi
TOKEN=$(curl -sH "Content-Type: application/json" -XPOST https://quay.io/cnr/api/v1/users/login -d '
{
"user": {
"username": "'"${QUAY_USERNAME}"'",
"password": "'"${QUAY_PASSWORD}"'"
}
}' | jq -r '.token')
echo $TOKEN
if [ "${TOKEN}" == "null" ]; then
echo "TOKEN was 'null'. Did you enter the correct quay Username & Password?"
exit 1
fi
cat <<EOF | oc create -f -
apiVersion: v1
kind: Secret
metadata:
name: quay-registry-$APP_REGISTRY_NAMESPACE
namespace: "openshift-marketplace"
type: Opaque
stringData:
token: "$TOKEN"
EOF
cat <<EOF | oc create -f -
apiVersion: operators.coreos.com/v1
kind: OperatorSource
metadata:
name: "${APP_REGISTRY_NAMESPACE}"
namespace: "openshift-marketplace"
spec:
type: appregistry
endpoint: https://quay.io/cnr
registryNamespace: $APP_REGISTRY_NAMESPACE
displayName: "${APP_REGISTRY_NAMESPACE}"
publisher: "Stage testing"
authorizationToken:
secretName: quay-registry-$APP_REGISTRY_NAMESPACE
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment