Merge branch 'dev'

This commit is contained in:
Jeff Lindsay
2013-06-30 11:46:11 -05:00
11 changed files with 82 additions and 50 deletions

View File

@@ -1,14 +1,15 @@
GITRECEIVE_URL = https://raw.github.com/progrium/gitreceive/master/gitreceive
SSHCOMMAND_URL = https://raw.github.com/progrium/sshcommand/master/sshcommand
PLUGINHOOK_URL = https://s3.amazonaws.com/progrium-pluginhook/pluginhook_0.1.0_amd64.deb
all: install
install: gitreceive sshcommand
install: gitreceive sshcommand pluginhook
cp dokku /usr/local/bin/dokku
cp receiver /home/git/receiver
cp nginx-app-conf /home/git/nginx-app-conf
cp nginx-reloader.conf /etc/init/nginx-reloader.conf
echo "include /home/git/*/nginx.conf;" > /etc/nginx/conf.d/dokku.conf
mkdir -p /var/lib/dokku/plugins
cp -r plugins/* /var/lib/dokku/plugins
PLUGIN_PATH=/var/lib/dokku/plugins pluginhook install
gitreceive:
wget -qO /usr/local/bin/gitreceive ${GITRECEIVE_URL}
@@ -20,5 +21,9 @@ sshcommand:
chmod +x /usr/local/bin/sshcommand
sshcommand create dokku /usr/local/bin/dokku
pluginhook:
wget -qO /tmp/pluginhook_0.1.0_amd64.deb ${PLUGINHOOK_URL}
cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb
count:
cat receiver dokku bootstrap.sh nginx-app-conf nginx-reloader.conf | wc -l
cat receiver dokku bootstrap.sh | wc -l

View File

@@ -4,7 +4,7 @@ DOCKER_PKG=${DOCKER_PKG:-"https://launchpad.net/~dotcloud/+archive/lxc-docker/+f
set -e
DEBIAN_FRONTEND=noninteractive apt-get install -y linux-image-extra-`uname -r`
apt-get update && apt-get install -y git nginx make curl dnsutils
apt-get update && apt-get install -y git make curl
wget -qO- "$DOCKER_PKG" > /tmp/lxc-docker_0.4.2-1_amd64.deb
dpkg --force-depends -i /tmp/lxc-docker_0.4.2-1_amd64.deb && apt-get install -f -y
@@ -15,15 +15,6 @@ cd dokku && make install
curl "$DOKKU_STACK" | gunzip -cd | docker import - progrium/buildstep
sed -i 's/docker -d/docker -d -r=true/' /etc/init/docker.conf
sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf
[[ $(dig +short $HOSTNAME) ]] && hostfile="DOMAIN" || hostfile="HOSTNAME"
echo $HOSTNAME > /home/git/$hostfile
/etc/init.d/nginx start
start nginx-reloader
echo
echo "Be sure to upload a public key for your user:"
echo " cat ~/.ssh/id_rsa.pub | ssh root@$HOSTNAME \"gitreceive upload-key progrium\""

30
dokku
View File

@@ -1,5 +1,7 @@
#!/bin/bash
set -e; case "$1" in
set -e
export PLUGIN_PATH="/var/lib/dokku/plugins"
case "$1" in
receive)
APP="$2"; IMAGE="app/$APP"
echo "-----> Building $APP ..."
@@ -8,17 +10,15 @@ set -e; case "$1" in
echo "-----> Deploying $APP ..."
dokku deploy $APP $IMAGE
echo "=====> Application deployed:"
echo " http://$(< "$HOME/$APP/HOSTNAME")"
echo " $(dokku url $APP)"
echo
;;
build)
IMAGE="$2"
# Place the app inside the container
id=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app")
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null
# Run the builder script and attach to view output
id=$(docker run -d $IMAGE /build/builder)
docker attach $id
test $(docker wait $id) -eq 0
@@ -33,14 +33,8 @@ set -e; case "$1" in
echo $id > "$HOME/$APP/CONTAINER"
port=$(docker port $id 5000)
echo $port > "$HOME/$APP/PORT"
if [[ -f "$HOME/DOMAIN" ]]; then
hostname="${APP/\//-}.$(< "$HOME/DOMAIN")"
$HOME/nginx-app-conf ${APP/\//-} $port $hostname > $HOME/$APP/nginx.conf
nc -U $HOME/reload-nginx
else
hostname="$(< "$HOME/HOSTNAME"):$port"
fi
echo $hostname > "$HOME/$APP/HOSTNAME"
echo "$(< "$HOME/HOSTNAME"):$port" > "$HOME/$APP/ADDRESS"
else
# Regular deploy
oldid=$(< "$HOME/$APP/CONTAINER")
@@ -49,17 +43,11 @@ set -e; case "$1" in
id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web")
echo $id > "$HOME/$APP/CONTAINER"
fi
pluginhook post-deploy $APP $port
;;
###
logs)
CONTAINER=$(</home/git/$2/CONTAINER)
docker logs $CONTAINER | tail -n 100
;;
url)
echo "http://$(< "/home/git/$2/HOSTNAME")"
*)
pluginhook commands "$@"
;;
esac

View File

@@ -1,10 +0,0 @@
#!/bin/bash
APP="$1"; PORT="$2"; HOSTNAME="$3"
cat<<EOF
upstream $APP { server 127.0.0.1:$PORT; }
server {
listen 80;
server_name $HOSTNAME;
location / { proxy_pass http://$APP; }
}
EOF

View File

@@ -1,4 +0,0 @@
script
echo | sudo -u git nc -l -U /home/git/reload-nginx && /etc/init.d/nginx reload
end script
respawn

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e; case "$1" in
logs)
CONTAINER=$(</home/git/$2/CONTAINER)
docker logs $CONTAINER | tail -n 100
;;
url)
echo "http://$(< "/home/git/$2/ADDRESS")"
;;
esac

View File

@@ -0,0 +1,5 @@
#!/bin/bash
sed -i 's/docker -d$/docker -d -r=true/' /etc/init/docker.conf
echo $HOSTNAME > /home/git/HOSTNAME

2
plugins/WARNING Normal file
View File

@@ -0,0 +1,2 @@
Please note that the hooks in Dokku are experimental and are likely to change quite a bit.

8
plugins/nginx-vhosts/commands Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e; case "$1" in
url)
echo "http://$(< "/home/git/$2/VHOST")"
;;
esac

18
plugins/nginx-vhosts/install Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
apt-get install -y nginx dnsutils
cat<<EOF > /etc/init/nginx-reloader.conf
script
echo | sudo -u git nc -l -U /home/git/reload-nginx && /etc/init.d/nginx reload
end script
respawn
EOF
echo "include /home/git/*/nginx.conf;" > /etc/nginx/conf.d/dokku.conf
sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf
[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME > /home/git/VHOST
/etc/init.d/nginx start
start nginx-reloader || true

View File

@@ -0,0 +1,17 @@
#!/bin/bash
set -e
APP="$1"; PORT="$2"
if [[ -f "$HOME/VHOST" ]]; then
hostname="${APP/\//-}.$(< "$HOME/VHOST")"
cat<<EOF > $HOME/$APP/nginx.conf
upstream $APP { server 127.0.0.1:$PORT; }
server {
listen 80;
server_name $hostname;
location / { proxy_pass http://$APP; }
}
EOF
nc -U $HOME/reload-nginx
echo "$hostname" > "$HOME/$APP/VHOST"
fi