Browse Source

Tweaked docker setup a little, fixed eventual clashes in migration

Rafał Pitoń 7 years ago
parent
commit
46541c92bd

+ 7 - 10
.dockerignore

@@ -1,14 +1,11 @@
 # Speed up bulding by excluding files from the docker context
-
-# Project files we don't need in docker
-postgres/
-
-# Local development stuff
+_book/
 dev/
+dist/
+docs/
 env/
+frontend/
 venv/
-venv2/
-venv3/
-venv34/
-venv35/
-venv36/
+
+.DS_Store
+thumbs.db

+ 1 - 8
.gitignore

@@ -68,20 +68,13 @@ _book/
 
 # Local development stuff
 dev/
-dev-manage.py
 env/
 venv/
-venv2/
-venv3/
-venv34/
-venv35/
-venv36/
-future-manage.py
 misago-admin.py
 db.sqlite3
 
 # Local development files
 /manage.py
-/devforum/
+/devproject/
 /avatargallery/
 /static/

+ 14 - 45
README.rst

@@ -82,62 +82,31 @@ If you are looking into using Misago to run live forum, you are absolutely invit
 Development
 ===========
 
-To start Misago site locally, first make sure you have `docker <https://www.docker.com/community-edition#/download>`_ installed.
+To start Misago site locally, first make sure you have `Docker <https://www.docker.com/community-edition#/download>`_ installed.
 
-To get a basic empty forum up simply run::
+Next, clone repository on your machine and run following commands::
 
    docker-compose build
    docker-compose run --rm misago initdev
-   docker-compose up -d
+   docker-compose up
 
-A Django developer server will start, enabling you to visit ``127.0.0.1:8000``
-in your browser and see the forum index. You should now be able to sign in with the superuser account.
+Those commands will install necessary dependencies, create new Misago project `devproject` that you may use for development as well as start Django developer server, enabling you to visit ``127.0.0.1:8000``
+in your browser and see the forum index. You should now be able to sign in with the superuser account, using `Admin` username and `password` password.
 
-Admin Control Panel available under ``127.0.0.1:8000/admincp/`` url.
+Admin Control Panel is available under the ``127.0.0.1:8000/admincp/`` url.
 
-The ``initdev`` script prepares everything you need:
+`manage.py` is available through Docker's `run` command::
+    
+    docker-compose run --rm misago python manage.py
 
-* requirements are installed
-* ``devforum`` project is created in the misago project root
-* ``settings.py`` is modified with variables from the ``docker-compose.yaml`` file
-* database migrations runs
-* superuser is created
-
-The default env vars passed in ``docker-compose.yml`` is:
-
-.. code-block:: yaml
-
-    environment:
-      # Postgres
-      - POSTGRES_USER=misago
-      - POSTGRES_PASSWORD=misago
-      - POSTGRES_DB=misago
-      - POSTGRES_HOST=postgres
-      - POSTGRES_TEST_DB=misago_test
-      # Superuser
-      - SUPERUSER_USERNAME=Admin
-      - SUPERUSER_EMAIL=admin@example.com
-      - SUPERUSER_PASSWORD=password
-
-Some useful commands during development:
-
-.. code-block:: bash
-
-    # Enter the running misago container
-    docker-compose exec misago bash
-
-    # Manually run the misago container. Run ``python manage.py runserver 0.0.0.0:8000``.
-    # This can be useful when debugging.
-    docker-compose run --rm --service-ports misago bash
+Docker also allows you to run tests suite::
+    
+    docker-compose run --rm misago python runtests.py
 
-    # View container logs
-    docker-compose logs -f --tail 100
+If you'll ever want to destroy Docker setup because you no longer need it, run this command::
 
-    # Enter psql so you can inspect or modify the database
-    docker-compose run --rm misago extras/psql.sh
+    docker-compose down
 
-    # Runnning tests
-    docker-compose run --rm misago python runtests.py
 
 Frontend
 --------

+ 7 - 6
docker-compose.yaml

@@ -3,18 +3,15 @@
 version: "3.0"
 services:
   postgres:
-    build: postgres
+    image: postgres:10
     environment:
       - POSTGRES_USER=misago
       - POSTGRES_PASSWORD=misago
-      - POSTGRES_DB=misago
+    ports:
+      - '127.0.0.1:5432:5432'
   misago:
     build: .
     command: python manage.py runserver 0.0.0.0:8000
-    volumes:
-      # Map in the entire project into the container
-      # This makes sure files in the container updates on the fly as we were working locally
-      - .:/srv/misago
     environment:
       # Postgres
       - POSTGRES_USER=misago
@@ -33,3 +30,7 @@ services:
     depends_on:
       - postgres
     tty: true
+    volumes:
+      # Map in the entire project into the container
+      # This makes sure files in the container updates on the fly as we were working locally
+      - .:/srv/misago:Z

+ 6 - 6
extras/createdevproject.py

@@ -1,5 +1,5 @@
 """
-Creates a test project for local development
+Creates a dev project for local development
 """
 
 import os
@@ -12,7 +12,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 
 def main():
-    project_name = 'devforum'
+    project_name = 'devproject'
 
     # Allow for overriding project name
     if len(sys.argv) > 1:
@@ -35,10 +35,10 @@ def fill_in_settings(f):
         s = fd.read()
 
         # Postgres
-        s = s.replace("'NAME': '',", "'NAME': os.environ['POSTGRES_DB'],")
-        s = s.replace("'USER': '',", "'USER': os.environ['POSTGRES_USER'],")
-        s = s.replace("'PASSWORD': '',", "'PASSWORD': os.environ['POSTGRES_PASSWORD'],")
-        s = s.replace("'HOST': 'localhost',", "'HOST': os.environ['POSTGRES_HOST'],")
+        s = s.replace("'NAME': '',", "'NAME': os.environ.get('POSTGRES_DB'),")
+        s = s.replace("'USER': '',", "'USER': os.environ.get('POSTGRES_USER'),")
+        s = s.replace("'PASSWORD': '',", "'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),")
+        s = s.replace("'HOST': 'localhost',", "'HOST': os.environ.get('POSTGRES_HOST'),")
 
         # Specify console backend for email
         s += "\nEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n"

+ 9 - 4
extras/createsuperuser.py

@@ -1,21 +1,26 @@
 """
-Create superuser for the devforum
+Create superuser for the devproject
 """
 
 import os
 import django
 
-os.environ['DJANGO_SETTINGS_MODULE'] = 'devforum.settings'
+os.environ['DJANGO_SETTINGS_MODULE'] = 'devproject.settings'
 django.setup()
 
 from django.contrib.auth import get_user_model
+from django.utils.crypto import get_random_string
 
 User = get_user_model()
 
 
 if User.objects.count() == 0:
-    User.objects.create_superuser(
+    superuser = User.objects.create_superuser(
         os.environ['SUPERUSER_USERNAME'],
         os.environ['SUPERUSER_EMAIL'],
-        password=os.environ['SUPERUSER_PASSWORD']
+        get_random_string(10) # set throwaway password
     )
+
+    # Override user's throwaway password with configured one
+    superuser.set_password(os.environ['SUPERUSER_PASSWORD'])
+    superuser.save()

+ 1 - 1
initdev

@@ -3,7 +3,7 @@
 python setup.py develop
 
 # Create new project
-python extras/createdevproject.py devforum /srv/misago
+python extras/createdevproject.py devproject /srv/misago
 
 # Clean up unnecessary project files
 rm -rf theme

+ 2 - 2
misago/users/migrations/0001_initial.py

@@ -186,7 +186,7 @@ class Migration(migrations.Migration):
                 ),
             ],
             options={
-                'get_latest_by': b'changed_on',
+                'get_latest_by': 'changed_on',
             },
             bases=(models.Model, ),
         ),
@@ -209,7 +209,7 @@ class Migration(migrations.Migration):
                 ('roles', models.ManyToManyField(to='misago_acl.Role', null=True, blank=True)),
             ],
             options={
-                'get_latest_by': b'order',
+                'get_latest_by': 'order',
             },
             bases=(models.Model, ),
         ),

+ 2 - 2
misago/users/migrations/0011_auto_20180326_1926.py → misago/users/migrations/0011_auto_20180331_2208.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Generated by Django 1.11.9 on 2018-03-26 19:26
+# Generated by Django 1.11.11 on 2018-03-31 22:08
 from __future__ import unicode_literals
 
 from django.db import migrations, models
@@ -20,6 +20,6 @@ class Migration(migrations.Migration):
         ),
         migrations.AddIndex(
             model_name='user',
-            index=misago.core.pgutils.PgPartialIndex(fields=['is_deleting_account'], name='misago_user_delete__8d97e7_part', where={'is_deleting_account': True}),
+            index=misago.core.pgutils.PgPartialIndex(fields=['is_deleting_account'], name='misago_user_is_dele_2798b0_part', where={'is_deleting_account': True}),
         ),
     ]

+ 0 - 3
postgres/Dockerfile

@@ -1,3 +0,0 @@
-FROM postgres:9
-
-COPY docker-entrypoint-initdb.d /docker-entrypoint-initdb.d

+ 0 - 7
postgres/docker-entrypoint-initdb.d/create-test-db.sh

@@ -1,7 +0,0 @@
-#!/bin/bash
-set -e
-
-psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
-    CREATE DATABASE misago_test;
-    GRANT ALL PRIVILEGES ON DATABASE misago_test TO "$POSTGRES_USER";
-EOSQL

+ 1 - 1
requirements.txt

@@ -11,7 +11,7 @@ html5lib==0.999999999
 markdown~=2.6.8
 path.py~=10.3.1
 pillow~=4.1.1
-psycopg2~=2.7.1
+psycopg2-binary~=2.7.1
 pytz
 requests<3
 unidecode~=0.4.20