From 44d2ce22abf6706d1f6b85128878fe1b701bc200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 5 Nov 2017 17:26:20 +0100 Subject: [PATCH 1/4] Got the site up running using docker-compose. Also added a Makefile for convenience. --- Dockerfile | 8 ++++++++ Makefile | 19 +++++++++++++++++++ README.md | 16 +++++++++++++--- docker-compose.yml | 19 +++++++++++++++++++ src/bornhack/environment_settings.py.dist | 8 ++++---- 5 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7e2bcadb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /code +WORKDIR /code +ADD src/requirements.txt /code/ +RUN pip install -r requirements.txt +RUN apt-get update +RUN apt-get -y install wkhtmltopdf diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e8f3eef1 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +all: build db_up sleep migrate bootstrap web_up + +build: + docker-compose build + +db_up: + docker-compose up -d db + +migrate: + docker-compose run web /usr/local/bin/python src/manage.py migrate + +bootstrap: + docker-compose run web /usr/local/bin/python src/manage.py bootstrap-devsite + +sleep: + echo "Sleeping to ensure that the db is up."; sleep 3 + +web_up: + docker-compose up web diff --git a/README.md b/README.md index 0e2401db..2c849a3c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,17 @@ Django project to power Bornhack. Features include news, villages, webshop, and ## Quickstart -### Clone the repo +### Using docker-compose + +If you have docker-compose you can use the included make file. Like so: + + $ make + +### Manual way + + + +#### Clone the repo Clone with --recursive to include submodules: git clone --recursive https://github.com/bornhack/bornhack-website @@ -13,14 +23,14 @@ If you already cloned the repository, you can add the submodules like this: git submodule update --init --recursive -### Virtualenv +#### Virtualenv Create a Python 3 virtual environment and activate it: ``` $ virtualenv venv -p python3 $ source venv/bin/activate ``` -### System libraries +#### System libraries Install system dependencies (method depends on OS): - postgresql headers (for psycopg2): - Debian: libpq-dev diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..0ec1bb21 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '2' + +services: + db: + image: postgres + restart: always + environment: + POSTGRES_PASSWORD: bornhack + POSTGRES_USER: bornhack + POSTGRES_DB: bornhack + web: + build: . + command: python3 src/manage.py runserver 0.0.0.0:8000 + volumes: + - .:/code + ports: + - "8000:8000" + depends_on: + - db diff --git a/src/bornhack/environment_settings.py.dist b/src/bornhack/environment_settings.py.dist index 4fced002..b86f7895 100644 --- a/src/bornhack/environment_settings.py.dist +++ b/src/bornhack/environment_settings.py.dist @@ -29,6 +29,10 @@ CHANNEL_LAYERS = { }, } +# start redirecting to the next camp instead of the previous camp after +# this much of the time between the camps has passed +CAMP_REDIRECT_PERCENT=40 + ### changes below here are only needed for production # email settings @@ -47,10 +51,6 @@ TIME_ZONE='{{ django_timezone }}' MEDIA_ROOT='{{ django_media_root }}' PDF_ARCHIVE_PATH='{{ pdf_archive_path }}' -# start redirecting to the next camp instead of the previous camp after -# this much of the time between the camps has passed -CAMP_REDIRECT_PERCENT=40 - # PSP settings EPAY_MERCHANT_NUMBER='{{ epay_merchant_number }}' EPAY_MD5_SECRET='{{ epay_md5_secret }}' From c3ebb6ebd321b4115795649e0fedef2406d45064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 5 Nov 2017 17:41:37 +0100 Subject: [PATCH 2/4] Make sure that the enviroment_setting.py file is there. --- Makefile | 5 ++++- src/bornhack/dev_environment_settings.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/bornhack/dev_environment_settings.py diff --git a/Makefile b/Makefile index e8f3eef1..9ed91da6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -all: build db_up sleep migrate bootstrap web_up +all: copy_environment_settings build db_up sleep migrate bootstrap web_up + +copy_environment_settings: + cp src/bornhack/dev_environment_settings.py src/bornhack/environment_settings.py build: docker-compose build diff --git a/src/bornhack/dev_environment_settings.py b/src/bornhack/dev_environment_settings.py new file mode 100644 index 00000000..4eb4d533 --- /dev/null +++ b/src/bornhack/dev_environment_settings.py @@ -0,0 +1,22 @@ +# This file is intended for easing the creation of a local development setup +SECRET_KEY = "something-very-random" +ALLOWED_HOSTS = "*" +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'bornhack', + 'USER': 'bornhack', + 'PASSWORD': 'bornhack', + 'HOST': 'db', + }, +} +DEBUG=True +WKHTMLTOPDF_CMD="wkhtmltopdf" +CHANNEL_LAYERS = { + "default": { + "BACKEND": "asgiref.inmemory.ChannelLayer", + "ROUTING": "bornhack.routing.channel_routing", + "CONFIG": {} + }, +} +CAMP_REDIRECT_PERCENT=40 From e514df89f2ec08a142d544bab27c53c9e8f350c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 5 Nov 2017 17:46:26 +0100 Subject: [PATCH 3/4] Adding run target to the Makefile. --- Makefile | 4 +++- README.md | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9ed91da6..439b3404 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: copy_environment_settings build db_up sleep migrate bootstrap web_up +all: copy_environment_settings build db_up sleep migrate bootstrap copy_environment_settings: cp src/bornhack/dev_environment_settings.py src/bornhack/environment_settings.py @@ -20,3 +20,5 @@ sleep: web_up: docker-compose up web + +run: db_up web_up diff --git a/README.md b/README.md index 2c849a3c..aed1c041 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ If you have docker-compose you can use the included make file. Like so: $ make +This will create everything. You can now start the project running: + + $ make run + ### Manual way From 3e55c1dc8d6bdc2883a3fd5217ac85b2a1e6db71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 5 Nov 2017 17:48:21 +0100 Subject: [PATCH 4/4] Update readme. --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index aed1c041..7fb505eb 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ This will create everything. You can now start the project running: ### Manual way - - #### Clone the repo Clone with --recursive to include submodules: @@ -49,13 +47,13 @@ Install system dependencies (method depends on OS): - Debian: ? - FreeBSD: x11-fonts/webfonts -### Python packages +#### Python packages Install pip packages: ``` (venv) $ pip install -r src/requirements.txt ``` -### Configuration file +#### Configuration file Copy environment settings file and change settings as needed: ``` (venv) $ cp src/bornhack/environment_settings.py.dist src/bornhack/environment_settings.py @@ -64,7 +62,7 @@ Copy environment settings file and change settings as needed: Edit the configuration file, replacing all the ``{{ placeholder }}`` patterns (intended for Ansible). -### Database +#### Database Is this a new installation? Initialize the database: ``` (venv) $ src/manage.py migrate @@ -75,7 +73,7 @@ Is this for local development? Bootstrap the database with dummy data and users: (venv) $ src/manage.py bootstrap-devsite ``` -### Deploy camps+program test data +#### Deploy camps+program test data Run this command to create a bunch of nice test data: @@ -84,7 +82,7 @@ Run this command to create a bunch of nice test data: ``` -### Done +#### Done Is this for local development? Start the Django devserver: ``` (venv) $ src/manage.py runserver