Created
August 13, 2013 02:47
-
-
Save thehydroimpulse/6217425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# We need to do a few things here. | |
# 1) Build the repo | |
set -e; | |
APP="$2"; IMAGE="app/$APP"; NAME=$1 | |
META="$HOME/meta" | |
APPMETA="$META/$NAME" | |
# Create meta folder | |
if [ ! -d $META ]; then | |
mkdir $META | |
fi | |
# Check if the current app already running | |
if [ ! -f $APPMETA ]; then | |
touch $APPMETA # Create the file | |
fi | |
PROCID=$(head -1 $APPMETA) | |
ISRUNNING=false | |
# Check if it's empty or not | |
if [ -z "$PROCID" ]; then | |
# Empty | |
ISRUNNING=false | |
echo "-> No old processes found." | |
else | |
ISRUNNING=true | |
echo "-> We found old processes running." | |
fi | |
function build() { | |
echo "++ Building..." | |
id=$(cat | docker run -i -a stdin progrium/buildstep /bin/bash -c "mkdir -p /app && tar -xC /app") | |
test $(docker wait $id) -eq 0 | |
docker commit $id $IMAGE > /dev/null | |
id=$(docker run -d $IMAGE /build/builder) | |
docker attach $id | |
test $(docker wait $id) -eq 0 | |
docker commit $id $IMAGE > /dev/null | |
} | |
# 2) Deploy | |
function deploy() { | |
echo "++ Deploying..." | |
id=$(docker run -d -p 5000 -e PORT=5000 $IMAGE /bin/bash -c "/start web") | |
echo "++ Launched new container" | |
if $ISRUNNING ; then | |
echo "++ Stopping previous container..." | |
docker stop $PROCID | |
fi | |
echo "++ Cleaning up..." | |
rm $APPMETA | |
touch $APPMETA | |
echo $id > $APPMETA | |
echo "-----> Deploy was successful!" | |
} | |
build | |
deploy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Took some parts from Dokku but adjusted it for a different purpose. The goal of this is to create a deploy system for a distributed system. Servers are not directly connected to a domain.
This system assumes that the servers are sitting behind a load balancer of some sort and will use nginx to act as a reverse proxy to work with the dynamic ports that Docker assigns to the containers.
Previous versions of containers are terminated once new versions are up and running. This makes it possible for a zero-downtime deploy.