nginx vhosts as a plugin?
This commit is contained in:
3
Makefile
3
Makefile
@@ -7,7 +7,6 @@ all: install
|
|||||||
install: gitreceive sshcommand pluginhook
|
install: gitreceive sshcommand pluginhook
|
||||||
cp dokku /usr/local/bin/dokku
|
cp dokku /usr/local/bin/dokku
|
||||||
cp receiver /home/git/receiver
|
cp receiver /home/git/receiver
|
||||||
cp nginx-app-conf /home/git/nginx-app-conf
|
|
||||||
mkdir -p /var/lib/dokku/plugins
|
mkdir -p /var/lib/dokku/plugins
|
||||||
cp -r plugins/* /var/lib/dokku/plugins
|
cp -r plugins/* /var/lib/dokku/plugins
|
||||||
PLUGIN_PATH=/var/lib/dokku/plugins pluginhook install
|
PLUGIN_PATH=/var/lib/dokku/plugins pluginhook install
|
||||||
@@ -27,4 +26,4 @@ pluginhook:
|
|||||||
cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb
|
cd /tmp && dpkg -i pluginhook_0.1.0_amd64.deb
|
||||||
|
|
||||||
count:
|
count:
|
||||||
cat receiver dokku bootstrap.sh nginx-app-conf | wc -l
|
cat receiver dokku bootstrap.sh | wc -l
|
||||||
19
dokku
19
dokku
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
export PLUGIN_PATH="/var/lib/dokku/plugins"
|
export PLUGIN_PATH="/var/lib/dokku/plugins"
|
||||||
set -e; case "$1" in
|
case "$1" in
|
||||||
receive)
|
receive)
|
||||||
APP="$2"; IMAGE="app/$APP"
|
APP="$2"; IMAGE="app/$APP"
|
||||||
echo "-----> Building $APP ..."
|
echo "-----> Building $APP ..."
|
||||||
@@ -9,17 +10,15 @@ set -e; case "$1" in
|
|||||||
echo "-----> Deploying $APP ..."
|
echo "-----> Deploying $APP ..."
|
||||||
dokku deploy $APP $IMAGE
|
dokku deploy $APP $IMAGE
|
||||||
echo "=====> Application deployed:"
|
echo "=====> Application deployed:"
|
||||||
echo " http://$(< "$HOME/$APP/HOSTNAME")"
|
echo " $(dokku url $APP)"
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
|
|
||||||
build)
|
build)
|
||||||
IMAGE="$2"
|
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")
|
id=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app")
|
||||||
test $(docker wait $id) -eq 0
|
test $(docker wait $id) -eq 0
|
||||||
docker commit $id $IMAGE > /dev/null
|
docker commit $id $IMAGE > /dev/null
|
||||||
# Run the builder script and attach to view output
|
|
||||||
id=$(docker run -d $IMAGE /build/builder)
|
id=$(docker run -d $IMAGE /build/builder)
|
||||||
docker attach $id
|
docker attach $id
|
||||||
test $(docker wait $id) -eq 0
|
test $(docker wait $id) -eq 0
|
||||||
@@ -34,14 +33,8 @@ set -e; case "$1" in
|
|||||||
echo $id > "$HOME/$APP/CONTAINER"
|
echo $id > "$HOME/$APP/CONTAINER"
|
||||||
port=$(docker port $id 5000)
|
port=$(docker port $id 5000)
|
||||||
echo $port > "$HOME/$APP/PORT"
|
echo $port > "$HOME/$APP/PORT"
|
||||||
if [[ -f "$HOME/DOMAIN" ]]; then
|
echo "$(< "$HOME/HOSTNAME"):$port" > "$HOME/$APP/ADDRESS"
|
||||||
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
|
else
|
||||||
# Regular deploy
|
# Regular deploy
|
||||||
oldid=$(< "$HOME/$APP/CONTAINER")
|
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")
|
id=$(docker run -d -p ":$port" -e "PORT=$port" $IMAGE /bin/bash -c "/start web")
|
||||||
echo $id > "$HOME/$APP/CONTAINER"
|
echo $id > "$HOME/$APP/CONTAINER"
|
||||||
fi
|
fi
|
||||||
|
pluginhook post-deploy $APP $port
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
shift
|
|
||||||
pluginhook commands "$@"
|
pluginhook commands "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
script
|
|
||||||
echo | sudo -u git nc -l -U /home/git/reload-nginx && /etc/init.d/nginx reload
|
|
||||||
end script
|
|
||||||
respawn
|
|
||||||
@@ -6,12 +6,7 @@ set -e; case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
url)
|
url)
|
||||||
echo "http://$(< "/home/git/$2/HOSTNAME")"
|
echo "http://$(< "/home/git/$2/ADDRESS")"
|
||||||
;;
|
|
||||||
|
|
||||||
test)
|
|
||||||
echo "Hello"
|
|
||||||
echo $2 $3 $4
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
8
plugins/nginx-vhosts/commands
Executable file
8
plugins/nginx-vhosts/commands
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e; case "$1" in
|
||||||
|
|
||||||
|
url)
|
||||||
|
echo "http://$(< "/home/git/$2/VHOST")"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
17
plugins/nginx-vhosts/post-deploy
Executable file
17
plugins/nginx-vhosts/post-deploy
Executable 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
|
||||||
Reference in New Issue
Block a user