Skip to content

Commit

Permalink
Replace gitreceive by a git plugin.
Browse files Browse the repository at this point in the history
This removes the need for two distinct users.
Git pushes and dokku commands are sent using the same user.
  • Loading branch information
plietar committed Oct 28, 2013
1 parent 6350f37 commit 27d4bc8
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 39 deletions.
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
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
STACK_URL ?= github.com/progrium/buildstep
Expand All @@ -11,19 +10,13 @@ install: dependencies stack copyfiles plugins

copyfiles:
cp dokku /usr/local/bin/dokku
cp receiver /home/git/receiver
mkdir -p /var/lib/dokku/plugins
cp -r plugins/* /var/lib/dokku/plugins

plugins: pluginhook docker
dokku plugins-install

dependencies: gitreceive sshcommand pluginhook docker stack

gitreceive:
wget -qO /usr/local/bin/gitreceive ${GITRECEIVE_URL}
chmod +x /usr/local/bin/gitreceive
test -f /home/git/receiver || gitreceive init
dependencies: sshcommand pluginhook docker stack

sshcommand:
wget -qO /usr/local/bin/sshcommand ${SSHCOMMAND_URL}
Expand All @@ -36,7 +29,6 @@ pluginhook:

docker: aufs
egrep -i "^docker" /etc/group || groupadd docker
usermod -aG docker git
usermod -aG docker dokku
curl https://get.docker.io/gpg | apt-key add -
echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ This may take around 5 minutes. Certainly better than the several hours it takes

## Configuring

Set up a domain and a wildcard domain pointing to that host. Make sure `/home/git/VHOST` is set to this domain. By default it's set to whatever the hostname the host has. This file only created if the hostname can be resolved by dig (`dig +short $HOSTNAME`). Otherwise you have to create the file manually and set it to your prefered domain. If this file still not present when you push your app, dokku will publish the app with a port number (i.e. `http://example.com:49154` - note the missing subdomain).
Set up a domain and a wildcard domain pointing to that host. Make sure `/home/dokku/VHOST` is set to this domain. By default it's set to whatever the hostname the host has. This file only created if the hostname can be resolved by dig (`dig +short $HOSTNAME`). Otherwise you have to create the file manually and set it to your prefered domain. If this file still not present when you push your app, dokku will publish the app with a port number (i.e. `http://example.com:49154` - note the missing subdomain).

You'll have to add a public key associated with a username as it says at the end of the bootstrapper. You'll do something
like this from your local machine:

$ cat ~/.ssh/id_rsa.pub | ssh progriumapp.com "sudo gitreceive upload-key progrium"
$ cat ~/.ssh/id_rsa.pub | ssh progriumapp.com "sudo sshcommand acl-add dokku progrium"

That's it!

Expand All @@ -33,7 +33,7 @@ Please check the documentation for your particular build pack as you may need to
Let's deploy the [Heroku Node.js sample app](https://github.com/heroku/node-js-sample). All you have to do is add a remote to name the app. It's created on-the-fly.

$ cd node-js-sample
$ git remote add progrium git@progriumapp.com:node-js-app
$ git remote add progrium dokku@progriumapp.com:node-js-app
$ git push progrium master
Counting objects: 296, done.
Delta compression using up to 4 threads.
Expand Down Expand Up @@ -75,7 +75,7 @@ SSH onto the server, then execute:

Typically application requires some environment variables to be set up for proper run. Environment variables might contain some private data, like passwords and API keys, so it's not recommend to store them as part of source code.

To setup environment for your application, create file `/home/git/APP_NAME/ENV`. This file is a script that would expose all required environment variables, like:
To setup environment for your application, create file `/home/dokku/APP_NAME/ENV`. This file is a script that would expose all required environment variables, like:

export NODE_ENV=production
export MONGODB_PASSWORD=password
Expand All @@ -84,7 +84,7 @@ Next time the application is deployed, those variables would be exposed by `star

## SSL support

Dokku provides easy SSL support from the box. To enable SSL connection to your application, copy `.crt` and `.key` file into `/home/git/:app/ssl` folder (notice, file names should be `server.crt` and `server.key`, respectively). Redeployment of application will be needed to apply SSL configuration. Once it redeployed, application will be accessible by `https://` (redirection from `http://` is applied as well).
Dokku provides easy SSL support from the box. To enable SSL connection to your application, copy `.crt` and `.key` file into `/home/dokku/:app/ssl` folder (notice, file names should be `server.crt` and `server.key`, respectively). Redeployment of application will be needed to apply SSL configuration. Once it redeployed, application will be accessible by `https://` (redirection from `http://` is applied as well).

## Advanced installation (for development)

Expand All @@ -96,11 +96,11 @@ the repository and calling the install script. Example:
$ sudo make install

The `Makefile` allows source URLs to be overridden to include customizations from your own
repositories. The DOCKER_URL, GITRECEIVE_URL, PLUGINHOOK_URL, SSHCOMMAND_URL and STACK_URL
repositories. The DOCKER_URL, PLUGINHOOK_URL, SSHCOMMAND_URL and STACK_URL
environment variables may be set to override the defaults (see the `Makefile` for how these
apply). Example:

$ sudo GITRECEIVE_URL=https://raw.github.com/yourusername/gitreceive/master/gitreceive make install
$ sudo SSHCOMMAND_URL=https://raw.github.com/yourusername/sshcommand/master/gitreceive make install

## Advanced installation (bootstrap a server from your own repository)

Expand Down Expand Up @@ -153,7 +153,6 @@ You can use [Github Issues](https://github.com/progrium/dokku/issues), check [Tr

* [Docker](https://github.com/dotcloud/docker) - Container runtime and manager
* [Buildstep](https://github.com/progrium/buildstep) - Buildpack builder
* [gitreceive](https://github.com/progrium/gitreceive) - Git push interface
* [pluginhook](https://github.com/progrium/pluginhook) - Shell based plugins and hooks
* [sshcommand](https://github.com/progrium/sshcommand) - Fixed commands over SSH

Expand Down
14 changes: 7 additions & 7 deletions plugins/00_dokku-standard/commands
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ set -e; case "$1" in
exit 1
fi
APP="$2"; IMAGE="app/$APP";
if [[ ! -d "/home/git/$APP" ]]; then
if [[ ! -d "$HOME/$APP" ]]; then
echo "App does not exist"
exit 1
fi

pluginhook pre-delete $APP
ID=$(< "/home/git/$APP/CONTAINER")
ID=$(< "$HOME/$APP/CONTAINER")

docker stop $ID > /dev/null
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
Expand All @@ -22,7 +22,7 @@ set -e; case "$1" in
;;

logs)
CONTAINER=$(</home/git/$2/CONTAINER)
CONTAINER=$(<$HOME/$2/CONTAINER)
docker logs $CONTAINER | tail -n 100
;;

Expand All @@ -32,7 +32,7 @@ set -e; case "$1" in
exit 1
fi
APP="$2"; IMAGE="app/$APP"
if [[ ! -d "/home/git/$APP" ]]; then
if [[ ! -d "$HOME/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
Expand All @@ -42,13 +42,13 @@ set -e; case "$1" in

url)
APP="$2";
if [[ ! -d "/home/git/$APP" ]]; then
if [[ ! -d "$HOME/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi

if [[ -f "/home/git/$APP/URL" ]]; then
echo $(< "/home/git/$APP/URL")
if [[ -f "$HOME/$APP/URL" ]]; then
echo $(< "$HOME/$APP/URL")
fi
;;

Expand Down
4 changes: 2 additions & 2 deletions plugins/00_dokku-standard/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

sed -i 's/docker -d$/docker -d -r=true/' /etc/init/docker.conf

echo $HOSTNAME > /home/git/HOSTNAME
echo $HOSTNAME > $HOME/HOSTNAME


# temporary hack for https://github.com/progrium/dokku/issues/82
Expand All @@ -14,6 +14,6 @@ start on (started docker)
script
sleep 2 # give docker some time
sudo -i -u git /usr/local/bin/dokku deploy:all
sudo -i -u dokku /usr/local/bin/dokku deploy:all
end script
EOF
8 changes: 4 additions & 4 deletions plugins/config/commands
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ if [[ $1 == config ]] || [[ $1 == config:* ]]; then
exit 1
else
APP="$2"
ENV_FILE="/home/git/$APP/ENV"
ENV_FILE="$HOME/$APP/ENV"

# Check if app exists with the same name
if [ ! -d "/home/git/$APP" ]; then
if [ ! -d "$HOME/$APP" ]; then
echo "App $APP does not exist"
exit 1
fi
Expand Down Expand Up @@ -105,7 +105,7 @@ case "$1" in
exit 1
fi

APP="$2"; APP_DIR="/home/git/$APP"
APP="$2"; APP_DIR="$HOME/$APP"
ENV_ADD=""
ENV_TEMP=`cat "${ENV_FILE}"`
ID=$(< "$APP_DIR/CONTAINER")
Expand Down Expand Up @@ -149,7 +149,7 @@ case "$1" in
exit 1
fi

APP="$2"; APP_DIR="/home/git/$APP"
APP="$2"; APP_DIR="$HOME/$APP"
ENV_TEMP=`cat "${ENV_FILE}"`
ID=$(< "$APP_DIR/CONTAINER")
VARS="${*:3}"
Expand Down
39 changes: 39 additions & 0 deletions plugins/git/commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e;

case "$1" in
git-hook)
APP=$2

while read oldrev newrev refname
do
# Only run this script for the master branch. You can remove this
# if block if you wish to run it for others as well.
if [[ $refname = "refs/heads/master" ]] ; then
git archive $newrev | dokku receive $APP
fi

done
;;

git-*)
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
APP_PATH=$HOME/$APP

if [[ $1 == "git-receive-pack" && ! -d $APP_PATH ]]; then
git init --bare $APP_PATH > /dev/null
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
cat > $PRERECEIVE_HOOK <<EOF
#!/bin/bash
cat | dokku git-hook $APP
EOF
chmod +x $PRERECEIVE_HOOK
fi

args=$@
git-shell -c "$args"
;;

esac
cat

5 changes: 2 additions & 3 deletions plugins/nginx-vhosts/install
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ if ! grep -q dokku-nginx-reload "/etc/sudoers"; then
touch /etc/sudoers.tmp
cp /etc/sudoers /tmp/sudoers.new
echo "%dokku ALL=(ALL)NOPASSWD:/etc/init.d/nginx reload # dokku-nginx-reload" >> /tmp/sudoers.new
echo "%git ALL=(ALL)NOPASSWD:/etc/init.d/nginx reload # dokku-nginx-reload" >> /tmp/sudoers.new
EDITOR="cp /tmp/sudoers.new" visudo
rm /tmp/sudoers.new
fi

echo "include /home/git/*/nginx.conf;" > /etc/nginx/conf.d/dokku.conf
echo "include $HOME/*/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
[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME > $HOME/VHOST

/etc/init.d/nginx start
2 changes: 0 additions & 2 deletions receiver

This file was deleted.

1 change: 0 additions & 1 deletion tests/run_ec2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ set -e
echo "-----> Connecting and running bootstrap script..."
cat ../bootstrap.sh | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "HOSTNAME=$PUBLIC_IP sudo bash" 2>&1 | indent
echo "-----> Installing SSH public keys..."
cat ~/.ssh/id_rsa.pub | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "sudo gitreceive upload-key test" > /dev/null
cat ~/.ssh/id_rsa.pub | ssh -o "StrictHostKeyChecking=no" ubuntu@$PUBLIC_IP "sudo sshcommand acl-add dokku test" > /dev/null
for app_path in apps/*; do
app=$(basename $app_path)
Expand Down
1 change: 0 additions & 1 deletion tests/run_vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ cd "$(dirname $SELF)/.." && vagrant up | indent
cd "$(dirname $SELF)"

echo "-----> Installing SSH public keys..."
cat $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key [email protected] "sudo gitreceive upload-key test"
cat $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key [email protected] "sudo sshcommand acl-add dokku test"

for app_path in apps/*; do
Expand Down
4 changes: 2 additions & 2 deletions tests/test_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ git config user.name "Test Robot"
git add .
git commit -m 'initial commit'
REPO="test-$(basename $APP)-$RANDOM"
git remote add target git@$TARGET:$REPO
git remote add target dokku@$TARGET:$REPO
git push target master
URL=$(ssh dokku@$TARGET url $REPO)$FORWARDED_PORT
sleep 2
./check_deploy $URL && echo "-----> Deploy success!" || {
sleep 4
./check_deploy $URL && echo "-----> Deploy success!"
}
}

0 comments on commit 27d4bc8

Please sign in to comment.