-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f8cf16
Showing
9 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Oliver Wilkie | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
REROKU_LIB_ROOT ?= /var/lib/reroku | ||
REROKU_ROOT ?= /home/reroku/reroku | ||
|
||
all: | ||
rm -rf build | ||
mkdir build | ||
cp -r nginx build/nginx | ||
|
||
install: all base_images | ||
sed -e "s+{{REROKU_ROOT}}+${REROKU_ROOT}+g" nginx/reroku.conf > /etc/nginx/conf.d/reroku.conf | ||
cp -r build ${REROKU_LIB_ROOT} | ||
cp reroku /usr/local/bin/reroku | ||
echo "%reroku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/reroku-nginx | ||
|
||
base_images: base_python_image | ||
|
||
base_python_image: | ||
cd images/python && docker build -t reroku/python . | ||
|
||
uninstall: | ||
rm -f /etc/nginx/conf.d/reroku.conf | ||
rm -rf ${REROKU_LIB_ROOT} | ||
rm -f /usr/local/bin/reroku | ||
rm -f /etc/sudoers.d/reroku-nginx |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# README | ||
|
||
## What is it? | ||
This is a proof-of-concept project demonstrating a distilled implementation of a mini-Heroku running on a Raspberry Pi 2. It is *heavily* inspired by the great [Dokku](https://github.com/dokku/dokku) project. | ||
|
||
Dokku does not run on the Pi because Dokku is built for a specific OS and processor architecture (Ubuntu 14 and x86). Reroku is designed to work with Raspbian and ARM. | ||
|
||
|
||
## Installation | ||
|
||
### Requirements | ||
|
||
- Raspberry PI 2 running [Hypriot's OS w.Docker](http://blog.hypriot.com/getting-started-with-docker-and-mac-on-the-raspberry-pi/) | ||
|
||
- Nginx | ||
|
||
``` | ||
sudo apt-get update && apt-get install nginx | ||
``` | ||
|
||
- SSHCommand | ||
|
||
``` | ||
git clone https://github.com/oliw/sshcommand.git | ||
git checkout oliverw/raspbian-support | ||
cd sshcommand | ||
sudo make install | ||
``` | ||
|
||
### Install | ||
|
||
``` | ||
sudo make install | ||
sudo sshcommand create reroku `which reroku` | ||
sudo usermod -aG docker reroku | ||
``` | ||
|
||
|
||
### Uninstall | ||
``` | ||
sudo make uninstall | ||
``` | ||
|
||
## Usage | ||
To deploy your APP to reroku: | ||
|
||
``` | ||
cd <APP> | ||
git remote add reroku reroku@<REROKU_URL>:<APP> | ||
git push reroku master | ||
open http://<APP>.<REROKU_URL> | ||
``` | ||
The default `REROKU_URL` is `raspberrypi`. If your network's DNS does not have a record in place, a quick hack is to edit the /etc/hosts file on the computer trying to access reroku. | ||
|
||
``` | ||
<RASPBERRY_PI_IP_ADDRESS> raspberrypi <APP>.raspberrypi | ||
``` | ||
|
||
## Caveats | ||
|
||
- Only python projects are currently supported | ||
- Your python project should serve `0.0.0.0:80` | ||
- Your project must include a Heroku-style Procfile with a web definition | ||
|
||
## Future Features | ||
|
||
- Environment Variables | ||
- Logs | ||
- App Management | ||
- DNS | ||
- Addons (e.g. Database) | ||
- Other base images e.g. (java, ruby) | ||
- Non-web dynos | ||
|
||
## Contacts | ||
|
||
- Feel free to file issues on this project's Github page though not this project is not actively worked on. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM resin/rpi-raspbian:wheezy | ||
MAINTAINER [email protected] | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
python \ | ||
python-dev \ | ||
python-pip \ | ||
python-greenlet \ | ||
python-gevent \ | ||
--no-install-recommends \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& pip install -U pip wheel setuptools | ||
|
||
ADD build /build | ||
RUN chmod +x /build | ||
|
||
ADD start /start | ||
RUN chmod +x /start |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
pushd /app | ||
pip install -r requirements.txt | ||
popd |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
set -x | ||
set -eo pipefail | ||
|
||
pushd /app | ||
|
||
COMMAND=$(grep web Procfile | awk -F": " '{$1=""; print $0}') | ||
PORT=80 eval $COMMAND | ||
popd |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include {{REROKU_ROOT}}/*/nginx.conf; | ||
server_tokens off; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
server { | ||
listen [::]:80; | ||
listen 80; | ||
server_name {{APP}}.{{HOST}}; | ||
access_log /var/log/nginx/{{APP}}-access.log; | ||
error_log /var/log/nginx/{{APP}}-error.log; | ||
|
||
location / { | ||
proxy_pass http://{{APP}}; | ||
proxy_http_version 1.1; | ||
} | ||
} | ||
|
||
upstream {{APP}} { | ||
server {{IP}}:{{PORT}}; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
export REROKU_ROOT=${REROKU_ROOT:=/home/reroku/reroku} | ||
export REROKU_LIB_DIR=${REROKU_LIB_DIR:=/var/lib/reroku} | ||
export HOST=${HOST:=raspberrypi} | ||
|
||
case "$1" in | ||
receive) | ||
echo "Received new app tar..." | ||
APP=$2 | ||
cat | reroku build $APP && reroku release $APP | ||
reroku deploy $APP | ||
;; | ||
build) | ||
echo "Building..." | ||
BASE_IMAGE='reroku/python' | ||
APP_IMAGE=$2 | ||
id=$(cat | docker run -i -a stdin $BASE_IMAGE /bin/bash -c "mkdir -p /app && tar xf - -C /app") | ||
test "$(docker wait $id)" -eq 0 | ||
docker commit $id $APP_IMAGE > /dev/null | ||
|
||
id=$(docker run -d $APP_IMAGE /build) | ||
docker attach $id | ||
test "$(docker wait $id)" -eq 0 | ||
docker commit $id $APP_IMAGE > /dev/null | ||
;; | ||
release) | ||
echo "Releasing..." | ||
# TODO set environment variables etc | ||
;; | ||
deploy) | ||
echo "Deploying..." | ||
APP=$2 | ||
APP_IMAGE=$APP | ||
RUNNING_IDS=$(docker ps -q --filter="ancestor=$APP_IMAGE") | ||
# start container | ||
id=$(docker run -d $APP_IMAGE /start) | ||
# create new nginx.config | ||
ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $id) | ||
port=80 | ||
|
||
sed -e "s/{{APP}}/$APP/g; s/{{HOST}}/$HOST/g; s/{{IP}}/$ip/g; s/{{PORT}}/$port/g;" $REROKU_LIB_DIR/nginx/template/nginx.conf.template > $REROKU_ROOT/$APP/nginx.conf | ||
|
||
# restart nginx | ||
sudo /etc/init.d/nginx reload > /dev/null | ||
# stop old ones | ||
if [[ ! -z $RUNNING_IDS ]]; then | ||
echo $RUNNING_IDS | while read line ; do docker stop $line; docker rm $line; done | ||
fi | ||
# prosper | ||
;; | ||
git-hook) | ||
APP=$2 | ||
|
||
while read oldrev newrev refname | ||
do | ||
if [[ $refname = "refs/heads/master" ]] ; then | ||
git archive $newrev | reroku receive $APP | ||
fi | ||
done | ||
;; | ||
git-*) | ||
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')" | ||
APP_PATH=$REROKU_ROOT/$APP | ||
|
||
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then | ||
git init --bare $APP_PATH > /dev/null | ||
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" | ||
cat > $PRERECEIVE_HOOK <<EOF | ||
#!/usr/bin/env bash | ||
set -e; set -o pipefail; | ||
cat | REROKU_ROOT="$REROKU_ROOT" reroku git-hook $APP | ||
EOF | ||
chmod +x $PRERECEIVE_HOOK | ||
fi | ||
|
||
if [[ $1 == "git-receive-pack" ]]; then | ||
args="$1 '$APP_PATH'" | ||
else | ||
args=$* | ||
fi | ||
git-shell -c "$args" | ||
;; | ||
*) | ||
echo 'Not implemented yet' | ||
;; | ||
esac |