Browse Source

Bits for a dockerized local setup

Allow folks to more easily run the application locally by deferring
all infra to docker.
pull/549/head
parent
commit
0e6a24f8bd
Signed by: hristoast GPG Key ID: 5FC7664AD47AA1C5
5 changed files with 116 additions and 5 deletions
  1. +39
    -2
      CONTRIBUTING.md
  2. +35
    -0
      Dockerfile
  3. +6
    -1
      Makefile
  4. +28
    -0
      docker-compose.yml
  5. +8
    -2
      momw/momw/settings.py

+ 39
- 2
CONTRIBUTING.md View File

@ -15,9 +15,46 @@ on your machine:
* Python3 (the latest 3.X release is desireable)
* python3-pip
## Installation
## About The Application
The below steps should work for any unix-based system (Linux, macOS). For windows, I need a volunteer to come up with those steps.
Before diving into the setup, a quick note about how the application is designed:
Although it uses a database, the site is actually 100% static. There's no runtime way to alter the database content, and every page is cached in production.
This means that when you make a change to the data, you simply wipe the database out and redo the "reset" process (see below) to regenerate your data.
PostgreSQL specifically is required due to the usage of [JSON data types](https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#jsonfield).
## Docker Setup
Docker can be used to simplify the setup of the infrastructure required to run the application locally.
1. [Install docker](https://www.docker.com/products/docker-desktop)
1. [Install docker-compose](https://docs.docker.com/compose/install/)
1. Clone the source code locally:
cd src
git clone http://git.modding-openmw.com/Modding-OpenMW.com/momw.git
1. `cd` into the source directory:
cd momw
1. Start the application:
sudo make compose-up
Once you see `Starting development server at http://0.0.0.0:8000/` in the terminal output, you can open up that URL in your browser to see the local copy of the application running. It will say "docker" in the site title.
There's a hardcoded ten second wait in the service command; this is to ensure that the database container is ready before the application tries to run. If the wait isn't long enough, simply edit that line.
If any data changes are made, that volume will need to be deleted (note the `psql` container needs to be deleted first):
docker rm momw_psql_1
docker volume rm momw_psql-data
Then simply re-run `sudo make compose-up`.
## Manual Setup
These steps should work for any unix-based system (Linux, macOS).
To get the source, clone the git repository via:


+ 35
- 0
Dockerfile View File

@ -0,0 +1,35 @@
FROM debian:10.4-slim
# Taken from the docker compose django docs...
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
&& apt-get install -y --force-yes \
git python3 python3-dev python3-pip python3-yaml postgresql-client-11
RUN mkdir app
WORKDIR /app
# Copy the requirements file first and do those installs before copying over the application code.
# This prevents the pip install step from running when it doesn't need to...
COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt
# Now copy everything...
COPY . .
EXPOSE 8000/tcp
RUN export user=momw home=/home/momw uid=1000 gid=1000 && \
mkdir -p ${home} && \
echo "${user}:x:${uid}:${gid}:${user},,,:${home}:/bin/bash" >> /etc/passwd && \
echo "${user}:x:${uid}:" >> /etc/group && \
chown ${uid}:${gid} -R ${home} /app
RUN echo "psql:5432:momwdb:momwdb:postgresqlpassword" > /home/momw/.pgpass && chmod 0600 /home/momw/.pgpass
USER momw
CMD [ "make", "PORT=8000" ]

+ 6
- 1
Makefile View File

@ -2,6 +2,8 @@ proj_dir := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
.DEFAULT_GOAL := server
PORT ?= 8666
host_check:
ifndef HOSTS
@echo "\n\033[31mPLEASE PROVIDE THE '\033[91mHOSTS\033[31m' VARIABLE!\nUSAGE: \033[91mmake TARGET HOSTS=some_hosts_or_host_group\033[0m\n"
@ -19,6 +21,9 @@ get-versions:
clean:
/bin/rm -fr *.sqlite3 src && for d in $$(find . -name __pycache__); do rm -rf $${d}; done
compose-up:
docker-compose up --build
migrate:
$(proj_dir)/momw/manage.py migrate
@ -40,7 +45,7 @@ seeddb:
reset: clean refreshdb migrate seeddb
server:
$(proj_dir)/momw/manage.py runserver 0.0.0.0:8666
$(proj_dir)/momw/manage.py runserver 0.0.0.0:$(PORT)
pip-requirements:
pip3 install --user -r requirements.txt


+ 28
- 0
docker-compose.yml View File

@ -0,0 +1,28 @@
version: "3.8"
services:
psql:
image: postgres:11.7
environment:
POSTGRES_DB: momwdb
POSTGRES_PASSWORD: postgresqlpassword
POSTGRES_USER: momwdb
volumes:
- psql-data:/var/lib/postgresql/data
django:
command: bash -c "sleep 5s; make migrate; make seeddb; make PORT=8000"
build: .
depends_on:
- psql
environment:
MOMW_DB_HOST: psql
MOMW_VER: docker
ports:
- target: 8000
published: 8000
protocol: tcp
mode: host
volumes:
psql-data:

+ 8
- 2
momw/momw/settings.py View File

@ -1,7 +1,13 @@
#
import os
MOMW_VER = "wtf"
try:
MOMW_DB = os.environ["MOMW_DB_HOST"]
MOMW_VER = os.environ["MOMW_VER"]
except KeyError:
MOMW_DB = "127.0.0.1"
MOMW_VER = "wtf"
PROJECT_HOSTNAME = "0.0.0.0"
PROJECT_NAME = "momw"
SITE_ID = 1
@ -37,7 +43,7 @@ DATABASES = {
"NAME": "momwdb",
"USER": "momwdb",
"PASSWORD": "postgresqlpassword",
"HOST": "127.0.0.1",
"HOST": MOMW_DB,
"PORT": "5432",
}
}


Loading…
Cancel
Save