From 573891cea0030a75fd5a25b2fd82d6210ccf0b9e Mon Sep 17 00:00:00 2001 From: Philip Belesky Date: Fri, 3 Feb 2017 19:55:20 +1100 Subject: [PATCH] Initial WIP --- .gitignore | 3 +++ Dockerfile | 35 +++++++++++++++++++++++++++++++++ docker-compose.yml | 27 +++++++++++++++++++++++++ tabbycat/local_settings.example | 6 +++--- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index a159e1d2b5c..af96acf1632 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ data/* !data/presets/ !data/fixtures/ +# Docker +dbdata + # Docs docs/site/ issues-*.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..12814fe99aa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Docker file lists all the commands needed to setup a fresh linux instance to +# run the application specified. docker-compose does not use this. + +# Grab a python image +FROM python:3.6 + +# Just needed for all things python +ENV PYTHONUNBUFFERED 1 + +# Setup Node/NPM +RUN apt-get update && apt-get install curl +RUN curl -sL https://deb.nodesource.com/setup_6.x | bash +RUN apt-get install -y nodejs + +# Copy all our files into the baseimage and cd to that directory +RUN mkdir /tcd +WORKDIR /tcd +ADD . /tcd/ # Can this be skipped? Takes ages +COPY ./tabbycat/local_settings.example /tcd/tabbycat/local_settings.py + +# Install our python requirements +RUN pip install -r ./requirements_common.txt + +# Install our node requirements +RUN npm install + +# This needs to happen else sass gets angry +RUN npm rebuild node-sass + +# Migrate our database +# RUN python ./tabbycat/manage.py migrate --noinput + +# Run server +EXPOSE 8000 +# RUN python ./tabbycat/manage.py runserver \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..a99eacd4c6b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +# Docker-compose is a way to run multiple containers at once and connect them +# This sets up and runs postgres, the django dev server + +# Initial setup with +# $ docker-compose up +# Can run management commands with +# $ docker-compose run web /code/manage.py whatever + +version: '2' +services: + db: + image: postgres + environment: + POSTGRES_PASSWORD: password + volumes: + - ./dbdata:/var/lib/postgresql/data + web: + # Hack to wait until Postgres is up before running things + command: bash -c "while ! nc -w 1 -z db 5432; do sleep 0.1; done; ./tabbycat/manage.py migrate; while :; do ./tabbycat/manage.py runserver_plus 0.0.0.0:8000; sleep 1; done" + image: django + build: . + volumes: + - .:/code + depends_on: + - db + environment: + IN_DOCKER: 1 diff --git a/tabbycat/local_settings.example b/tabbycat/local_settings.example index d4f3c3ce929..020074aeef0 100644 --- a/tabbycat/local_settings.example +++ b/tabbycat/local_settings.example @@ -9,10 +9,10 @@ SECRET_KEY = '#2q43u&tp4((4&m3i8v%w-6z6pp7m(v0-6@w@i!j5n)n15epwc' DATABASES = { 'default': { 'ENGINE' : 'django.db.backends.postgresql_psycopg2', - 'NAME' : '', - 'USER' : '', + 'NAME' : 'postgres', + 'USER' : 'postgres', 'PASSWORD': '', - 'HOST': 'localhost', + 'HOST': 'db', 'PORT': '5432', 'CONN_MAX_AGE': 600, }