3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 function configure_containerd
() {
19 echo "Configuring containerd to expose CRI and use systemd cgroup"
20 sudo
mv /etc
/containerd
/config.toml
/etc
/containerd
/config.toml.orig
2>/dev
/null
21 sudo bash
-c "containerd config default > /etc/containerd/config.toml"
22 sudo
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc
/containerd
/config.toml
23 if [ -n "${DOCKER_PROXY_URL}" ]; then
24 echo "Configuring ${DOCKER_PROXY_URL} as registry mirror in /etc/containerd/config.toml"
25 sudo
sed -i "s#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]#\[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors\]\n \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"\]\n endpoint = \[\"${DOCKER_PROXY_URL}\"\]\n \[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"registry.hub.docker.com\"]\n endpoint = \[\"${DOCKER_PROXY_URL}\"]#" /etc
/containerd
/config.toml
27 if [ -n "${OSM_BEHIND_PROXY}" ] ; then
28 echo "Configuring http proxies in /etc/systemd/system/containerd.service.d/http-proxy.conf"
29 if ! [ -f /etc
/systemd
/system
/containerd.service.d
/http-proxy.conf
] ; then
30 sudo mkdir
-p /etc
/systemd
/system
/containerd.service.d
31 cat << EOF | sudo tee -a /etc/systemd/system/containerd.service.d/http-proxy.conf
35 [ -n "${HTTP_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
36 Environment=\"HTTP_PROXY=${HTTP_PROXY}\"
38 [ -n "${HTTPS_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
39 Environment=\"HTTPS_PROXY=${HTTPS_PROXY}\"
41 [ -n "${NO_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/containerd.service.d/http-proxy.conf
42 Environment=\"NO_PROXY=${NO_PROXY}\"
45 sudo systemctl restart containerd
48 function install_docker_ce
() {
49 # installs and configures Docker CE
50 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
51 echo "Removing previous installation of docker ..."
52 for pkg
in docker.io docker-doc docker-compose podman-docker containerd runc
; do sudo apt-get remove
$pkg; done
53 echo "Installing Docker CE ..."
54 sudo apt-get
-y update
55 sudo apt-get
install -y apt-transport-https ca-certificates software-properties-common gnupg
56 sudo
install -m 0755 -d /etc
/apt
/keyrings
57 curl
-fsSL https
://download.docker.com
/linux
/ubuntu
/gpg | sudo gpg
--dearmor -o /etc
/apt
/keyrings
/docker.gpg
58 sudo
chmod a
+r
/etc
/apt
/keyrings
/docker.gpg
59 echo "deb [arch="$
(dpkg
--print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
60 "$
(.
/etc
/os-release
&& echo "$VERSION_CODENAME")" stable" | \
61 sudo
tee /etc
/apt
/sources.list.d
/docker.list
> /dev
/null
62 sudo apt-get
-y update
63 sudo apt-get
install -y docker-ce
65 echo "Adding user to group 'docker'"
66 sudo groupadd
-f docker
67 sudo usermod
-aG docker
$USER
69 if [ -n "${DOCKER_PROXY_URL}" ]; then
70 echo "Configuring docker proxy ..."
71 if [ -f /etc
/docker
/daemon.json
]; then
72 if grep -q registry-mirrors
/etc
/docker
/daemon.json
; then
73 sudo
sed -i "s|registry-mirrors.*|registry-mirrors\": [\"${DOCKER_PROXY_URL}\"] |" /etc
/docker
/daemon.json
75 sudo
sed -i "s|^{|{\n \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"],|" /etc
/docker
/daemon.json
78 sudo bash
-c "cat << EOF > /etc/docker/daemon.json
80 \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"]
85 if [ -n "${OSM_BEHIND_PROXY}" ] ; then
86 if ! [ -f /etc
/systemd
/system
/docker.service.d
/http-proxy.conf
] ; then
87 sudo mkdir
-p /etc
/systemd
/system
/docker.service.d
88 cat << EOF | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
92 [ -n "${HTTP_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
93 Environment=\"HTTP_PROXY=${HTTP_PROXY}\"
95 [ -n "${HTTPS_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
96 Environment=\"HTTPS_PROXY=${HTTPS_PROXY}\"
98 [ -n "${NO_PROXY}" ] && sudo bash
-c "cat <<EOF >> /etc/systemd/system/docker.service.d/http-proxy.conf
99 Environment=\"NO_PROXY=${NO_PROXY}\"
102 if [ -n "${DOCKER_PROXY_URL}" ] ||
[ -n "${OSM_BEHIND_PROXY}" ] ; then
103 sudo systemctl daemon-reload
104 sudo systemctl restart docker
105 echo "... restarted Docker service"
110 [ -z "${DEBUG_INSTALL}" ] ||
! echo "File: /etc/docker/daemon.json" ||
cat /etc
/docker
/daemon.json
111 echo "Testing Docker CE installation ..."
112 sg docker
-c "docker version" || FATAL_TRACK docker_ce
"Docker installation failed. Cannot run docker version"
113 sg docker
-c "docker run --rm hello-world" || FATAL_TRACK docker_ce
"Docker installation failed. Cannot run hello-world"
114 echo "... Docker CE installation done"
115 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
122 while getopts ":D:p:-: P" o
; do
125 OSM_DEVOPS
="${OPTARG}"
128 DOCKER_PROXY_URL
="${OPTARG}"
134 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL
="y" && continue
135 echo -e "Invalid option: '--$OPTARG'\n" >&2
139 echo "Option -$OPTARG requires an argument" >&2
143 echo -e "Invalid option: '-$OPTARG'\n" >&2
152 source $OSM_DEVOPS/common
/logging
154 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
155 echo "DOCKER_PROXY_URL=$DOCKER_PROXY_URL"
156 echo "OSM_BEHIND_PROXY=$OSM_BEHIND_PROXY"