Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prototype of Dokku-like deploys (with "zero downtime") using Nginx appliance and slugbuilder/slugrunner
#!/bin/bash
set -eo pipefail
name="$1"
port="5000"
domain="$name.dokku.me"
vhost_config='{"upstream": {"%s": {"server": {"%s:%s": null}}}, "server": [{"listen": 80, "server_name": "%s", "location": {"/": {"proxy_pass": "http://%s"}}}]}'
mkdir -p "/tmp/$name"
cat | docker run -i -a stdin -a stdout -a stderr flynn/slugbuilder - | tar -C "/tmp/$name" -zxf -
old_ids="$(docker ps | ( grep "$name." || true ) | cut -d ' ' -f 1)"
docker run -d -p "$port" -e "PORT=$port" -v "/tmp/$name:/app" --name "$name.$RANDOM" flynn/slugrunner start web > /dev/null
sleep 1
internal_ip="$(docker inspect -f "{{.NetworkSettings.IPAddress}}" `docker ps -lq`)"
curl --fail -s -d "$(printf "$vhost_config" "$name" "$internal_ip" "$port" "$domain" "$name")" localhost:9000/v1/config/http
docker rm -f $old_ids > /dev/null 2>&1 || true
echo "=====> Application $name deployed:"
echo " http://$domain"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment