Rename basebuild to builder
[ci-management.git] / packer / provision / docker.sh
1 #!/bin/bash
2
3 # vim: ts=4 sw=4 sts=4 et tw=72 :
4
5 # force any errors to cause the script and job to end in failure
6 set -xeu -o pipefail
7
8 rh_systems() {
9     # Assumes that python is already installed by basebuild
10
11     # Install dependencies for robotframework and robotframework-sshlibrary
12     yum install -y yum-utils unzip sshuttle nc libffi-devel openssl-devel
13
14     # Install docker
15     yum install -y docker supervisor bridge-utils
16     systemctl enable docker
17
18     # configure docker networking so that it does not conflict with LF
19     # internal networks
20     cat <<EOL > /etc/sysconfig/docker-network
21 # /etc/sysconfig/docker-network
22 DOCKER_NETWORK_OPTIONS='--bip=10.250.0.254/24'
23 EOL
24     # configure docker daemon to listen on port 5555 enabling remote
25     # managment
26     sed -i -e "s#='--selinux-enabled'#='--selinux-enabled -H unix:///var/run/docker.sock -H tcp://0.0.0.0:5555'#g" /etc/sysconfig/docker
27
28     # docker group doesn't get created by default for some reason
29     groupadd docker
30 }
31
32 ubuntu_docker_mtu_fix(){
33     echo "---> Fixing docker's mtu settings"
34     systemctl stop docker
35     cat <<'EOL' > /etc/systemd/system/docker.service
36 [Unit]
37 Description=Docker Application Container Engine
38 Documentation=https://docs.docker.com
39 After=network.target docker.socket
40 Requires=docker.socket
41
42 [Service]
43 Type=notify
44 # the default is not to use systemd for cgroups because the delegate issues still
45 # exists and systemd currently does not support the cgroup feature set required
46 # for containers run by docker
47 ExecStart=
48 ExecStart=/usr/bin/dockerd --mtu 1454 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
49 ExecReload=/bin/kill -s HUP $MAINPID
50 # Having non-zero Limit*s causes performance problems due to accounting overhead
51 # in the kernel. We recommend using cgroups to do container-local accounting.
52 LimitNOFILE=infinity
53 LimitNPROC=infinity
54 LimitCORE=infinity
55 # Uncomment TasksMax if your systemd version supports it.
56 # Only systemd 226 and above support this version.
57 TasksMax=infinity
58 TimeoutStartSec=0
59 # set delegate yes so that systemd does not reset the cgroups of docker containers
60 Delegate=yes
61 # kill only the docker process, not all processes in the cgroup
62 KillMode=process
63
64 [Install]
65 WantedBy=multi-user.target
66 EOL
67     systemctl start docker
68     echo "---> Checking MTU"
69     docker network inspect bridge
70     echo "---> MTU set to 1454"
71 }
72
73 ubuntu_systems() {
74     # Assumes that python is already installed by basebuild
75
76     # Install Python3.6
77     sudo add-apt-repository -y ppa:jonathonf/python-3.6
78     sudo apt-get update
79     sudo apt-get install -y python3.6 python3.6-dev
80
81     # Install dependencies for robotframework and robotframework-sshlibrary
82     apt install -y unzip sshuttle netcat libffi-dev libssl-dev
83     wget https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz
84     tar xvzf geckodriver-v0.18.0-linux64.tar.gz -C /usr/local/bin
85     export PATH=$PATH:/usr/local/bin
86
87     # Install docker
88     apt install -y docker.io
89
90     # Fixing Docker MTU settings
91     ubuntu_docker_mtu_fix
92 }
93
94 all_systems() {
95     # Install docker-compose
96     curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.15.0/docker-compose-$(uname -s)-$(uname -m)"
97     chmod +x /usr/local/bin/docker-compose
98     docker-compose -v
99 }
100
101 echo "---> Detecting OS"
102 ORIGIN=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
103
104 case "${ORIGIN}" in
105     fedora|centos|redhat)
106         echo "---> RH type system detected"
107         rh_systems
108     ;;
109     ubuntu)
110         echo "---> Ubuntu system detected"
111         ubuntu_systems
112     ;;
113     *)
114         echo "---> Unknown operating system"
115     ;;
116 esac
117
118 # execute steps for all systems
119 all_systems