Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save progrium/aa2a42683dec1f0adf17 to your computer and use it in GitHub Desktop.
Save progrium/aa2a42683dec1f0adf17 to your computer and use it in GitHub Desktop.
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