forked from runlevel5/gce-buildkite-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install2.sh
executable file
·179 lines (139 loc) · 5.82 KB
/
install2.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
# Tweak open rc
printf "\e[7mTweaking open rc\e[0m\n"
# set this if you want to break the boot process
# notice that this always breaks the shutdown process!
# echo "rc_interactive=\"YES\"" >> /etc/rc.conf
echo "rc_shell=\"/bin/sh\"" >> /etc/rc.conf
echo "rc_verbose=yes" >> /etc/rc.conf
# install virtio modules
printf "\e[7mInstalling Virtio Modules\e[0m\n"
cp $SCRIPTPATH/etc/modules-load.d/virtio /etc/modules-load.d/virtio
# configure net-online
printf "\e[7mConfiguring net-online\e[0m\n"
cp $SCRIPTPATH/etc/conf.d/net-online /etc/conf.d/net-online
rc-update add net-online default
# install haveged
printf "\e[7mInstalling haveged\e[0m\n"
apk add haveged
rc-update add haveged boot
rc-service haveged start
# install google services
printf "\e[7mInstalling Google Services\e[0m\n"
# set timezone to UTC
ln -sf /etc/zoneinfo/UTC /etc/localtime
# install dependencies
apk add git sudo shadow dhclient coreutils python python-dev dev86 musl-dev openssl-dev make py-setuptools ethtool iproute2
# cleanup old runs
rm -rf /tmp/compute-image-packages 2>&1 || true
# clone the services
git clone --branch "20180611" https://github.com/talon-one/compute-image-packages.git /tmp/compute-image-packages
pushd /tmp/compute-image-packages
./setup.py install
popd
# autostart services
cp $SCRIPTPATH/etc/init.d/google-instance-setup /etc/init.d/google-instance-setup
chmod 0700 /etc/init.d/google-instance-setup
rc-update add google-instance-setup default
cp $SCRIPTPATH/etc/init.d/google-network-daemon /etc/init.d/google-network-daemon
chmod 0700 /etc/init.d/google-network-daemon
rc-update add google-network-daemon default
cp $SCRIPTPATH/etc/init.d/google-accounts-daemon /etc/init.d/google-accounts-daemon
chmod 0700 /etc/init.d/google-accounts-daemon
rc-update add google-accounts-daemon default
cp $SCRIPTPATH/etc/init.d/google-clock-skew-daemon /etc/init.d/google-clock-skew-daemon
chmod 0700 /etc/init.d/google-clock-skew-daemon
rc-update add google-clock-skew-daemon default
cp $SCRIPTPATH/etc/init.d/google-startup-scripts /etc/init.d/google-startup-scripts
chmod 0700 /etc/init.d/google-startup-scripts
rc-update add google-startup-scripts default
cp $SCRIPTPATH/etc/init.d/google-shutdown-scripts /etc/init.d/google-shutdown-scripts
chmod 0700 /etc/init.d/google-shutdown-scripts
rc-update add google-shutdown-scripts default
# install docker
printf "\e[7mInstalling Docker\e[0m\n"
apk add docker shadow sudo
rc-update add docker default
rc-service docker start
mkdir /etc/docker 2>&1 || true
cp $SCRIPTPATH/etc/docker/daemon.json /etc/docker/daemon.json
cp $SCRIPTPATH/etc/subuid /etc/subuid
cp $SCRIPTPATH/etc/subgid /etc/subgid
# install garbage collection cronjobs
cp $SCRIPTPATH/etc/periodic/hourly/docker-gc /etc/periodic/hourly/docker-gc
chmod 0700 /etc/periodic/hourly/docker-gc
cp $SCRIPTPATH/etc/periodic/hourly/docker-gc-free-space /etc/periodic/hourly/docker-gc-free-space
chmod 0700 /etc/periodic/hourly/docker-gc-free-space
cp $SCRIPTPATH/usr/sbin/docker-purge /usr/sbin/docker-purge
# install docker-credential-file
cp $SCRIPTPATH/etc/init.d/docker-credential-file /etc/init.d/docker-credential-file
chmod 0700 /etc/init.d/docker-credential-file
rc-update add docker-credential-file default
# install docker compose
printf "\e[7mInstalling Docker Compose\e[0m\n"
apk add python py-pip gcc libffi libffi-dev py-bcrypt py-cryptography py-pynacl
pip install --upgrade pip
pip install docker-compose
# install buildkite
printf "\e[7mInstalling Buildkite\e[0m\n"
apk add shadow
# cleanup old runs
rm -rf /etc/buildkite-agent 2>&1 || true
rm -rf /tmp/buildkite 2>&1 || true
# create needed directories
mkdir /etc/buildkite-agent 2>&1 || true
mkdir /tmp/buildkite 2>&1 || true
pushd /tmp/buildkite
# download and install
wget -O buildkite-agent.tar.gz https://github.com/buildkite/agent/releases/download/v3.22.1/buildkite-agent-linux-amd64-3.22.1.tar.gz
tar -xzf buildkite-agent.tar.gz
mv buildkite-agent /usr/sbin/buildkite-agent
popd
# setup permissions
chmod -R 0755 /etc/buildkite-agent
chmod 0755 /usr/sbin/buildkite-agent
# add a group
addgroup -g 100000 buildkite
sleep 1
# add user
adduser -D -s /sbin/nologin -u 100000 -G buildkite buildkite
sleep 1
# add user to docker group
adduser buildkite docker
sleep 1
cp $SCRIPTPATH/etc/init.d/buildkite-agent /etc/init.d/buildkite-agent
chmod 0700 /etc/init.d/buildkite-agent
rc-update add buildkite-agent default
chown -hR buildkite:buildkite /home/buildkite
# update /etc/profile
echo "export PS1='\u@\h:\`pwd\`\$ '" >> /etc/profile
cp $SCRIPTPATH/usr/sbin/iamroot /usr/sbin/iamroot
chmod 0755 /usr/sbin/iamroot
cp $SCRIPTPATH/usr/sbin/iambuildkite /usr/sbin/iambuildkite
chmod 0755 /usr/sbin/iambuildkite
# update /etc/motd
printf "\e[1m\e[7m" > /etc/motd
printf " \n" >> /etc/motd
printf " Welcome to buildkite-agent \n" >> /etc/motd
printf " \n" >> /etc/motd
printf " Commands \n" >> /etc/motd
printf " iamroot | switch to root \n" >> /etc/motd
printf " iambuildkite | switch to buildkite \n" >> /etc/motd
printf " \n" >> /etc/motd
printf "\e[0m\n" >> /etc/motd
# install nginx to have a health check available
printf "\e[7mInstalling nginx\e[0m\n"
apk add nginx
cp $SCRIPTPATH/etc/nginx/nginx.conf /etc/nginx/nginx.conf
# add github-comment
cp $SCRIPTPATH/usr/sbin/github-comment /usr/sbin/github-comment
chmod 0755 /usr/sbin/github-comment
# test if github-comment works
/usr/sbin/github-comment --version
apk add htop
# adding tmpfs to fstab
# printf "tmpfs /home/buildkite/builds/ tmpfs defaults 0 0\n" >> /etc/fstab
# this needs some improvement: 1. limit the size to 50% of available memory using size=50%
# 2. when the folder is full write to hdd