|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +help=" |
| 8 | +build-test-registry.sh is a script to stand up an image registry within a cluster. |
| 9 | +Usage: |
| 10 | + build-test-registry.sh [NAMESPACE] [NAME] [IMAGE] |
| 11 | +
|
| 12 | +Argument Descriptions: |
| 13 | + - NAMESPACE is the namespace that should be created and is the namespace in which the image registry will be created |
| 14 | + - NAME is the name that should be used for the image registry Deployment and Service |
| 15 | + - IMAGE is the name of the image that should be used to run the image registry |
| 16 | +" |
| 17 | + |
| 18 | +if [[ "$#" -ne 3 ]]; then |
| 19 | + echo "Illegal number of arguments passed" |
| 20 | + echo "${help}" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +namespace=$1 |
| 25 | +name=$2 |
| 26 | +image=$3 |
| 27 | + |
| 28 | +oc apply -f - << EOF |
| 29 | +--- |
| 30 | +apiVersion: v1 |
| 31 | +kind: Namespace |
| 32 | +metadata: |
| 33 | + name: ${namespace} |
| 34 | +--- |
| 35 | +apiVersion: apps/v1 |
| 36 | +kind: Deployment |
| 37 | +metadata: |
| 38 | + name: ${name} |
| 39 | + namespace: ${namespace} |
| 40 | + labels: |
| 41 | + app: registry |
| 42 | +spec: |
| 43 | + replicas: 1 |
| 44 | + selector: |
| 45 | + matchLabels: |
| 46 | + app: registry |
| 47 | + template: |
| 48 | + metadata: |
| 49 | + labels: |
| 50 | + app: registry |
| 51 | + spec: |
| 52 | + containers: |
| 53 | + - name: registry |
| 54 | + image: ${image} |
| 55 | + imagePullPolicy: IfNotPresent |
| 56 | + command: |
| 57 | + - /registry |
| 58 | + args: |
| 59 | + - "--registry-address=:5000" |
| 60 | + volumeMounts: |
| 61 | + - mountPath: /var/certs |
| 62 | + name: operator-controller-e2e-certs |
| 63 | + env: |
| 64 | + - name: REGISTRY_HTTP_TLS_CERTIFICATE |
| 65 | + value: "/var/certs/tls.crt" |
| 66 | + - name: REGISTRY_HTTP_TLS_KEY |
| 67 | + value: "/var/certs/tls.key" |
| 68 | + volumes: |
| 69 | + - name: operator-controller-e2e-certs |
| 70 | + secret: |
| 71 | + optional: false |
| 72 | + secretName: operator-controller-e2e-certs |
| 73 | +--- |
| 74 | +apiVersion: v1 |
| 75 | +kind: Service |
| 76 | +metadata: |
| 77 | + name: ${name} |
| 78 | + namespace: ${namespace} |
| 79 | + annotations: |
| 80 | + service.beta.openshift.io/serving-cert-secret-name: operator-controller-e2e-certs |
| 81 | +spec: |
| 82 | + selector: |
| 83 | + app: registry |
| 84 | + ports: |
| 85 | + - name: http |
| 86 | + port: 5000 |
| 87 | + targetPort: 5000 |
| 88 | + type: NodePort |
| 89 | +EOF |
| 90 | + |
| 91 | +oc wait --for=condition=Available -n "${namespace}" "deploy/${name}" --timeout=60s |
| 92 | + |
| 93 | +oc apply -f - << EOF |
| 94 | +apiVersion: batch/v1 |
| 95 | +kind: Job |
| 96 | +metadata: |
| 97 | + name: ${name}-push |
| 98 | + namespace: ${namespace} |
| 99 | +spec: |
| 100 | + template: |
| 101 | + spec: |
| 102 | + restartPolicy: Never |
| 103 | + containers: |
| 104 | + - name: push |
| 105 | + image: ${image} |
| 106 | + command: |
| 107 | + - /push |
| 108 | + args: |
| 109 | + - "--registry-address=${name}.${namespace}.svc:5000" |
| 110 | + - "--images-path=/images" |
| 111 | + volumeMounts: |
| 112 | + - mountPath: /var/certs |
| 113 | + name: operator-controller-e2e-certs |
| 114 | + env: |
| 115 | + - name: SSL_CERT_DIR |
| 116 | + value: "/var/certs/" |
| 117 | + volumes: |
| 118 | + - name: operator-controller-e2e-certs |
| 119 | + secret: |
| 120 | + optional: false |
| 121 | + secretName: operator-controller-e2e-certs |
| 122 | +EOF |
| 123 | + |
| 124 | +oc wait --for=condition=Complete -n "${namespace}" "job/${name}-push" --timeout=60s |
0 commit comments