diff --git a/Makefile b/Makefile index 077824657..79f7f73d7 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,6 @@ all: install install: gitreceive sshcommand cp dokku /usr/local/bin/dokku cp receiver /home/git/receiver - cp deploystep /home/git/deploystep - cp buildstep /home/git/buildstep 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 @@ -23,4 +21,4 @@ sshcommand: sshcommand create dokku /usr/local/bin/dokku count: - cat receiver deploystep buildstep bootstrap.sh nginx-app-conf nginx-reloader.conf | wc -l \ No newline at end of file + cat receiver dokku bootstrap.sh nginx-app-conf nginx-reloader.conf | wc -l \ No newline at end of file diff --git a/bootstrap.sh b/bootstrap.sh index 4a1478ac7..1cbbd40dd 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,30 +1,26 @@ DOKKU_REPO=${DOKKU_REPO:-"https://github.com/progrium/dokku.git"} DOKKU_STACK=${DOKKU_STACK:-"https://s3.amazonaws.com/progrium-dokku/progrium_buildstep.tgz"} -DOCKER_PKG=${DOCKER_PKG:-"https://launchpad.net/~dotcloud/+archive/lxc-docker/+files/lxc-docker_0.4.2-1_amd64.deb"} set -e -apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y linux-image-extra-`uname -r` -apt-get install -y git nginx make curl dnsutils - -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 -rm /tmp/lxc-docker_0.4.2-1_amd64.deb - -sed -i.bak 's/docker -d/docker -d -r=true/' /etc/init/docker.conf # Docker should restart containers +apt-get install -y python-software-properties +add-apt-repository -y ppa:dotcloud/lxc-docker +apt-get update && apt-get install -y lxc-docker git nginx make curl dnsutils cd ~ && git clone ${DOKKU_REPO} cd dokku && make install + curl "$DOKKU_STACK" | gunzip -cd | docker import - progrium/buildstep -[[ -f /etc/nginx/nginx.conf ]] && sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/nginx/nginx.conf +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 -[[ $(dig +short $HOSTNAME) ]] && HOSTFILE=DOMAIN || HOSTFILE=HOSTNAME -echo $HOSTNAME > /home/git/$HOSTFILE - 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\"" diff --git a/dokku b/dokku index d61df9d89..037569505 100755 --- a/dokku +++ b/dokku @@ -1,5 +1,58 @@ #!/bin/bash -case "$1" in +set -e; case "$1" in + receive) + APP="$2"; IMAGE="app/$APP" + echo "-----> Building $APP ..." + cat | dokku build $IMAGE + echo "=====> Build complete!" + echo "-----> Deploying $APP ..." + dokku deploy $APP $IMAGE + echo "=====> Application deployed:" + echo " http://$(< "$HOME/$APP/HOSTNAME")" + 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 + docker commit $id $IMAGE > /dev/null + ;; + + deploy) + APP="$1"; IMAGE="$2" + if [[ ! -f "$HOME/$APP/PORT" ]]; then + # First deploy + id=$(docker run -d -p 5000 -e PORT=5000 $IMAGE /bin/bash -c "/start web") + 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" + else + # Regular deploy + oldid=$(< "$HOME/$APP/CONTAINER") + docker kill $oldid > /dev/null + port=$(< "$HOME/$APP/PORT") + id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web") + echo $id > "$HOME/$APP/CONTAINER" + fi + ;; + +### + logs) CONTAINER=$( Building $APP ..." -cat | $HOME/buildstep $CONTAINER -echo "-----> Build complete!" - -echo "-----> Deploying $APP ..." -$HOME/deploystep $APP $CONTAINER -echo "-----> Application deployed:" -echo " http://$(< "$HOME/$APP/HOSTNAME")" -echo \ No newline at end of file +set -e; cat | dokku receive $1 \ No newline at end of file