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.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wasabideveloper committed Sep 14, 2015
2 parents 5085f59 + 9bc114c commit 0c07b56
Show file tree
Hide file tree
Showing 40 changed files with 1,196 additions and 326 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ docker-compose.yml
osmaxx-py/src/
# ignore environment file for local production environment
.env
*.log
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM geometalab/python3-gis

ENV USER osmaxx
# ENV USERID 1000
# ENV GROUPID 1000
# RUN groupadd -g $GROUPID $USER && useradd -g $USERID --create-home --home-dir /home/$USER -g $USER $USER

ENV COMPOSE_VERSION 1.3.3

RUN DEBIAN_FRONTEND=noninteractive apt-get update -q \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends curl ca-certificates \
&& curl -o /usr/local/bin/docker-compose -L \
"https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-Linux-x86_64" \
&& chmod +x /usr/local/bin/docker-compose

ENV HOME /home/$USER

Expand Down
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,30 @@ Then initiate the project defaults by running the following command:

```shell
# For development:
docker-compose run osmaxxwebappdev /bin/bash -c 'python3 manage.py migrate && python3 manage.py createsuperuser'
docker-compose up -d databasedev;
docker-compose run webappdev /bin/bash -c './manage.py migrate && ./manage.py createsuperuser'

# For production:
docker-compose run osmaxxwebapp /bin/bash -c 'python3 manage.py migrate && python3 manage.py createsuperuser'
docker-compose up -d databaseprod;
docker-compose run webapp /bin/bash -c './manage.py migrate && ./manage.py createsuperuser'
```

Alternative to this command, bootstrap the container and execute the commands inside the container by hand:

```shell
# For development:
docker-compose run osmaxxwebappdev /bin/bash
docker-compose up -d databasedev
docker-compose run webappdev /bin/bash

# For production:
docker-compose run osmaxxwebapp /bin/bash
docker-compose up -d database
docker-compose run webapp /bin/bash
```

Inside the container:

1. Execute migrations: `$ python3 manage.py migrate`
2. (optional, recommended) setup a superuser: `$ python3 manage.py createsuperuser`
1. Execute migrations: `$ ./manage.py migrate`
2. (optional, recommended) setup a superuser: `$ ./manage.py createsuperuser`


### Running the project
Expand Down Expand Up @@ -99,3 +103,17 @@ LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
```

You forgot to **run the migrations**


#### Tests failed, but worked before with no apparent change

Do not run `docker-compose build --no-cache`. Use `docker-compose rm -f && docker-compose build`, or
if you really want to start clean, remove all docker containers

`docker rm -f $(docker ps -q)`

and remove all images

`docker rmi -f $(docker images -q)`

*WARNING*: This removes all containers/images on the machine.
11 changes: 6 additions & 5 deletions compose-common.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
osmaxxdatabasebase:
databasebase:
image: geometalab/postgis:9.4

osmaxxbase:
base:
build: .
environment:
# shared data
- DJANGO_STATIC_ROOT=/data/static
- DJANGO_MEDIA_ROOT=/data/media
- DJANGO_PRIVATE_MEDIA_ROOT=/data/private_media
- DJANGO_RESULT_MEDIA_ROOT=/results
# --link some-rabbit:rabbit "just works"
- DJANGO_CELERY_BROKER_URL=amqp://guest@osmaxxrabbit
- DJANGO_DATABASE_URL=postgis://postgres@osmaxxdatabase/postgres
- DJANGO_CELERY_BROKER_URL=amqp://guest@rabbit
- DJANGO_DATABASE_URL=postgis://postgres@database/postgres
- DJANGO_EMAIL_HOST=localhost
# Settings above likely need to be changed, depending on the environment
##########################################################################
Expand Down Expand Up @@ -41,5 +42,5 @@ osmaxxbase:
- DJANGO_CSRF_COOKIE_HTTPONLY=true
- DJANGO_X_FRAME_OPTIONS='DENY'

osmaxxrabbitmqbase:
rabbitmqbase:
image: rabbitmq:3
64 changes: 39 additions & 25 deletions compose-development.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,82 @@
osmaxxshareddatadev:
shareddatadev:
image: buildpack-deps:jessie
command: /bin/true
volumes:
# as noted in https://docs.docker.com/userguide/dockervolumes/#mount-a-host-file-as-a-data-volume
# the parent directory should be mounted, not the directories itself
# otherwise we get OSError: Device or resource busy
- /data
# database
- /database/data
# temporary results directory used as pipe between multiple docker forests
- /tmp/osmaxx-results:/results
net: "none"

osmaxxsourcedev:
sourcedev:
build: docker/volume-mount
volumes:
- osmaxx-py:/home/osmaxx/source
- ./osmaxx-py:/home/osmaxx/source
- ~/.cache/pip:/home/osmaxx/.cache/pip

osmaxxwebappdev:
webappdev:
extends:
file: compose-common.yml
service: osmaxxbase
service: base
command: honcho start -f Procfile.django.dev
ports:
- "8000:8000"
expose:
- "8000"
volumes_from:
- osmaxxsourcedev
- osmaxxshareddatadev
- sourcedev
- shareddatadev
links:
- osmaxxrabbitmqdev:rabbit
- osmaxxdatabasedev
- osmaxxemaildev
- osmaxxcelerydev
- rabbitmqdev:rabbit
- databasedev
- emaildev
- celerydev
environment:
- DJANGO_CELERY_BROKER_URL=amqp://guest@rabbit
- DJANGO_DATABASE_URL=postgis://postgres@osmaxxdatabasedev/postgres
- DJANGO_DATABASE_URL=postgis://postgres@databasedev/postgres
- DJANGO_DEBUG=true
- DJANGO_EMAIL_HOST=emaildev

osmaxxrabbitmqdev:

rabbitmqdev:
extends:
file: compose-common.yml
service: osmaxxrabbitmqbase
service: rabbitmqbase

osmaxxcelerydev:
celerydev:
extends:
file: compose-common.yml
service: osmaxxbase
service: base
command: honcho start -f Procfile.celery
volumes:
- /var/run/docker.sock:/var/run/docker.sock
volumes_from:
- osmaxxsourcedev
- osmaxxshareddatadev
- sourcedev
- shareddatadev
links:
- osmaxxrabbitmqdev:rabbit
- osmaxxdatabasedev
- osmaxxemaildev
- rabbitmqdev:rabbit
- databasedev
- emaildev
environment:
- DJANGO_CELERY_BROKER_URL=amqp://guest@rabbit
- DJANGO_DATABASE_URL=postgis://postgres@osmaxxdatabasedev/postgres
- DJANGO_DATABASE_URL=postgis://postgres@databasedev/postgres
- DJANGO_DEBUG=true
- DJANGO_EMAIL_HOST=emaildev

osmaxxdatabasedev:
databasedev:
extends:
file: compose-common.yml
service: osmaxxdatabasebase
service: databasebase
volumes_from:
- shareddatadev
environment:
- PGDATA=/database/data

osmaxxemaildev:
emaildev:
image: python:3
ports:
- 1025:1025
Expand Down
55 changes: 31 additions & 24 deletions compose-production.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
osmaxxshareddata:
shareddata:
image: buildpack-deps:jessie
command: /bin/true
volumes:
- /data
- /database/data
- /tmp/osmaxx-results:/results
net: "none"

# TODO: this file is only a placeholder for now!
osmaxxwebapp:
webapp:
extends:
file: compose-common.yml
service: osmaxxbase
service: base
ports:
- "8000:8000"
volumes_from:
- osmaxxshareddata
- shareddata
command: honcho start -f Procfile.django
links:
- osmaxxrabbitmq:rabbit
- osmaxxdatabase
- osmaxxemail
- osmaxxcelery
- rabbitmq:rabbit
- database
- email
- celery
environment:
- APP_PORT=8000
- APP_HOST=0.0.0.0
- DJANGO_CELERY_BROKER_URL=amqp://guest@rabbit
- DJANGO_DATABASE_URL=postgis://postgres@osmaxxdatabase/postgres
- DJANGO_DATABASE_URL=postgis://postgres@database/postgres
- DJANGO_EMAIL_USE_TLS=false
- DJANGO_EMAIL_HOST=osmaxxemail
- DJANGO_EMAIL_HOST=email
- DJANGO_EMAIL_HOST_PASSWORD=osmaxx
- DJANGO_EMAIL_HOST_USERNAME=osmaxx
- DJANGO_EMAIL_PORT=25

osmaxxrabbitmq:
rabbitmq:
extends:
file: compose-common.yml
service: osmaxxrabbitmqbase
service: rabbitmqbase

osmaxxcelery:
celery:
extends:
file: compose-common.yml
service: osmaxxbase
service: base
volumes_from:
- osmaxxshareddata
- shareddata
command: honcho start -f Procfile.celery
links:
- osmaxxrabbitmq:rabbit
- osmaxxdatabase
- osmaxxemail
- rabbitmq:rabbit
- database
- email
environment:
- DJANGO_CELERY_BROKER_URL=amqp://guest@rabbit
- DJANGO_DATABASE_URL=postgis://postgres@osmaxxdatabase/postgres
- DJANGO_DATABASE_URL=postgis://postgres@database/postgres
- DJANGO_EMAIL_HOST=email

osmaxxdatabase:
database:
extends:
file: compose-common.yml
service: osmaxxdatabasebase
service: databasebase
volumes_from:
- shareddata
environment:
- PGDATA=/database/data

osmaxxemail:
email:
image: catatnight/postfix
environment:
- maildomain=osmaxx.hsr.ch
- maildomain=.hsr.ch
- smtp_user=osmaxx:osmaxx
expose:
- 25
73 changes: 66 additions & 7 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,70 @@

To deploy to production server:

1. Clone the repository, Details see [Project repository](git-repository.md).
1. Clone the repository master branch without history:

```shell
git clone --depth 1 -b master https://github.com/geometalab/osmaxx.git osmaxx && cd osmaxx
git submodule init && git submodule update
```
Repository details see [Project repository](git-repository.md).
2. Link production configuration for docker-compose, Details see [Docker container bootstrapping](../README.md#initializationdocker-container-bootstrapping).
3. Build the containers
4. Run migrations and add create super user, Details see [Docker container bootstrapping](../README.md#initializationdocker-container-bootstrapping).
5. Load data container content from old container if there is one, Details see [Useful Docker commands](project-development-environment.md#useful-docker-commands).
6. Load database container content from old container if there is one, Details see [Useful Docker commands](project-development-environment.md#useful-docker-commands).
7. Add a system startup script running `docker-compose up`
8. Start the containers
3. Add target specific environment variables to compose-production.yml
* If you are using an nginx proxy (jwilder/nginx-proxy), you need to set the environment variable
`VIRTUAL_HOST=osmaxx.yourdomain.tld`
4. Build the containers. Use docker-compose container instead of native installation:

a. Create the docker-compose container:
```shell
docker create \
--name osmaxx-starter
-v "/path/to/source/repo:/app" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-e "COMPOSE_PROJECT_NAME=osmaxx" \
"dduportal/docker-compose:1.2.0"
```

b. Build osmaxx containers:

```shell
docker start osmaxx-starter build --no-cache
```

5. Run migrations and add create super user, Details see [Docker container bootstrapping](../README.md#initializationdocker-container-bootstrapping).
For docker-compose container run:

```shell
docker exec -ti osmaxx-starter /usr/local/bin/docker-compose \
run webapp /bin/bash -c "python3 manage.py migrate && python3 manage.py createsuperuser"
```
6. Load data container content from old container if there is one, Details see [Useful Docker commands](project-development-environment.md#useful-docker-commands).
7. Load database container content from old container if there is one, Details see [Useful Docker commands](project-development-environment.md#useful-docker-commands).
8. Add a system startup script running `docker-compose up`
E.g. /etc/systemd/system/osmaxx.service:

```shell

[Unit]
Description=Start osmaxx application

[Service]
ExecStart=/usr/bin/docker start -a osmaxx-starter
ExecStop=/usr/bin/docker exec osmaxx-starter /usr/local/bin/docker-compose stop --timeout 60
ExecStop=/usr/bin/docker kill --signal=INT osmaxx-starter
ExecStop=/usr/bin/docker stop -t 10 osmaxx-starter
Restart=always

[Install]
WantedBy=multi-user.target
```
**important**: osmax-starter container needs to be created before!

9. Enable startup service
```shell
sudo systemctl enable docker-osmaxx.service
```

10. Start the containers
```shell
sudo systemctl start docker-osmaxx.service
```
4 changes: 1 addition & 3 deletions docs/git-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ For developers have write access to this repository:
Implementation of feature #123 (Merge will close #123 ).

* locales **NOT** compiled -> do this on release (prevent huge locale diffs in changes)
* ran flake8
* ran check
* ran test
* ran tests
* tested views by hand:
* /orders/new [get/post]
* /orders/{id}
Expand Down
Loading

0 comments on commit 0c07b56

Please sign in to comment.