-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocp-setup-local-registry.sh
executable file
·143 lines (120 loc) · 3.41 KB
/
ocp-setup-local-registry.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
#This script will install docker , docker compose and initialize local docker local registry
# written by Moran Guy
GREEN='\033[0;32m'
NC='\033[0m'
set -e
set -u
group="docker"
if grep -q $group /etc/group
then
echo "${group} permissions cofigured!"
else
echo "${group} does not exist"
echo "configure docker permissions..."
echo "please re run the script"
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
fi
#*** installing docker
function install-docker {
if [ -x "$(command -v docker)" ]
then
echo "Dockder already installed"
else
echo -e "${GREEN} installing docker ${NC}"
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install docker-ce docker-ce-cli containerd.io > /dev/null
fi
}
#*** installing docker-compose
function install-docker-compose {
echo -e "${GREEN} installing docker-compose ${NC}"
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
cd $registry_name
docker-compose up -d
sleep 5
if pgrep -x "registry" >/dev/null
then
echo "docker-compose is up and running"
else
echo "docker-compose is not running"
fi
}
echo "Please enter local registry name ?"
read registry_name
echo "Please enter local domain name for registry?"
read domain
mkdir $registry_name
mkdir -p $registry_name/data
cat <<EOF > $registry_name/docker-compose.yaml
services:
#Registry
registry:
image: registry:2
restart: always
ports:
- "5000:5000"
environment:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
volumes:
- ./data:/data
networks:
- mynet
#Docker Networks
networks:
mynet:
driver: bridge
#Volumes
volumes:
myregistrydata:
driver: local
EOF
install-docker
install-docker-compose
cat <<EOF > /etc/docker/daemon.json
{
"insecure-registries" : ["$registry_name.$domain:5000"]
}
EOF
systemctl restart docker
sleep 5
if pgrep -x "dockerd" >/dev/null
then
echo "docker is up and running"
else
echo "docker is not running"
fi
ip_addr=`hostname -I | awk '{print $1}'`
echo "***Installation has been completed***"
echo
echo "*********************************************"
echo
echo "Please add A record $registry_name.$domain pointing to $ip_addr to your DNS"
echo
echo
echo 'For k8s please add /etc/docker/daemon.json on each node of the cluster as below :'
echo
cat <<EOF
{
"insecure-registries" : ["$registry_name.$domain:5000"]
}
EOF
echo
echo
echo 'For openshift please run oc edit image.config.openshift.io/cluster and add the following :'
echo
cat <<EOF
spec:
additionalTrustedCA:
name: registry-config
registrySources:
insecureRegistries:
- $registry_name.$domain:5000
EOF