|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -INSTALL_HOST=${1:-`hostname`} |
4 |
| -echo "Installing using hostname ${INSTALL_HOST}" |
5 |
| - |
6 |
| -# write out configuration |
7 |
| -openshift start master --write-config /etc/atomic-registry/master \ |
8 |
| - --etcd-dir /var/lib/atomic-registry/etcd \ |
9 |
| - --public-master ${INSTALL_HOST} \ |
10 |
| - --master https://localhost:8443 |
11 |
| - |
12 |
| -echo "Copy files to host" |
13 |
| - |
14 |
| -set -x |
15 |
| -mkdir -p /etc/atomic-registry/master/site |
16 |
| -mkdir -p /etc/atomic-registry/registry |
17 |
| -mkdir -p /etc/atomic-registry/serviceaccount |
18 |
| -mkdir -p /host/var/lib/atomic-registry/registry |
19 |
| - |
20 |
| -cp /exports/unit_files/* /host/etc/systemd/system/ |
21 |
| -cp /exports/config/* /host/etc/sysconfig/ |
22 |
| -cp /exports/oauthclient.yaml /etc/atomic-registry/master/ |
23 |
| -cp /exports/setup-atomic-registry.sh /host/var/run/ |
24 |
| -cp /exports/registry-login-template.html /host/etc/atomic-registry/master/site/ |
25 |
| - |
26 |
| -chown -R 1001:root /host/var/lib/atomic-registry/registry |
27 |
| -chown -R 1001:root /etc/atomic-registry/registry |
28 |
| - |
29 |
| -set +x |
30 |
| -echo "Add serviceaccount token and certificate to registry configuration" |
31 |
| -ln /etc/atomic-registry/master/ca.crt /etc/atomic-registry/serviceaccount/ca.crt |
32 |
| -echo "default" >> /etc/atomic-registry/serviceaccount/namespace |
33 |
| -echo "This directory stores the service account token, namespace text file and certificate to enable the registry to connect to the API master." \ |
34 |
| - >> /etc/atomic-registry/serviceaccount/README |
35 |
| -cat /etc/atomic-registry/master/ca.crt > /etc/atomic-registry/serviceaccount/service-ca.crt |
36 |
| -cat /etc/atomic-registry/master/service-signer.crt >> /etc/atomic-registry/serviceaccount/service-ca.crt |
37 |
| - |
38 |
| -echo "This directory stores the docker/distribution registry configuration file. To secure the service add TLS certificates here and reference them as environment variables." \ |
39 |
| - >> /etc/atomic-registry/registry/README |
40 |
| -echo "This directory stores configuration and certificates for the API master." \ |
41 |
| - >> /etc/atomic-registry/master/README |
42 |
| - |
43 |
| -set -x |
44 |
| - |
45 |
| -# add OpenShift API master URL to web console env file |
46 |
| -echo "OPENSHIFT_OAUTH_PROVIDER_URL=https://${INSTALL_HOST}:8443" >> /host/etc/sysconfig/atomic-registry-console |
47 |
| -echo "REGISTRY_HOST=${INSTALL_HOST}:5000" >> /host/etc/sysconfig/atomic-registry-console |
48 |
| -# generate random secret for multi-registry shared storage deployment |
49 |
| -echo "REGISTRY_HTTP_SECRET=$(head -c 64 /dev/urandom | base64 -w0)" >> /host/etc/sysconfig/atomic-registry |
50 |
| -echo "DOCKER_REGISTRY_SERVICE_HOST=${INSTALL_HOST}" >> /host/etc/sysconfig/atomic-registry |
51 |
| - |
52 |
| -# load updated systemd unit files |
53 |
| -chroot /host systemctl daemon-reload |
54 |
| - |
55 |
| -set +x |
56 |
| - |
57 |
| -echo "Updating login template" |
58 |
| -sed -i 's/ templates: null$/ templates:\n login: site\/registry-login-template.html/' /etc/atomic-registry/master/master-config.yaml |
59 |
| - |
60 |
| -echo "Optionally edit configuration file authentication /etc/atomic-registry/master/master-config.yaml," |
61 |
| -echo "and/or add certificates to /etc/atomic-registry/master," |
62 |
| -echo "then enable and start services:" |
63 |
| -echo " sudo systemctl enable --now atomic-registry-master.service" |
64 |
| -echo "Once all 3 containers are running (docker ps), run the setup script" |
65 |
| -echo "(you can run it again if it is run early and fails)" |
66 |
| -echo " sudo /var/run/setup-atomic-registry.sh ${INSTALL_HOST}" |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +installhost="${1:-"$(hostname)"}" |
| 8 | + |
| 9 | +# Defaults |
| 10 | +REGISTRYPORT="${REGISTRYPORT:-5000}" |
| 11 | +MASTERPORT="${MASTERPORT:-8443}" |
| 12 | +CONSOLEPORT="${CONSOLEPORT:-9090}" |
| 13 | +REGISTRYIMAGE="${REGISTRYIMAGE:-openshift/origin-docker-registry}" |
| 14 | +MASTERIMAGE="${MASTERIMAGE:-openshift/origin}" |
| 15 | +CONSOLEIMAGE="${CONSOLEIMAGE:-cockpit/kubernetes}" |
| 16 | +REGISTRYTAG="${REGISTRYTAG:-latest}" |
| 17 | +MASTERTAG="${MASTERTAG:-latest}" |
| 18 | +CONSOLETAG="${CONSOLETAG:-latest}" |
| 19 | + |
| 20 | +echo "Installing using hostname ${installhost}" |
| 21 | + |
| 22 | +function write_config() { |
| 23 | + openshift start master --write-config=/etc/atomic-registry/master \ |
| 24 | + --etcd-dir=/var/lib/atomic-registry/etcd \ |
| 25 | + --public-master="${installhost}:${MASTERPORT}" \ |
| 26 | + --master="https://localhost:${MASTERPORT}" \ |
| 27 | + --listen="https://0.0.0.0:${MASTERPORT}" \ |
| 28 | + --cors-allowed-origins="${installhost}:${CONSOLEPORT}" |
| 29 | +} |
| 30 | + |
| 31 | +function copy_files_to_host() { |
| 32 | + echo "Copy files to host" |
| 33 | + |
| 34 | + set -x |
| 35 | + mkdir -p /etc/atomic-registry/master/site |
| 36 | + mkdir -p /etc/atomic-registry/registry |
| 37 | + mkdir -p /etc/atomic-registry/serviceaccount |
| 38 | + mkdir -p /host/var/lib/atomic-registry/registry |
| 39 | + |
| 40 | + cp /exports/unit_files/* /host/etc/systemd/system/ |
| 41 | + cp /exports/config/* /host/etc/sysconfig/ |
| 42 | + cp /exports/oauthclient.yaml /etc/atomic-registry/master/ |
| 43 | + cp /exports/setup-atomic-registry.sh /host/var/run/ |
| 44 | + cp /exports/registry-login-template.html /host/etc/atomic-registry/master/site/ |
| 45 | + |
| 46 | + chown -R 1001:root /host/var/lib/atomic-registry/registry |
| 47 | + chown -R 1001:root /etc/atomic-registry/registry |
| 48 | + |
| 49 | + set +x |
| 50 | + echo "Add serviceaccount token and certificate to registry configuration" |
| 51 | + ln /etc/atomic-registry/master/ca.crt /etc/atomic-registry/serviceaccount/ca.crt |
| 52 | + echo "default" >> /etc/atomic-registry/serviceaccount/namespace |
| 53 | + echo "This directory stores the service account token, namespace text file and certificate to enable the registry to connect to the API master." \ |
| 54 | + >> /etc/atomic-registry/serviceaccount/README |
| 55 | + cat /etc/atomic-registry/master/ca.crt > /etc/atomic-registry/serviceaccount/service-ca.crt |
| 56 | + cat /etc/atomic-registry/master/service-signer.crt >> /etc/atomic-registry/serviceaccount/service-ca.crt |
| 57 | + |
| 58 | + echo "This directory stores the docker/distribution registry configuration file. To secure the service add TLS certificates here and reference them as environment variables." \ |
| 59 | + >> /etc/atomic-registry/registry/README |
| 60 | + echo "This directory stores configuration and certificates for the API master." \ |
| 61 | + >> /etc/atomic-registry/master/README |
| 62 | +} |
| 63 | + |
| 64 | +function customize_config() { |
| 65 | + echo "Update custom ports, images and tags" |
| 66 | + |
| 67 | + echo "REGISTRY_HTTP_SECRET=$(head -c 64 /dev/urandom | base64 -w0)" >> /host/etc/sysconfig/atomic-registry |
| 68 | + |
| 69 | + sed -i "s/8443/${MASTERPORT}/g" /host/etc/sysconfig/atomic-registry |
| 70 | + |
| 71 | + echo "OPENSHIFT_OAUTH_PROVIDER_URL=https://${installhost}:${MASTERPORT}" >> /host/etc/sysconfig/atomic-registry-console |
| 72 | + echo "REGISTRY_HOST=${installhost}:${REGISTRYPORT}" >> /host/etc/sysconfig/atomic-registry-console |
| 73 | + echo "DOCKER_REGISTRY_SERVICE_PORT=${REGISTRYPORT}" >> /host/etc/sysconfig/atomic-registry |
| 74 | + echo "REGISTRY_HTTP_ADDR=:${REGISTRYPORT}" >> /host/etc/sysconfig/atomic-registry |
| 75 | + echo "REGISTRYPORT=${REGISTRYPORT}" >> /host/etc/sysconfig/atomic-registry |
| 76 | + echo "REGISTRYIMAGE=${REGISTRYIMAGE}" >> /host/etc/sysconfig/atomic-registry |
| 77 | + echo "REGISTRYTAG=${REGISTRYTAG}" >> /host/etc/sysconfig/atomic-registry |
| 78 | + echo "KUBERNETES_SERVICE_HOST=${installhost}" >> /host/etc/sysconfig/atomic-registry |
| 79 | + echo "KUBERNETES_SERVICE_PORT=${MASTERPORT}" >> /host/etc/sysconfig/atomic-registry |
| 80 | + echo "MASTERPORT=${MASTERPORT}" >> /host/etc/sysconfig/atomic-registry-master |
| 81 | + echo "MASTERIMAGE=${MASTERIMAGE}" >> /host/etc/sysconfig/atomic-registry-master |
| 82 | + echo "MASTERTAG=${MASTERTAG}" >> /host/etc/sysconfig/atomic-registry-master |
| 83 | + echo "CONSOLEPORT=${CONSOLEPORT}" >> /host/etc/sysconfig/atomic-registry-console |
| 84 | + echo "CONSOLEIMAGE=${CONSOLEIMAGE}" >> /host/etc/sysconfig/atomic-registry-console |
| 85 | + echo "CONSOLETAG=${CONSOLETAG}" >> /host/etc/sysconfig/atomic-registry-console |
| 86 | + echo "KUBERNETES_SERVICE_HOST=${installhost}" >> /host/etc/sysconfig/atomic-registry-console |
| 87 | + echo "KUBERNETES_SERVICE_PORT=${MASTERPORT}" >> /host/etc/sysconfig/atomic-registry-console |
| 88 | + |
| 89 | + echo "Updating login template" |
| 90 | + sed -i 's/ templates: null$/ templates:\n login: site\/registry-login-template.html/' /host/etc/atomic-registry/master/master-config.yaml |
| 91 | + |
| 92 | + echo "Files updated" |
| 93 | + for file in /host/etc/sysconfig/atomic*; do |
| 94 | + echo $'\t'"${file}:" |
| 95 | + cat "${file}" |
| 96 | + echo |
| 97 | + done |
| 98 | + chroot /host systemctl daemon-reload |
| 99 | +} |
| 100 | + |
| 101 | +function print_next_steps() { |
| 102 | + echo "Optionally edit configuration file authentication /etc/atomic-registry/master/master-config.yaml," |
| 103 | + echo "and/or add certificates to /etc/atomic-registry/master," |
| 104 | + echo "then enable and start services:" |
| 105 | + echo " sudo systemctl enable --now atomic-registry-master.service" |
| 106 | + echo "Once all 3 containers are running (docker ps), run the setup script" |
| 107 | + echo "(you can run it again if it is run early and fails)" |
| 108 | + echo " sudo /var/run/setup-atomic-registry.sh" |
| 109 | +} |
| 110 | + |
| 111 | +write_config |
| 112 | +copy_files_to_host |
| 113 | +customize_config |
| 114 | +print_next_steps |
0 commit comments