-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure-system.sh
More file actions
91 lines (76 loc) · 2.9 KB
/
Copy pathconfigure-system.sh
File metadata and controls
91 lines (76 loc) · 2.9 KB
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
#!/bin/bash -e
# We assume that we already have a Docker-compatible kernel and appropriate
# grub options set up. (See our precise64-docker subdirectory for a script
# which does this under Docker.) Everything after that is up to this script.
#
# This script will be run repeatedly, so it should be "idempotent", in the
# devops sense of doing nothing if run a second time in the same
# environment. This script may run either under Vagrant, or manually
# against a Linode server (which can't be provisioned via Vagrant at the
# time of writing).
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
echo 'deb http://get.docker.io/ubuntu docker main' > /etc/apt/sources.list.d/docker.list
# Install docker and some other things we'll need.
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -q -y lxc-docker git nginx-full
# Configure docker to not restart running containers on boot, since it's
# unreliable at the best of times, and we want to use upstart.
sed -i 's/.*DOCKER_OPTS=.*/DOCKER_OPTS=\"-r=false\"/g' /etc/default/docker
# Don't start things which depend on Docker until it's actually present.
if ! grep post-start /etc/init/docker.conf; then
cat <<EOF >> /etc/init/docker.conf
post-start script
while [ ! -e /var/run/docker.sock ] ; do
inotifywait -t 2 -e create /var/run/
end
end script
EOF
fi
# Reload our newly-configured Docker.
service docker restart
# Configure nginx.
rm -f /etc/nginx/sites-enabled/default
# Install our gitreceive hooks.
cd /usr/local/bin
wget -N https://raw.github.com/progrium/gitreceive/master/gitreceive
chmod +x gitreceive
if [ ! -x /home/git/receiver ]; then
gitreceive init
fi
cat <<'EOF' > /home/git/receiver
#!/bin/bash -e
# Decide on an image tag.
name="$(basename $1 .git)"
# Store our exported git tree in a temp directory (and make sure we delete
# it on exit).
echo "-----> Unpacking source tree"
WORKDIR=$(mktemp -d build-imageXXXXXX)
function cleanup {
rm -rf "$WORKDIR"
}
trap cleanup EXIT
cat | tar -x -C "$WORKDIR"
# Build our docker image.
cd "$WORKDIR"
echo "-----> Building image: $name"
docker build -t "$name" .
# Install our upstart goodies if we have them.
if [ -e upstart.conf ]; then
echo "-----> Registering image with upstart: $name"
sudo cp upstart.conf "/etc/init/$name.conf"
echo "-----> Launching image: $name"
sudo service "$name" restart
fi
# Add any custom configuration to our nginx proxy server.
if [ -e "nginx-proxy.conf" ]; then
echo "-----> Installing nginx proxy configuration"
sudo cp nginx-proxy.conf "/etc/nginx/sites-available/$name"
sudo ln -sf "/etc/nginx/sites-available/$name" "/etc/nginx/sites-enabled/$name"
echo "-----> Reloading nginx"
sudo service nginx reload
fi
EOF
usermod -a -G docker git # Gives full root privileges via docker.
usermod -a -G sudo git # Gives full root privileges via sudo.
echo "Successfully provisioned host!"