diff --git a/Dockerfile b/Dockerfile index cca5777d..c4f7b3f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,20 @@ -FROM python:3.4-wheezy +FROM python:3.4 +ENV PYTHONUNBUFFERED 1 +ENV PYTHONPATH /code:$PYTHONPATH +# runtime dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3-dev \ + libxml2-dev \ + libxslt1-dev \ + zlib1g-dev \ + libffi-dev \ + && rm -rf /var/lib/apt/lists/* -VOLUME ["/opt/code"] - -RUN apt-get update && apt-get install -y apt-utils cmake gcc make tk-dev libjpeg-dev zlib1g-dev libtiff5-dev libfreetype6-dev liblcms2-dev libwebp-dev libtk-img-doc libopenjpeg-dev - -ADD ./scripts/install-openjpeg.sh /tmp/ -RUN /tmp/install-openjpeg.sh - -COPY ./scripts/webcli.py /webcli - -CMD [ "/bin/bash" ] -EXPOSE 8000 +RUN mkdir /code +WORKDIR /code +# update pip (to use wheels) +RUN wget -O - https://bootstrap.pypa.io/get-pip.py | python3 +COPY dev_requirements.txt /code +COPY requirements.txt /code +RUN pip install -r dev_requirements.txt +COPY . /code/ diff --git a/docker-compose.yml b/docker-compose.yml index 73d98d6e..92111b29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,35 +2,31 @@ version: '2' volumes: pgdata: - redisdata: services: - web: - build: . - command: python3 manage.py runserver 0.0.0.0:8000 - volumes: - - .:/code - ports: - - "8000:8000" - env_file: .env - links: - - postgres - - redis - postgres: restart: always - image: postgres:latest + image: postgres:9.4.4 ports: - - "5432:5433" + - "5432:5432" volumes: - pgdata:/var/lib/postgresql/data/ + environment: + - POSTGRES_PASSWORD=secret - redis: - restart: always - image: redis:latest - ports: - - "6379:6379" + web: + build: . + command: python3 manage.py runserver 0.0.0.0:8000 volumes: - - redisdata:/data - - + - .:/code + ports: + - "8000:8000" + links: + - postgres + depends_on: + - postgres + environment: + - DB_USER=postgres + - DB_NAME=postgres + - DB_PASS=secret + - DB_SERVICE=postgres diff --git a/initialize.sh b/initialize.sh index ff7776b2..6ffece75 100755 --- a/initialize.sh +++ b/initialize.sh @@ -1,3 +1,3 @@ #!/bin/bash python3 manage.py migrate -python3 manage.py loaddata fixtures/initial_data.json +python3 manage.py createsuperuser diff --git a/pyarweb/settings.py b/pyarweb/settings.py index 7abd830a..7867aeb7 100644 --- a/pyarweb/settings.py +++ b/pyarweb/settings.py @@ -26,7 +26,7 @@ # Sites framework SITE_ID = 1 -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Django registration # https://django-registration.readthedocs.org/en/latest/quickstart.html diff --git a/scripts/install-openjpeg.sh b/scripts/install-openjpeg.sh deleted file mode 100755 index 466facf3..00000000 --- a/scripts/install-openjpeg.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# install openjpeg - -if [ "$(id -u)" != "0" ]; then - echo "This script must be run as root" 1>&2 - exit 1 -fi - -command -v wget >/dev/null 2>&1 || { echo >&2 "I require wget but it's not installed. Aborting."; exit 1; } - -CURDIR=`pwd` - -cd /tmp - -if [ ! -f openjpeg-2.1.0.tar.gz ]; then - wget 'http://iweb.dl.sourceforge.net/project/openjpeg.mirror/2.1.0/openjpeg-2.1.0.tar.gz' - -fi - -if [ ! -d openjpeg-2.1.0 ]; then - rm -r openjpeg-2.1.0 -fi - -tar -xvzf openjpeg-2.1.0.tar.gz - -pushd openjpeg-2.1.0 - -cmake -DCMAKE_INSTALL_PREFIX=/usr . && make -j4 && make install - -popd - -cd $CURDIR diff --git a/scripts/webcli.py b/scripts/webcli.py deleted file mode 100755 index 03f29333..00000000 --- a/scripts/webcli.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 - -import os -import argparse - - -CONTAINER_NAME = 'pyar' - - -parser = argparse.ArgumentParser( - prog='webcmd', - description='Helper to start a Pyarweb development instance.') - -parser.add_argument( - '--build-image', - action='store_true', - help='Build PyAr web docker image') - -parser.add_argument( - '--run-container', - action='store_true', - help='Build PyAr web docker image') - -parser.add_argument( - '--del-container', - action='store_true', - help='Removes PyAr web container') - -parser.add_argument( - '--shell', - action='store_true', - help='Exec a bash interpreter on a running container') - - -def build(): - """Run docker build, then docker run.""" - curdir = os.path.abspath(os.path.curdir) - dockerfile = os.path.join(curdir, 'Dockerfile') - assert os.path.isfile(dockerfile), "{} file not found.".format(dockerfile) - - cmd = "docker build -t pyarweb/django ." - os.system(cmd) - - -def run(): - """Run docker run to create a container from pyarweb/django image.""" - curdir = os.path.abspath(os.path.curdir) - dockerfile = os.path.join(curdir, 'Dockerfile') - assert os.path.isfile(dockerfile), "{} file not found.".format(dockerfile) - - cmd = "docker run -it -v {}:/opt/code -p 8000:8000 --name {} pyarweb/django".format( - curdir, CONTAINER_NAME) - os.system(cmd) - - -def delete_container(): - """Removes PyAr .""" - cmd = "docker rm {}".format(CONTAINER_NAME) - os.system(cmd) - - -def shell(): - """Get a bash shell in docker container.""" - cmd = "docker exec -it {} /bin/bash".format(CONTAINER_NAME) - os.system(cmd) - - -args = parser.parse_args() -if args.build_image: - build() -elif args.run_container: - run() -elif args.shell: - shell() -elif args.del_container: - delete_container()