Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #237 from quokkaproject/dockerized
Browse files Browse the repository at this point in the history
Dockerized
  • Loading branch information
rochacbruno committed Jul 13, 2015
2 parents 9367b82 + d3fc119 commit d298727
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 96 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ media/*
*.swp

quokka/mediafiles
etc/elasticdata/elasticsearch
etc/mongodata/journal
etc/mongodata/_tmp
etc/mongodata/*.0
etc/mongodata/*.ns
etc/mongodata/*.lock
etc/mongodata/*.bson
etc/logs/*.log
33 changes: 9 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
FROM ubuntu:14.04

FROM alpine
MAINTAINER Bruno Rocha <rochacbruno@gmail.com>

ADD . /quokka
WORKDIR /quokka

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get -y install nginx sed python-pip python-dev uwsgi-plugin-python supervisor libjpeg-dev

RUN mkdir -p /var/log/nginx/app
RUN mkdir -p /var/log/uwsgi/app/

RUN rm /etc/nginx/sites-enabled/default
COPY quokka_nginx.conf /etc/nginx/sites-available/quokka.conf
RUN ln -s /etc/nginx/sites-available/quokka.conf /etc/nginx/sites-enabled/quokka.conf

RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN pip install -r requirements.txt

CMD ["/usr/bin/supervisord"]
WORKDIR /tmp
COPY requirements.txt /tmp/
RUN apk update
RUN apk add gcc python py-pip libjpeg zlib zlib-dev tiff freetype git py-pillow python-dev musl-dev bash
RUN pip install -r /tmp/requirements.txt
RUN pip install ipython

# docker run --link <mongo_container_id>:mongo -v $PWD:/quokka -t -i quokka/quokkadev /bin/bash
164 changes: 125 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,77 +25,163 @@ Quokka is a flexible content management platform powered by Python, Flask and Mo
</p>


Quick start
============
> Quokka runs on Python 2.7
> Quokka runs on Python 2.7 (Python 3 support is being developed)

1. Get Quokka
```bash
$ git clone https://github.com/quokkaproject/quokka
$ cd quokka
$ pip install -r requirements.txt
## Get Quokka and enter in to its root directory
```bash
git clone https://github.com/quokkaproject/quokka
cd quokka
```

2. Quokka require a MongoDB instance running to connect.
## Run Quokka (for development)

You have 2 options **RUN NORMAL** or **RUN IN DOCKER**

### RUN NORMAL

Install needed packages in your local computer

You can install everything you need in your local computer or if preferred use a virtualenv for Python

#### Mongo

* Quokka requires a MongoDB instance running to connect.

1. If you don't have a MongoDB instance running, you can quickly configure it:

* Download from [here](https://www.mongodb.org/downloads)
* Unzip the file
* Open a separate console
* Run it inside the MongoDB directory:
```bash
./bin/mongod --dbpath /tmp/
```

```bash
./bin/mongod --dbpath /tmp/
```
> WARNING: If you want to persist the data, give another path in place of ```--dbpath /tmp```

2. If you already have, just define your MongoDB settings:
```bash
$ $EDITOR quokka/local_settings.py
===============quokka/quokka/local_settings.py===============
MONGODB_SETTINGS = {'DB': 'your_mongo_db'}
MONGODB_DB = "yourdbname"
MONGODB_HOST = 'your_host'
MONGODB_PORT = 27017
MONGODB_USERNAME = None
MONGODB_PASSWORD = None
DEBUG = True
DEBUG_TOOLBAR_ENABLED = True
=============================================================
```

3. (optional) If you have Docker installed you can simply run the official Mongo image
```bash
$ cd quokka
$ docker run -d -v $PWD/mongodata:/data/db -p 27017:27017 mongo
cd quokka
docker run -d -v $PWD/etc/mongodata:/data/db -p 27017:27017 mongo
```

3. Populate with sample data (optional)
#### Requirements

* O.S Requirements (for media conversions) you may need the following requirements on your operating system

1. Ubuntu/Debian
```bash
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev
```
2. Alpine Linux
```bash
apk add gcc python py-pip libjpeg zlib zlib-dev tiff freetype git py-pillow python-dev musl-dev
```
3. Python requirements
```bash
pip install -r requirements.txt
```

#### Bootstrap commands

```bash
$ python manage.py populate
* Initial data, users and running commands

3. Populate with sample data (optional)
```bash
$ python manage.py populate

```

```
4. Create a superuser
```bash
$ python manage.py createsuperuser
you@email.com
P4$$W0Rd
```

5. Run
```bash
$ python manage.py runserver --host 0.0.0.0 --port 5000
```
- Site on [http://localhost:5000](http://localhost:5000)
- Admin on [http://localhost:5000/admin](http://localhost:5000/admin)

4. Create a superuser

```bash
$ python manage.py createsuperuser
you@email.com
P4$$W0Rd
```
### RUN IN DOCKER

5. Run
- Run pre built docker images with everything pre-installed
- You will need docker and docker compose installed in your machine
- Once in Docker all data is stored behind quokka/etc folder

```bash
$ python manage.py runserver
```
6. Access on http://localhost:5000
7. Admin on http://localhost:5000/admin

or by making your server reachable on other networks
#### Install Docker and docker-compose

```bash
$ python manage.py run0
```
6. Access on http://0.0.0.0:8000
7. Admin on http://0.0.0.0:8000/admin
- **Docker** - https://docs.docker.com/installation/
- **Docker-Compose** - https://docs.docker.com/compose/install/


> Ensure that local port 27017(mongo) is not being used on your computer
* ### Run with docker-compose

1. Easiest way is just running the following command in quokka root folder
```bash
docker-compose up
```

> use -d on above to leave it as a daemon
2. Enter Quokka Shell (in a separate console)
```bash
docker-compose run shell python manage.py shell
```

3. Run Quokka Commands (in a separate console)
```bash
docker-compose run shell python manage.py populate
```

* ### Run standalone containers
> (each in separate shells or use -d option)
1. run mongo container
```bash
docker run -v $PWD/etc/mongodata:/data/db -p 27017:27017 --name mongo mongo
```

2. run quokka web app container
```bash
docker run -e "QUOKKA_MONGODB_HOST=mongo" -p 5000:5000 --link mongo:mongo -v $PWD:/quokka --workdir /quokka -t -i quokka/quokkadev python manage.py runserver --host 0.0.0.0

```

3. run quokka shell if needed
```bash
docker run -e "QUOKKA_MONGODB_HOST=mongo" -p 5000:5000 --link mongo:mongo -v $PWD:/quokka --workdir /quokka -t -i quokka/quokkadev python manage.py shell

```


## Deployment

Check ``wsgi.py``, ``wsgi_gunicorn.py`` and scripts under /etc folder for deployment options or check documentation

## DOCS
Documentation is not complete yet, but is being written at:

http://quokkaproject.org/documentation
Expand Down
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
mongo:
image: mongo
ports:
- "27017:27017"
volumes:
- etc/mongodata:/data/db

# elastic:
# image: catholabs/elastic-with-marvel
# command: elasticsearch
# volumes:
# - etc/elasticdata:/usr/share/elasticsearch/data
# ports:
# - "9200:9200"
# mem_limit: 1000000000

web:
restart: always
image: quokka/quokkadev
working_dir: /quokka
ports:
- "5000:5000"
volumes:
- .:/quokka
links:
- mongo:mongo
# - elastic:elastic
command: sh etc/docker_wait_to_start.sh
environment:
- QUOKKA_MONGODB_HOST=mongo
- WAIT_COMMAND=$(nc -zv mongo 27017)
- WAIT_START_CMD=python manage.py runserver --host 0.0.0.0 --reload --debug
- WAIT_SLEEP=2
- WAIT_LOOPS=10
mem_limit: 1000000000

shell:
image: quokka/quokkadev
working_dir: /quokka
volumes:
- .:/quokka
links:
- mongo:mongo
# - elastic:elastic
- web:web
mem_limit: 1000000000
command: /bin/bash
stdin_open: true
tty: true
privileged: true
environment:
- RECSYS_ENV=docker
- C_FORCE_ROOT=1
- QUOKKA_MONGODB_HOST=mongo
29 changes: 29 additions & 0 deletions etc/docker_wait_to_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash


#WAIT_COMMAND='[ $(curl --write-out %{http_code} --silent --output /dev/null http://elastic:9200/_cat/health?h=st) = 200 ]'
#WAIT_LOOPS=3
#WAIT_START_CMD="python -V"
#WAIT_SLEEP=2

echo $WAIT_COMMAND
echo $WAIT_START_CMD

is_ready() {
eval "$WAIT_COMMAND"
}

# wait until is ready
i=0
while ! is_ready; do
i=`expr $i + 1`
if [ $i -ge $WAIT_LOOPS ]; then
echo "$(date) - still not ready, giving up"
exit 1
fi
echo "$(date) - waiting to be ready"
sleep $WAIT_SLEEP
done

#start the script
exec $WAIT_START_CMD
File renamed without changes.
File renamed without changes.
Empty file added etc/mongodata/README.md
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fi
cd /home/quokka
virtualenv quokka-env
cd quokka-env
git clone https://github.com/pythonhub/quokka
git clone https://github.com/quokkaproject/quokka
cd quokka

/home/quokka/quokka-env/bin/pip install -r requirements.txt
Expand Down Expand Up @@ -86,7 +86,7 @@ echo 'server {
}
location / {
uwsgi_pass unix:/home/quokka/quokka-env/quokka/logs/quokka.socket;
uwsgi_pass unix:/home/quokka/quokka-env/quokka/etc/quokka.socket;
include /etc/nginx/uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
Expand All @@ -104,9 +104,9 @@ chmod-socket = 666
virtualenv = /home/quokka/quokka-env
mount = /=wsgi:application
chdir = /home/quokka/quokka-env/quokka
socket = /home/quokka/quokka-env/quokka/logs/%n.socket
stats = /home/quokka/quokka-env/quokka/logs/%n.stats.socket
logto = /home/quokka/quokka-env/quokka/logs/%n.log
socket = /home/quokka/quokka-env/quokka/etc/logs/%n.socket
stats = /home/quokka/quokka-env/quokka/etc/logs/%n.stats.socket
logto = /home/quokka/quokka-env/quokka/etc/logs/%n.log
workers = 4
uid = quokka
gid = quokka
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ adduser --disabled-login --gecos 'Quokka' quokka
cd /home/quokka
virtualenv quokka-env
cd quokka-env
git clone https://github.com/pythonhub/quokka
git clone https://github.com/quokkaproject/quokka

cd quokka
/home/quokka/quokka-env/bin/pip install -r requirements.txt
Expand Down Expand Up @@ -82,7 +82,7 @@ echo 'server {
}
location / {
uwsgi_pass unix:/home/quokka/quokka-env/quokka/logs/quokka.socket;
uwsgi_pass unix:/home/quokka/quokka-env/quokka/etc/quokka.socket;
include /etc/nginx/uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
Expand All @@ -104,9 +104,9 @@ chmod-socket = 666
virtualenv = /home/quokka/quokka-env
mount = /=wsgi:application
chdir = /home/quokka/quokka-env/quokka
socket = /home/quokka/quokka-env/quokka/logs/%n.socket
stats = /home/quokka/quokka-env/quokka/logs/%n.stats.socket
logto = /home/quokka/quokka-env/quokka/logs/%n.log
socket = /home/quokka/quokka-env/quokka/etc/logs/%n.socket
stats = /home/quokka/quokka-env/quokka/etc/logs/%n.stats.socket
logto = /home/quokka/quokka-env/quokka/etc/logs/%n.log
workers = 4
uid = quokka
gid = quokka
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d298727

Please sign in to comment.