Skip to content

Instantly share code, notes, and snippets.

@rochacon
Last active January 2, 2016 16:09
Show Gist options
  • Save rochacon/8328621 to your computer and use it in GitHub Desktop.
Save rochacon/8328621 to your computer and use it in GitHub Desktop.
Simple flynn/gitreceiver-next receiver script to build and run a slug
#!/bin/bash
# This script will setup your server from scratch
set -e
# Setup Docker
curl -sL http://get.docker.io/ | bash
docker pull flynn/slugbuilder
docker pull flynn/slugrunner
# Setup gitreceived
curl -sL https://go.googlecode.com/files/go1.2.linux-amd64.tar.gz | tar xzC /usr/local
export PATH=/usr/local/go/bin:$PATH
export GOROOT=/usr/local/go
export GOPATH=/go
apt-get install -yq git
go get github.com/flynn/gitreceive-next/gitreceived
useradd -G docker -m -s /bin/bash git || true
su -c "mkdir -p /home/git/.ssh && ssh-keygen -t rsa -f /home/git/.ssh/id_rsa -N ''" git
su -c "wget -qO /home/git/receiver.sh https://gist.github.com/rochacon/8328621/raw/768e5eb07c8e4d13bd704f9de1e48f34ec2cbb4b/receiver.sh && chmod +x /home/git/receiver.sh" git
su -c "mkdir -p /home/git/{keys,repositories}" git
cat >/etc/init/gitreceived.conf <<EOF
start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]
setuid git
setgid docker
respawn
console log
chdir /home/git
exec /go/bin/gitreceived -p 2222 -k /home/git/keys -r /home/git/repositories /home/git/.ssh/id_rsa /home/git/receiver.sh
EOF
start gitreceived
#!/bin/bash
set -e
# XXX change this to your bucket URL and allow access for GET and PUT keys to your server
BUCKET="https://s3.amazonaws.com/slugs"
IMAGE="$BUCKET/$2.tgz"
PORT="$RANDOM"
URL="http://$(curl -sL 169.254.169.254/latest/meta-data/public-hostname):$PORT"
CACHE="/tmp/app-cache"
echo '-----> Builing image'
[[ ! -d "$CACHE" ]] && mkdir -p "$CACHE"
cat | docker run -i -a stdin -a stdout -v "$CACHE":/tmp/cache:rw flynn/slugbuilder "$IMAGE"
echo '-----> Starting container'
# FIXME run other processes other than web
id=$(docker run -d -i -e SLUG_URL="$IMAGE" -e PORT=8000 -p $PORT:8000 flynn/slugrunner start web)
echo "-----> $URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment