mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #270 from plietar/git-plugin
Replace gitreceive by a git plugin.
This commit is contained in:
10
Makefile
10
Makefile
@@ -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
|
||||
@@ -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}
|
||||
@@ -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
|
||||
|
||||
15
README.md
15
README.md
@@ -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!
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
22
dokku
22
dokku
@@ -2,6 +2,8 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
|
||||
export DOKKU_ROOT=${DOKKU_ROOT:="/home/dokku"}
|
||||
|
||||
case "$1" in
|
||||
receive)
|
||||
APP="$2"; IMAGE="app/$APP"
|
||||
@@ -38,8 +40,8 @@ case "$1" in
|
||||
release)
|
||||
APP="$2"; IMAGE="$3"
|
||||
pluginhook pre-release $APP $IMAGE
|
||||
if [[ -f "$HOME/$APP/ENV" ]]; then
|
||||
id=$(cat "$HOME/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh")
|
||||
if [[ -f "$DOKKU_ROOT/$APP/ENV" ]]; then
|
||||
id=$(cat "$DOKKU_ROOT/$APP/ENV" | docker run -i -a stdin $IMAGE /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/app-env.sh")
|
||||
test $(docker wait $id) -eq 0
|
||||
docker commit $id $IMAGE > /dev/null
|
||||
fi
|
||||
@@ -49,20 +51,20 @@ case "$1" in
|
||||
deploy)
|
||||
APP="$2"; IMAGE="$3"
|
||||
pluginhook pre-deploy $APP $IMAGE
|
||||
if [[ ! -f "$HOME/$APP/PORT" ]]; then
|
||||
if [[ ! -f "$DOKKU_ROOT/$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"
|
||||
echo $id > "$DOKKU_ROOT/$APP/CONTAINER"
|
||||
port=$(docker port $id 5000)
|
||||
echo $port > "$HOME/$APP/PORT"
|
||||
echo "http://$(< "$HOME/HOSTNAME"):$port" > "$HOME/$APP/URL"
|
||||
echo $port > "$DOKKU_ROOT/$APP/PORT"
|
||||
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
|
||||
else
|
||||
# Regular deploy
|
||||
oldid=$(< "$HOME/$APP/CONTAINER")
|
||||
oldid=$(< "$DOKKU_ROOT/$APP/CONTAINER")
|
||||
docker kill $oldid > /dev/null
|
||||
port=$(< "$HOME/$APP/PORT")
|
||||
port=$(< "$DOKKU_ROOT/$APP/PORT")
|
||||
id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web")
|
||||
echo $id > "$HOME/$APP/CONTAINER"
|
||||
echo $id > "$DOKKU_ROOT/$APP/CONTAINER"
|
||||
fi
|
||||
pluginhook post-deploy $APP $port
|
||||
;;
|
||||
@@ -84,7 +86,7 @@ case "$1" in
|
||||
|
||||
# temporary hack for https://github.com/progrium/dokku/issues/82
|
||||
deploy:all)
|
||||
for app in $(ls -d $HOME/*/); do
|
||||
for app in $(ls -d $DOKKU_ROOT/*/); do
|
||||
APP=$(basename $app);
|
||||
IMAGE="app/$APP"
|
||||
dokku deploy $APP $IMAGE
|
||||
|
||||
@@ -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 "$DOKKU_ROOT/$APP" ]]; then
|
||||
echo "App does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pluginhook pre-delete $APP
|
||||
ID=$(< "/home/git/$APP/CONTAINER")
|
||||
ID=$(< "$DOKKU_ROOT/$APP/CONTAINER")
|
||||
|
||||
docker stop $ID > /dev/null
|
||||
docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null &
|
||||
@@ -22,7 +22,7 @@ set -e; case "$1" in
|
||||
;;
|
||||
|
||||
logs)
|
||||
CONTAINER=$(</home/git/$2/CONTAINER)
|
||||
CONTAINER=$(<$DOKKU_ROOT/$2/CONTAINER)
|
||||
docker logs $CONTAINER | tail -n 100
|
||||
;;
|
||||
|
||||
@@ -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 "$DOKKU_ROOT/$APP" ]]; then
|
||||
echo "App $APP does not exist"
|
||||
exit 1
|
||||
fi
|
||||
@@ -42,13 +42,13 @@ set -e; case "$1" in
|
||||
|
||||
url)
|
||||
APP="$2";
|
||||
if [[ ! -d "/home/git/$APP" ]]; then
|
||||
if [[ ! -d "$DOKKU_ROOT/$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 "$DOKKU_ROOT/$APP/URL" ]]; then
|
||||
echo $(< "$DOKKU_ROOT/$APP/URL")
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
sed -i 's/docker -d$/docker -d -r=true/' /etc/init/docker.conf
|
||||
|
||||
echo $HOSTNAME > /home/git/HOSTNAME
|
||||
echo $HOSTNAME > $DOKKU_ROOT/HOSTNAME
|
||||
|
||||
|
||||
# temporary hack for https://github.com/progrium/dokku/issues/82
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
[[ -n $1 ]] && rm -r "/home/git/$1" > /dev/null
|
||||
[[ -n $1 ]] && rm -r "$DOKKU_ROOT/$1" > /dev/null
|
||||
|
||||
@@ -8,10 +8,10 @@ if [[ $1 == config ]] || [[ $1 == config:* ]]; then
|
||||
exit 1
|
||||
else
|
||||
APP="$2"
|
||||
ENV_FILE="/home/git/$APP/ENV"
|
||||
ENV_FILE="$DOKKU_ROOT/$APP/ENV"
|
||||
|
||||
# Check if app exists with the same name
|
||||
if [ ! -d "/home/git/$APP" ]; then
|
||||
if [ ! -d "$DOKKU_ROOT/$APP" ]; then
|
||||
echo "App $APP does not exist"
|
||||
exit 1
|
||||
fi
|
||||
@@ -105,7 +105,7 @@ case "$1" in
|
||||
exit 1
|
||||
fi
|
||||
|
||||
APP="$2"; APP_DIR="/home/git/$APP"
|
||||
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP"
|
||||
ENV_ADD=""
|
||||
ENV_TEMP=`cat "${ENV_FILE}"`
|
||||
ID=$(< "$APP_DIR/CONTAINER")
|
||||
@@ -149,7 +149,7 @@ case "$1" in
|
||||
exit 1
|
||||
fi
|
||||
|
||||
APP="$2"; APP_DIR="/home/git/$APP"
|
||||
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP"
|
||||
ENV_TEMP=`cat "${ENV_FILE}"`
|
||||
ID=$(< "$APP_DIR/CONTAINER")
|
||||
VARS="${*:3}"
|
||||
|
||||
40
plugins/git/commands
Executable file
40
plugins/git/commands
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/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 | sed -u "s/^/"$'\e[1G'"/"
|
||||
fi
|
||||
|
||||
done
|
||||
;;
|
||||
|
||||
git-*)
|
||||
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
|
||||
APP_PATH=$DOKKU_ROOT/$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
|
||||
#!/usr/bin/env bash
|
||||
set -e; set -o pipefail;
|
||||
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP
|
||||
EOF
|
||||
chmod +x $PRERECEIVE_HOOK
|
||||
fi
|
||||
|
||||
args=$@
|
||||
git-shell -c "$args"
|
||||
;;
|
||||
|
||||
esac
|
||||
cat
|
||||
|
||||
@@ -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 $DOKKU_ROOT/*/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 > $DOKKU_ROOT/VHOST
|
||||
|
||||
/etc/init.d/nginx start
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
APP="$1"; PORT="$2"
|
||||
WILDCARD_SSL="$HOME/ssl"
|
||||
SSL="$HOME/$APP/ssl"
|
||||
WILDCARD_SSL="$DOKKU_ROOT/ssl"
|
||||
SSL="$DOKKU_ROOT/$APP/ssl"
|
||||
|
||||
if [[ -f "$HOME/VHOST" ]]; then
|
||||
VHOST=$(< "$HOME/VHOST")
|
||||
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
||||
VHOST=$(< "$DOKKU_ROOT/VHOST")
|
||||
SUBDOMAIN=${APP/%\.${VHOST}/}
|
||||
if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then
|
||||
hostname="${APP/\//-}"
|
||||
@@ -21,7 +21,7 @@ if [[ -f "$HOME/VHOST" ]]; then
|
||||
|
||||
# ssl based nginx.conf
|
||||
if [[ -n "$SSL_INUSE" ]]; then
|
||||
cat<<EOF > $HOME/$APP/nginx.conf
|
||||
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf
|
||||
upstream $APP { server 127.0.0.1:$PORT; }
|
||||
server {
|
||||
listen 80;
|
||||
@@ -54,10 +54,10 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "https://$hostname" > "$HOME/$APP/URL"
|
||||
echo "https://$hostname" > "$DOKKU_ROOT/$APP/URL"
|
||||
else
|
||||
# default nginx.conf
|
||||
cat<<EOF > $HOME/$APP/nginx.conf
|
||||
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf
|
||||
upstream $APP { server 127.0.0.1:$PORT; }
|
||||
server {
|
||||
listen 80;
|
||||
@@ -76,7 +76,7 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "http://$hostname" > "$HOME/$APP/URL"
|
||||
echo "http://$hostname" > "$DOKKU_ROOT/$APP/URL"
|
||||
fi
|
||||
pluginhook nginx-pre-reload $APP
|
||||
sudo /etc/init.d/nginx reload
|
||||
|
||||
2
receiver
2
receiver
@@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e; set -o pipefail; cat | dokku receive $1 | sed -u "s/^/"$'\e[1G'"/"
|
||||
@@ -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)
|
||||
|
||||
@@ -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 vagrant@dokku.me "sudo gitreceive upload-key test"
|
||||
cat $PUBLIC_KEY | ssh -o "StrictHostKeyChecking=no" -i ~/.vagrant.d/insecure_private_key vagrant@dokku.me "sudo sshcommand acl-add dokku test"
|
||||
|
||||
for app_path in apps/*; do
|
||||
|
||||
@@ -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!"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user