-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from miraculixx/fix-otpversion
Fix otpversion
- Loading branch information
Showing
8 changed files
with
198 additions
and
18 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
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 |
---|---|---|
|
@@ -13,8 +13,12 @@ MAINTAINER Pablo Fredrikson <[email protected]> | |
RUN \ | ||
apt-get update && \ | ||
apt-get install -y openjdk-7-jre wget && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
rm -rf /var/lib/apt/lists/* && \ | ||
mkdir -p /var/otp/pdx && \ | ||
echo "downloading otp" && \ | ||
cd /var/otp && \ | ||
wget -S -nv -O /var/otp/otp.jar http://dev.opentripplanner.org/jars/otp-0.14.0.jar | ||
|
||
ADD build.sh /root/ | ||
RUN chmod +x /root/build.sh | ||
|
||
|
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 |
---|---|---|
@@ -1,27 +1,35 @@ | ||
#!/bin/bash | ||
|
||
|
||
# Getting the urls and environment variables for otp | ||
while getopts ":u:e:" opt | ||
do | ||
case $opt in | ||
u ) urls=$OPTARG;; | ||
e ) envs=$OPTARG;; | ||
u ) urls=$OPTARG;; | ||
e ) envs=$OPTARG;; | ||
r ) router=$OPTARG;; | ||
esac | ||
done | ||
|
||
OTP_BASE=/var/otp | ||
OTP_GRAPHS=$OTP_BASE/graphs | ||
OTP_ROUTER=${router:-default} | ||
|
||
mkdir -p $OTP_GRAPHS | ||
|
||
for url in $urls; do | ||
wget -q -P /var/otp/pdx/ $url | ||
echo "downloading $url" | ||
wget -S -nv -P $OTP_GRAPHS/$OTP_ROUTER $url || echo "-- error" | ||
done | ||
|
||
# Defining the env variables | ||
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64" | ||
mkdir -p /var/otp/pdx && \ | ||
#mkdir -p /var/otp/pdx && \ | ||
|
||
# Let's build the maps | ||
cd /var/otp && \ | ||
wget -q -O /var/otp/otp.jar http://dev.opentripplanner.org/jars/otp-latest-master.jar && \ | ||
java -Xmx8G -jar /var/otp/otp.jar --build /var/otp/pdx $envs | ||
echo "generating graph" | ||
java -Xmx8G -jar /var/otp/otp.jar --build $OTP_GRAPHS/$OTP_ROUTER $envs | ||
|
||
# Moving the generated graph to the shared dir | ||
mkdir -p /var/otp/graphs && \ | ||
mv /var/otp/pdx/Graph.obj /var/otp/graphs/ | ||
echo "finalizing" | ||
find $OTP_GRAPHS |
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,125 @@ | ||
from fabric.context_managers import settings, prefix, cd, lcd, shell_env | ||
from fabric.contrib.project import rsync_project | ||
from fabric.decorators import task, roles | ||
from fabric.operations import local, prompt, run, put | ||
from fabric.state import env | ||
from fabric.tasks import execute | ||
import time | ||
from dockerfabric import tasks as docker | ||
|
||
|
||
# see https://github.com/merll/docker-fabric | ||
env.docker_tunnel_local_port = 22024 # or any other available port above 1024 of your choice | ||
# see http://stackoverflow.com/a/28382014 | ||
env.use_ssh_config = True | ||
|
||
running_locally = lambda : not env.hosts or len(env.hosts) == 0 | ||
|
||
def xrun(cmd, *args, **kwargs): | ||
if running_locally(): | ||
local(cmd, *args, **kwargs) | ||
else: | ||
run(cmd, *args, **kwargs) | ||
|
||
@task | ||
def build_builder(): | ||
""" | ||
build the builder | ||
""" | ||
xrun('docker build -t opentripplanner:builder builder') | ||
xrun('docker images | grep opentripplanner') | ||
|
||
@task | ||
def build_server(): | ||
""" | ||
build the server | ||
""" | ||
xrun('docker build -t opentripplanner:server server') | ||
xrun('docker images | grep opentripplanner') | ||
|
||
@task | ||
def build_nginx(): | ||
""" | ||
build the nginx image | ||
""" | ||
xrun('docker build -t opentripplanner:nginx nginx ') | ||
xrun('docker images | grep opentripplanner') | ||
|
||
@task | ||
def go(name=None, port=None, urls=None, params=None, build=False, router=False): | ||
""" | ||
run the server, build the graph, restart the server | ||
:param name: the name of the image, defaults to 'otpserver' | ||
:param port: the host port to serve at, defaults to 80 | ||
:param urls: list of URL files to download (gtfs, pdx) | ||
:param params: list of parameters to run the server | ||
""" | ||
params = params or '' | ||
assert urls, "need at least one gtfs file (checkout http://www.gtfs-data-exchange.com/agencies)" | ||
opts = { | ||
'name' : name or 'otpserver', | ||
'urls' : ' '.join(urls.split(',')), | ||
'params' : ' '.join(params.split(',')), | ||
'port' : port or 80, | ||
'router' : router or 'default' | ||
} | ||
if build: | ||
if not running_locally(): | ||
target = './otp-dockerdeploy' | ||
tmptar = '/tmp/otp-dockerdeploy.tgz' | ||
run('mkdir -p %s' % target) | ||
local('tar -czf %s --exclude .git .' % tmptar) | ||
put(tmptar, tmptar) | ||
run('tar -C %s -xzf %s' % (target, tmptar)) | ||
run('docker ps') | ||
with cd(target): | ||
execute(build_builder) | ||
execute(build_server) | ||
else: | ||
execute(build_builder) | ||
execute(build_server) | ||
cmd_rmserver = ( | ||
'docker rm -f {name} 2>&1 /dev/null' | ||
).format(**opts) | ||
cmd_server = ( | ||
'docker run ' | ||
' -p {port}:8080 -d' | ||
' --name {name}' | ||
' opentripplanner:server ' | ||
' --router {router} --server ' | ||
).format(**opts) | ||
cmd_builder = ( | ||
'docker run --volumes-from {name}' | ||
' opentripplanner:builder ' | ||
' -u "{urls}" -e "{params}"' | ||
).format(**opts) | ||
cmd_restart = ( | ||
'docker restart {name}' | ||
).format(**opts) | ||
# be nice and tell what we're doing | ||
print "[INFO] Running with options %s" % opts | ||
# run the server (delete existing server first) | ||
with settings(warn_only=True): | ||
xrun(cmd_rmserver) | ||
xrun(cmd_server) | ||
# build the graph | ||
time.sleep(10) | ||
xrun(cmd_builder) | ||
# restart the server | ||
xrun(cmd_restart) | ||
# report success | ||
print "[INFO] server {name} running at http://localhost:{port}".format(**opts) | ||
|
||
@task | ||
def dockerrm(images=None, containers=None): | ||
""" | ||
mass remove images and containers | ||
""" | ||
prompt('Are you sure? Press Ctrl-C otherwise.') | ||
xrun('docker ps --all | grep Exited | cut -c1-19 | xargs -L1 docker rm') | ||
xrun('docker images | grep "6 months" | cut -c 35-65 | xargs -L1 docker rmi') | ||
|
||
@task | ||
def enter(name=None): | ||
xrun('PID=$(docker inspect --format {{.State.Pid}} %s) && nsenter --target $PID --mount' % name) |
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,8 @@ | ||
#!/bin/bash | ||
# run this to install required software on the server | ||
# | ||
# sudo ./install.ch | ||
# | ||
apt-get install python-pip && pip -q install docker-py | ||
apt-get install docker | ||
pip install -r requirements.txt |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
|
||
# Starting nginx on the foreground | ||
system("/usr/sbin/nginx -g \"daemon 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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
== SERVER | ||
|
||
Docker > 1.3 | ||
|
||
apt-get install python-pip && pip -q install docker-py | ||
fabric | ||
docker-fabric==0.3.2 |
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