diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..8ed7a56b --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +DOCKER_COMPOSE = COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose -p bma -f docker/compose.yaml +DOCKER_RUN = ${DOCKER_COMPOSE} run -u `id -u` +MANAGE_EXEC = ${DOCKER_COMPOSE} exec app python /app/src/manage.py +MANAGE_RUN = ${DOCKER_RUN} app python /app/src/manage.py +PARALLEL=4 +TEST_OPTIONS = --failfast --keepdb --parallel ${PARALLEL} +TEST_TO_RUN = . + +init: copy_env_file migrate + +run: + ${DOCKER_COMPOSE} up + +migrate: + ${MANAGE_RUN} $@ ${ARGS} + +makemigrations: + ${MANAGE_RUN} $@ ${ARGS} + +bootstrap_devsite: + ${MANAGE_RUN} $@ ${ARGS} + +shell: + ${MANAGE_RUN} $@ ${ARGS} + +manage: + ${MANAGE_RUN} ${COMMAND} + +test: + ${DOCKER_RUN} app \ + bash -c "cd /app/src/; python manage.py test $(TEST_OPTIONS) ${TEST_TO_RUN}" + +build_docker_image: + ${DOCKER_COMPOSE} build app + +copy_env_file: + test -f src/bma/environment_settings.py || cp src/bma/environment_settings.py.dist src/bma/environment_settings.py + test -f docker/.env || cp docker/.env.dev docker/.env diff --git a/docker/.env.dev b/docker/.env.dev new file mode 100644 index 00000000..8b959df8 --- /dev/null +++ b/docker/.env.dev @@ -0,0 +1,3 @@ +# Ports are purposefully selected to not conflict with default ports for bornhack-website +db_port=5433 +web_port=8001 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..93a23a19 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +FROM python:3.10-slim-bullseye + +ENV PYTHONFAULTHANDLER=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PYTHONHASHSEED=random \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 + +WORKDIR /app + +RUN apt-get update \ + && apt-get install -y \ + build-essential \ + binutils \ + python3-dev \ + python3-pip \ + python3-setuptools \ + python3-cffi \ + libxslt-dev \ + libxml2-dev \ + libxmlsec1-dev \ + libpq-dev \ + libjpeg-dev \ + libgdal-dev \ + wkhtmltopdf + +RUN --mount=type=bind,readwrite,source=.,target=/app \ + pip3 install --no-cache-dir /app[dev,test] + +RUN groupadd -g 1000 www +RUN useradd -u 1000 -ms /bin/bash -g www www diff --git a/docker/compose.yaml b/docker/compose.yaml new file mode 100644 index 00000000..05c2ebee --- /dev/null +++ b/docker/compose.yaml @@ -0,0 +1,36 @@ +services: + app: + build: + context: .. + dockerfile: docker/Dockerfile + ports: + - "${web_port}:8000" + tty: true + stdin_open: true + command: python src/manage.py runserver 0.0.0.0:8000 + volumes: + - ..:/app + depends_on: + - db + environment: + - DJANGO_SECRET_KEY=a-long-randomsecret-key + - DJANGO_DEBUG=True + - DEBUG_TOOLBAR=True + - DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 + - DJANGO_DATABASE_URL=postgres://bma:hunter12@db:5432/bma + - DJANGO_ADMIN_PREFIX=notadmin + - DJANGO_MEDIA_ROOT=/persist/django_media_root + - DJANGO_NGINX_PROXY=false + - DJANGO_LOG_LEVEL=INFO + - BMA_LOG_LEVEL=INFO + - DJANGO_CORS_ALLOWED_ORIGINS=http://127.0.0.1:8000 + - BMA_CREATOR_GROUP_NAME=creators + - BMA_MODERATOR_GROUP_NAME=moderators + - BMA_CURATOR_GROUP_NAME=curators + db: + image: postgis/postgis:14-3.3-alpine + environment: + - POSTGRES_USER=bma + - POSTGRES_PASSWORD=hunter12 + ports: + - "${db_port}:5432" \ No newline at end of file