From 17953fc5a024e118efee5cb957d181f81b771b2b Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 10:37:32 -0500 Subject: [PATCH 1/7] initial attempt at plugins --- Makefile | 10 +++++++--- bootstrap.sh | 12 +++--------- dokku | 12 +++--------- plugins/00_dokku-standard/commands | 17 +++++++++++++++++ plugins/00_dokku-standard/install | 5 +++++ plugins/WARNING | 2 ++ plugins/nginx-vhosts/install | 18 ++++++++++++++++++ 7 files changed, 55 insertions(+), 21 deletions(-) create mode 100755 plugins/00_dokku-standard/commands create mode 100755 plugins/00_dokku-standard/install create mode 100644 plugins/WARNING create mode 100755 plugins/nginx-vhosts/install diff --git a/Makefile b/Makefile index 79f7f73d7..b37fec97e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ 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 + cp -r plugins /home/git/.plugins gitreceive: wget -qO /usr/local/bin/gitreceive ${GITRECEIVE_URL} @@ -20,5 +20,9 @@ sshcommand: chmod +x /usr/local/bin/sshcommand sshcommand create dokku /usr/local/bin/dokku +pluginhook: + wget -qO ${PLUGINHOOK_URL} /tmp/pluginhook_0.1.0_amd64.deb + cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb + count: 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 2b8cd37e5..d68e12b7f 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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,14 +15,8 @@ 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 +PLUGINPATH=/home/git/.plugins +pluginhook install echo echo "Be sure to upload a public key for your user:" diff --git a/dokku b/dokku index b4505872a..341a81f53 100755 --- a/dokku +++ b/dokku @@ -1,4 +1,5 @@ #!/bin/bash +PLUGIN_PATH="$HOME/.plugins" set -e; case "$1" in receive) APP="$2"; IMAGE="app/$APP" @@ -51,15 +52,8 @@ set -e; case "$1" in fi ;; -### - - logs) - CONTAINER=$( /home/git/HOSTNAME \ No newline at end of file diff --git a/plugins/WARNING b/plugins/WARNING new file mode 100644 index 000000000..d3eee9aac --- /dev/null +++ b/plugins/WARNING @@ -0,0 +1,2 @@ + +Please note that the hooks in Dokku are experimental and are likely to change quite a bit. \ No newline at end of file diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install new file mode 100755 index 000000000..1c7fa74ca --- /dev/null +++ b/plugins/nginx-vhosts/install @@ -0,0 +1,18 @@ +#!/bin/bash +apt-get install -y nginx dnsutils + +cat< /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 From 1ebfc9486a1f007189252914d6a217a9784cb48d Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 10:41:47 -0500 Subject: [PATCH 2/7] forgot how to use wget --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b37fec97e..b8529d87e 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ sshcommand: sshcommand create dokku /usr/local/bin/dokku pluginhook: - wget -qO ${PLUGINHOOK_URL} /tmp/pluginhook_0.1.0_amd64.deb + wget -qO /tmp/pluginhook_0.1.0_amd64.deb ${PLUGINHOOK_URL} cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb count: From 6be113f7ded89e800d10f256bdc68f6d5784e38c Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 11:02:40 -0500 Subject: [PATCH 3/7] using absolute path for plugins --- Makefile | 3 ++- bootstrap.sh | 2 +- dokku | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b8529d87e..76223318d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ 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 -r plugins /home/git/.plugins + mkdir -p /var/lib/dokku/plugins + cp -r plugins/* /var/lib/dokku/plugins gitreceive: wget -qO /usr/local/bin/gitreceive ${GITRECEIVE_URL} diff --git a/bootstrap.sh b/bootstrap.sh index d68e12b7f..67183a241 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -15,7 +15,7 @@ cd dokku && make install curl "$DOKKU_STACK" | gunzip -cd | docker import - progrium/buildstep -PLUGINPATH=/home/git/.plugins +PLUGIN_PATH=/var/lib/dokku/plugins pluginhook install echo diff --git a/dokku b/dokku index 341a81f53..4c30ed233 100755 --- a/dokku +++ b/dokku @@ -1,5 +1,5 @@ #!/bin/bash -PLUGIN_PATH="$HOME/.plugins" +export PLUGIN_PATH="/var/lib/dokku/plugins" set -e; case "$1" in receive) APP="$2"; IMAGE="app/$APP" @@ -53,6 +53,7 @@ set -e; case "$1" in ;; *) + shift pluginhook commands "$@" ;; From 79b099e4012017251d1897fa5a540c52d583b420 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 11:13:23 -0500 Subject: [PATCH 4/7] moving install hook trigger into make install --- Makefile | 3 ++- bootstrap.sh | 3 --- plugins/00_dokku-standard/install | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 76223318d..6f8564ff9 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ install: gitreceive sshcommand pluginhook cp nginx-app-conf /home/git/nginx-app-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} @@ -26,4 +27,4 @@ pluginhook: cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb count: - cat receiver dokku bootstrap.sh nginx-app-conf nginx-reloader.conf | wc -l \ No newline at end of file + cat receiver dokku bootstrap.sh nginx-app-conf | wc -l \ No newline at end of file diff --git a/bootstrap.sh b/bootstrap.sh index 67183a241..7b59ea115 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -15,9 +15,6 @@ cd dokku && make install curl "$DOKKU_STACK" | gunzip -cd | docker import - progrium/buildstep -PLUGIN_PATH=/var/lib/dokku/plugins -pluginhook install - 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/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index aff71d664..8009189a7 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -1,5 +1,5 @@ #!/bin/bash -sed -i 's/docker -d/docker -d -r=true/' /etc/init/docker.conf +[[ $(cat /etc/init/docker.conf | grep r=true) ]] || sed -i 's/docker -d/docker -d -r=true/' /etc/init/docker.conf echo $HOSTNAME > /home/git/HOSTNAME \ No newline at end of file From 51dc343630873229fcba20097acc8174d5b2c764 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 11:15:13 -0500 Subject: [PATCH 5/7] make sure to not fail --- plugins/nginx-vhosts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 1c7fa74ca..96c7dcc7f 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -15,4 +15,4 @@ sed -i 's/# server_names_hash_bucket_size/server_names_hash_bucket_size/' /etc/n [[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME > /home/git/VHOST /etc/init.d/nginx start -start nginx-reloader +start nginx-reloader || true From c4fd6d620bbc82bc39b0a5890c795471d7866eb8 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 11:39:05 -0500 Subject: [PATCH 6/7] nginx vhosts as a plugin? --- Makefile | 3 +-- dokku | 19 ++++++------------- nginx-app-conf | 10 ---------- nginx-reloader.conf | 4 ---- plugins/00_dokku-standard/commands | 7 +------ plugins/nginx-vhosts/commands | 8 ++++++++ plugins/nginx-vhosts/post-deploy | 17 +++++++++++++++++ 7 files changed, 33 insertions(+), 35 deletions(-) delete mode 100755 nginx-app-conf delete mode 100644 nginx-reloader.conf create mode 100755 plugins/nginx-vhosts/commands create mode 100755 plugins/nginx-vhosts/post-deploy diff --git a/Makefile b/Makefile index 6f8564ff9..bace8047f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ all: install install: gitreceive sshcommand pluginhook cp dokku /usr/local/bin/dokku cp receiver /home/git/receiver - cp nginx-app-conf /home/git/nginx-app-conf mkdir -p /var/lib/dokku/plugins cp -r plugins/* /var/lib/dokku/plugins PLUGIN_PATH=/var/lib/dokku/plugins pluginhook install @@ -27,4 +26,4 @@ pluginhook: cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb count: - cat receiver dokku bootstrap.sh nginx-app-conf | wc -l \ No newline at end of file + cat receiver dokku bootstrap.sh | wc -l \ No newline at end of file diff --git a/dokku b/dokku index 4c30ed233..6dd103737 100755 --- a/dokku +++ b/dokku @@ -1,6 +1,7 @@ #!/bin/bash +set -e export PLUGIN_PATH="/var/lib/dokku/plugins" -set -e; case "$1" in +case "$1" in receive) APP="$2"; IMAGE="app/$APP" echo "-----> Building $APP ..." @@ -9,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 @@ -34,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") @@ -50,10 +43,10 @@ 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 ;; *) - shift pluginhook commands "$@" ;; diff --git a/nginx-app-conf b/nginx-app-conf deleted file mode 100755 index 3ac9236cb..000000000 --- a/nginx-app-conf +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -APP="$1"; PORT="$2"; HOSTNAME="$3" -cat< $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 \ No newline at end of file From 5c0f7320cfe0a92630a5659208297160431c43d6 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Sun, 30 Jun 2013 11:45:27 -0500 Subject: [PATCH 7/7] doing it the mike-park way --- plugins/00_dokku-standard/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index 8009189a7..6a570b9d6 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -1,5 +1,5 @@ #!/bin/bash -[[ $(cat /etc/init/docker.conf | grep r=true) ]] || sed -i 's/docker -d/docker -d -r=true/' /etc/init/docker.conf +sed -i 's/docker -d$/docker -d -r=true/' /etc/init/docker.conf echo $HOSTNAME > /home/git/HOSTNAME \ No newline at end of file