Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Blaser committed Apr 21, 2015
2 parents e646283 + 5dd55ec commit 132c7b4
Show file tree
Hide file tree
Showing 41 changed files with 620 additions and 243 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 HSR Hochschule für Technik, Rapperswil

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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Website: http://osmaxx.hsr.ch/


## Development
See `developmentEnvironment/` for instructions.
See https://github.com/geometalab/osmaxx-docs for documentations and `developmentEnvironment/` for instructions.


# Documentation
Expand Down
1 change: 1 addition & 0 deletions deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source.tar
79 changes: 79 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FROM debian:jessie

MAINTAINER Tobias Blaser <[email protected]>

# Update system
RUN apt-get update
RUN apt-get -y autoremove
RUN apt-get -y install apt-utils

# Install python 3
RUN apt-get -y install tar python3 python3-doc python3-setuptools python3-pip python-dev libpq-dev
RUN pip3 install virtualenv

# Install GEO libraries
RUN apt-get -y install binutils libgeos-3.4. # GEOS
RUN apt-get -y install libproj0 # PROJ.4
RUN apt-get -y install python-gdal # GDAL

# Install database
RUN apt-get -y install postgresql postgresql-client
RUN apt-get -y install postgis osmctools postgresql-9.4-postgis-2.1
RUN apt-get -y install python3-psycopg2
RUN service postgresql start

# Install apache
RUN apt-get -y install apache2 apache2-utils libapache2-mod-wsgi-py3
RUN a2enmod wsgi
RUN service apache2 restart

USER postgres
# Fix pg template ascii bug
# @source: http://stackoverflow.com/questions/16736891/pgerror-error-new-encoding-utf8-is-incompatible
RUN service postgresql start &&\
psql -c "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';" &&\
psql -c "DROP DATABASE template1;" &&\
psql -c "CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';" &&\
psql -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';" &&\
psql -c "\c template1" &&\
psql -c "VACUUM FREEZE;"

# Setup database
RUN service postgresql start &&\
psql -c "CREATE USER osmaxx WITH PASSWORD 'osmaxx';" &&\
psql -c "CREATE DATABASE osmaxx ENCODING 'UTF8';" &&\
psql -c "GRANT ALL PRIVILEGES ON DATABASE osmaxx TO osmaxx;"

RUN service postgresql start &&\
psql -c "CREATE EXTENSION postgis;" "osmaxx" &&\
psql -c "CREATE EXTENSION postgis_topology;" "osmaxx"
USER root

# Install osmaxx
RUN cd /var/www; if [ ! -d "eda" ]; then mkdir "eda"; fi; cd "eda"
RUN virtualenv-3.4 /var/www/eda/environment

ADD source.tar /var/www/eda/
COPY requirementsProduction.txt /var/www/eda/requirementsProduction.txt
RUN mv /var/www/eda/source /var/www/eda/projects;

RUN cd "/var/www/eda/projects"
RUN /var/www/eda/environment/bin/pip3 install -r /var/www/eda/requirementsProduction.txt
RUN service postgresql start &&\
/var/www/eda/environment/bin/python /var/www/eda/projects/manage.py migrate
RUN service postgresql start &&\
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '', 'osmaxx')" | /var/www/eda/environment/bin/python /var/www/eda/projects/manage.py shell

RUN mkdir /var/www/eda/projects/data; chown root:www-data /var/www/eda/projects/data; chmod 777 /var/www/eda/projects/data

# Create apache virtualhost
COPY osmaxxProduction.vhost /etc/apache2/sites-available/osmaxx.conf
RUN ln -s /etc/apache2/sites-available/osmaxx.conf /etc/apache2/sites-enabled/osmaxx.conf
RUN a2ensite osmaxx

COPY startApplication.sh /usr/local/bin/startApplication.sh
RUN chmod +x /usr/local/bin/startApplication.sh

EXPOSE 80

CMD /usr/local/bin/startApplication.sh && /bin/bash
79 changes: 79 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Deployment container for Docker


## Docker installation

See https://docs.docker.com/installation/ubuntulinux/

1. Be sure your kernel version is 3.10 or newer and wget is installed
2. Install docker:

```shell
wget -qO- https://get.docker.com/ | sh
```
3. Create a docker group and add you

```shell
sudo usermod -aG docker {yourUserName}
```


## Build & run container

1. Copy current source to docker data:

```shell
# use a clean repo to tar the source
cd /tmp
git clone [email protected]:geometalab/osmaxx.git --branch master --single-branch && cd osmaxx
git submodule init && git submodule update
tar -cf deployment/source.tar source
# git archive not working with submodules
# git archive master --format tar --output deployment/source.tar
# tar from not-empty repository:
tar -cf deployment/source.tar --exclude='*.git' --exclude='*.od*' --exclude='*.gitignore' --exclude='*.gitmodules' --exclude='*developmentEnvironment/' --exclude='*data/' --exclude='*.idea' --exclude='*test_db.sqlite' --exclude='*__pycache__/' source
```
2. Build image:

```shell
docker build --tag=osmaxx --no-cache=true deployment/
```
3. Run container:

```shell
# map host port 8080 to port 80 of container
docker run -d -p 8080:80 osmaxx
```
**Note:** If you start the container with custom arguments (e.g. *docker run osmaxx /bin/bash*) you will override the CMD command to start the server.
So you need to start the server by your self.


## Management

Run container interactive:
```shell
(sudo) docker run -i -t osmaxx /bin/bash
```

Show running containers:
```shell
docker ps
```

Stop running container:
```shell
docker stop {containerID}
```

Save docker image to file:
```shell
docker save osmaxx > /tmp/osmaxx-alpha1.docker-img.tar
```

Load docker image from file:
```shell
docker load < /tmp/osmaxx-alpha1.docker-img.tar
```
14 changes: 14 additions & 0 deletions deployment/osmaxxProduction.vhost
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WSGIDaemonProcess osmaxx.dev python-path=/var/www/eda/environment/:/var/www/eda/environment/lib/python3.4/site-packages
WSGIProcessGroup osmaxx.dev

ErrorLog /var/log/apache2/osmaxx.log
WSGIScriptAlias / /var/www/eda/projects/osmaxx/wsgi.py

Alias "/static/admin" "/var/www/eda/environment/lib/python3.4/site-packages/django/contrib/admin/static/admin"
Alias "/static/excerptexport" "/var/www/eda/projects/excerptexport/static/excerptexport"

<Directory /var/www/eda/projects>
<Files osmaxx/wsgi.py>
Require all granted
</Files>
</Directory>
3 changes: 3 additions & 0 deletions deployment/requirementsProduction.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Django==1.7.4
django-enumfield==1.2
psycopg2==2.6
3 changes: 3 additions & 0 deletions deployment/startApplication.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

service postgresql start && /usr/sbin/apache2ctl -D FOREGROUND
43 changes: 34 additions & 9 deletions developmentEnvironment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ For developers with write access to this repository:

A vagrant box is provided as part of this project's repository.

## Local prerequisites

for commiting and using the pre-commit hook (which really should be used) flake8 needs to be installed on
the local system/machine.

For Ubuntu and Debian this is:

`sudo apt-get install python3-flake8`

Then the pre-commit hook can be linked to the hooks.

```
$ cd <osmaxx-repo-root>
$ ln -s ../../hooks/pre-commit .git/hooks/pre-commit
```

## Features

* Ubuntu 14.04 http://www.ubuntu.com/download/server
Expand All @@ -57,11 +73,11 @@ A vagrant box is provided as part of this project's repository.
5. Add 'localhost osmaxx.dev' to your /etc/hosts file
6. Use the configured Apache or start development server (live update after file change)
1. Live simulation with Apache
* Open http://osmax.dev:8080/excerptExport/ in your local browser
* Open http://osmaxx.dev:8080/excerptExport/ in your local browser
2. Development
* Log into vagrant machine: `vagrant ssh`
* Run development start script: `/var/www/eda/projects/runDevelopmentServer.sh`
* Open http://osmax.dev:8000/excerptExport/ in your local browser
* Open http://osmaxx.dev:8000/excerptExport/ in your local browser


### Reset the box
Expand Down Expand Up @@ -103,19 +119,18 @@ to your local /etc/hosts file.

### Run application using Django built in server (see runDevelopmentServer.sh)

You need to specify the ip. Otherwise you are not able to reach the application from outside of the vm.
Specify IP `0.0.0.0` to listen on **all** interfaces. Default would be local interfaces only, so you would not be able
to reach the application from outside of the VM.

```shell
#!/bin/bash

CURRENTDIR=`dirname $0`
CURRENTDIR=$(dirname $0)
cd "$CURRENTDIR"
# activate environment
source "../environment/bin/activate"
# get local ip
LOCALIP=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`
echo "$LOCALIP"
python ./manage.py runserver "$LOCALIP:8000"
source ../environment/bin/activate
# start server listening on all interfaces
python ./manage.py runserver 0.0.0.0:8000
```

### Clear Django cache
Expand Down Expand Up @@ -168,3 +183,13 @@ sudo -u postgres pg_dump osmaxx --data-only > /var/www/eda/data/{yymmdd}-osmaxx-
# restore
sudo -u postgres psql osmaxx < /var/www/eda/data/{yymmdd}-osmaxx-data.sql
```


### Deployment

#### Package release

```shell
cd toDirectoryContainingOsmaxxRepo
zip -r osmaxx-0.1.zip osmaxx -x *.git* -x *.od* -x *.gitignore* -x *.gitmodules* -x *developmentEnvironment/* -x *data/* -x *.idea* -x *test_db.sqlite* -x *__pycache__*
```
18 changes: 18 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import sys
import os
from flake8.hooks import git_hook

COMPLEXITY = os.getenv('FLAKE8_COMPLEXITY', 10)
STRICT = os.getenv('FLAKE8_STRICT', True)
IGNORE = os.getenv('FLAKE8_IGNORE')
LAZY = os.getenv('FLAKE8_LAZY', False)


if __name__ == '__main__':
sys.exit(git_hook(
complexity=COMPLEXITY,
strict=STRICT,
ignore=IGNORE,
lazy=LAZY,
))
31 changes: 15 additions & 16 deletions source/excerptexport/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from __future__ import unicode_literals

from django.db import models, migrations
import django.contrib.gis.db.models.fields
from django.conf import settings
import django.contrib.gis.db.models.fields
import excerptexport.models.output_file


class Migration(migrations.Migration):
Expand All @@ -16,7 +17,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='BoundingGeometry',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('type', models.IntegerField(default=0)),
('geometry', django.contrib.gis.db.models.fields.GeometryField(null=True, srid=4326, blank=True)),
],
Expand All @@ -27,10 +28,11 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Excerpt',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('is_public', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('bounding_geometry', models.OneToOneField(to='excerptexport.BoundingGeometry')),
('owner', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='excerpts')),
],
options={
Expand All @@ -40,10 +42,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ExtractionOrder',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('state', models.IntegerField(default=1)),
('process_start_date', models.DateTimeField(verbose_name='process start date')),
('process_reference', models.CharField(max_length=128)),
('process_start_date', models.DateTimeField(null=True, verbose_name='process start date')),
('process_reference', models.CharField(null=True, max_length=128, blank=True)),
('excerpt', models.ForeignKey(to='excerptexport.Excerpt', related_name='extraction_orders')),
('orderer', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='extraction_orders')),
],
Expand All @@ -54,21 +56,18 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='OutputFile',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('mime_type', models.CharField(max_length=64)),
('path', models.CharField(max_length=512)),
('create_date', models.DateTimeField(verbose_name='create date')),
('file', models.FileField(null=True, upload_to='/var/www/eda/projects/data', blank=True)),
('create_date', models.DateTimeField(auto_now_add=True)),
('deleted_on_filesystem', models.BooleanField(default=False)),
('extraction_order', models.ForeignKey(to='excerptexport.ExtractionOrder', related_name='output_files')),
('public_identifier', models.CharField(default=excerptexport.models.output_file.
default_public_identifier, max_length=512)),
('extraction_order', models.ForeignKey(to='excerptexport.ExtractionOrder',
related_name='output_files')),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='boundinggeometry',
name='excerpt',
field=models.OneToOneField(to='excerptexport.Excerpt', null=True),
preserve_default=True,
),
]
Loading

0 comments on commit 132c7b4

Please sign in to comment.