Browse Source

Another pass on dev: rename clear to remove, tweak some messages, add manage.py shortcut

rafalp 6 years ago
parent
commit
8a0d61ffd4
4 changed files with 41 additions and 53 deletions
  1. 6 21
      README.rst
  2. 34 29
      dev
  3. 0 2
      docker-compose.yaml
  4. 1 1
      misago/bin/misago-start-devproject.py

+ 6 - 21
README.rst

@@ -86,31 +86,16 @@ If you are looking into using Misago to run live forum, you are absolutely invit
 Development
 ===========
 
-Preferred way to setup Misago for local development is with `Docker <https://www.docker.com/community-edition#/download>`_, which makes it easy to spin up arbitrary number of instances running different code with separate databases and dependencies one besides the other with just three terminal commands.
+Preferred way to run Misago development instances on your machine is with `Docker <https://www.docker.com/community-edition#/download>`_, which makes it easy to spin up arbitrary number of instances running different code with separate databases and dependencies besides each other.
 
-To start, clone repository to your machine and then run following commands::
+To start, clone the repository and run ``./dev init`` command in your terminal. This will build necessary docker containers, install python dependencies, initialize the database and create development project for you. After command does its magic, you will be able to start development server using the `docker-compose up` command.
 
-   docker-compose build
-   docker-compose run --rm misago initdev
-   docker-compose up
+After development server starts, visit the ``http://127.0.0.1:8000/`` in your browser to see default your Misago installation.
 
-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 is available under the ``127.0.0.1:8000/admincp/`` url.
-
-`manage.py` is available through Docker's `run` command::
-    
-    docker-compose run --rm misago python manage.py
-
-Docker also allows you to run tests suite::
-    
-    docker-compose run --rm misago python runtests.py
-
-If you'll ever want to destroy Docker setup because you no longer need it, run this command::
-
-    docker-compose down
+Admin Control Panel is available under the ``http://127.0.0.1:8000/admincp/`` address. To log in to it use ``Admin`` username and ``password`` password.
 
+The ``./dev`` utility provides many more features, run it without any arguments to get the list of them.
+ 
 
 Frontend
 --------

+ 34 - 29
dev

@@ -30,8 +30,9 @@ required_ports=($port_postgresql $port_django)
 # Default superuser
 username="Admin"
 password="password"
+email="admin@example.com"
 
-# Some commond shorthands
+# Utils used elsewhere
 error() {
     echo -e "${RED}Error:${NORMAL} $1"
 }
@@ -56,7 +57,7 @@ wait_for_db() {
 }
 
 # Check if user has docker-compose
-if [[ ! $IN_DOCKER = 1 ]]; then
+if [[ ! $IN_MISAGO_DOCKER = 1 ]]; then
     if ! command -v docker-compose >/dev/null 2>&1; then
         error "You need to have Docker installed to use this tool."
         echo
@@ -74,11 +75,11 @@ intro() {
     echo
     echo "Development project:"
     echo
-    echo "    ${BOLD}init${NORMAL}              initialize new dev project for development, do nothing if project already exists."
-    echo "    ${BOLD}afterinit${NORMAL}         display help message displayed after init command is complete."
-    echo "    ${BOLD}clear${NORMAL}             if dev project exists, delete it's files and destroy docker containers."
+    echo "    ${BOLD}init${NORMAL}              initialize new dev project for development, does nothing if project already exists."
+    echo "    ${BOLD}afterinit${NORMAL}         repeat help message displayed after init command is complete."
+    echo "    ${BOLD}remove${NORMAL}            if dev project exists, delete it's files and destroy docker containers."
     echo "    ${BOLD}rebuild${NORMAL}           rebuild docker containers."
-    echo "    ${BOLD}reset${NORMAL}             run clear followed by init."
+    echo "    ${BOLD}reset${NORMAL}             run remove followed by init."
     echo
     echo "    Both init and rebuild args can be followed with any number of extra args and options that should be forwarded to docker-compose build."
     echo
@@ -98,9 +99,10 @@ intro() {
     echo
     echo "Shortcuts:"
     echo
-    echo "    ${BOLD}bash${NORMAL}              shortcut for entering bash session inside running Misago container."
-    echo "    ${BOLD}run${NORMAL}               shortcut for \"docker-compose run --rm misago\"."
-    echo "    ${BOLD}psql${NORMAL}              shortcut for dev database's psql."
+    echo "    ${BOLD}manage.py${NORMAL}         runs \"python manage.py\" inside docker."
+    echo "    ${BOLD}bash${NORMAL}              starts bash session inside running Misago container."
+    echo "    ${BOLD}run${NORMAL}               runs \"docker-compose run --rm misago\"."
+    echo "    ${BOLD}psql${NORMAL}              runs psql connected to development database."
     echo
 }
 
@@ -113,16 +115,12 @@ invalid_argument() {
 
 # Initialize new dev project
 init() {
-    if [[ $2 = "message" ]]; then
-        after_init_message
-        exit 0
-    fi
-
     for dev_path in "${dev_paths[@]}"; do
         if [ -e $dev_path ]; then
             error "Dev project already exists, or was not deleted completely."
             echo
-            echo "Please use \"clear\" option to clear any possible remaining files and try again."
+            echo "Please use \"remove\" option to remove any possible remaining files and try again."
+            echo
             exit 1
         fi
     done
@@ -133,10 +131,12 @@ init() {
             if [[ $port = $port_django ]]; then
                 error "Other application appears to already be running on http://127.0.0.1:8000"
             elif [[ $port = $port_postgresql ]]; then
-                error "Other PostgreSQL instance appears to already be running on port $port."
+                error "PostgreSQL appears to already be running on the port $port."
+                echo
+                echo "Misago runs its own PostgreSQL instance in the docker container and uses port $port to expose it to other programs."
+                echo "Please stop your PostgreSQL server and try again."
+                echo
             fi
-            echo
-            echo "Please stop other process and try again."
             exit 1
         fi
     done
@@ -163,7 +163,7 @@ init_in_docker() {
     # migrate the DB
     python manage.py migrate
     # create superuser Admin with password "password"
-    python manage.py createsuperuser --username $username --email admin@example.com --password $password
+    python manage.py createsuperuser --username $username --email $email --password $password
 
     # display after init message
     echo
@@ -187,7 +187,7 @@ after_init_message() {
     echo
     echo "Development project directories:"
     echo
-    echo "devproject        contains configuration files for development instance."
+    echo "devproject        configuration files for development instance."
     echo "media             user uploaded files."
     echo "userdata          working directory for user data exports."
     echo "avatargallery     example avatar gallery."
@@ -204,9 +204,9 @@ after_init_message() {
     echo
 }
 
-# Clear existing dev project
-clear() {
-    echo -e "${RED}Warning:${NORMAL} You are going clear current development project."
+# Remove existing dev project
+remove() {
+    echo -e "${RED}Warning:${NORMAL} You are going remove current development project."
     echo
 
     will_delete_files=false
@@ -225,8 +225,6 @@ clear() {
         echo
     fi
 
-    echo "This will also stop and remove docker containers used by this project."
-    echo
     echo "Enter \"y\" to confirm:"
 
     read confirmation
@@ -304,7 +302,12 @@ docker_run_bash() {
     docker exec -it misago_misago_1 bash
 }
 
-# Shortcut for docker-compose run...
+# Shortcut for docker-compose run --rm misago python manage.py
+docker_run_managepy() {
+    docker-compose run --rm misago python manage.py "${@:2}"
+}
+
+# Shortcut for docker-compose run --rm misago...
 docker_run() {
     docker-compose run --rm misago "${@:2}"
 }
@@ -327,10 +330,10 @@ if [[ $1 ]]; then
         init_in_docker
     elif [[ $1 = "afterinit" ]]; then
         after_init_message
-    elif [[ $1 = "clear" ]]; then
-        clear
+    elif [[ $1 = "remove" ]]; then
+        remove
     elif [[ $1 = "reset" ]]; then
-        clear
+        remove
         init $@
     elif [[ $1 = "rebuild" ]]; then
         rebuild $@
@@ -355,6 +358,8 @@ if [[ $1 ]]; then
         compilemessages
     elif [[ $1 = "bash" ]]; then
         docker_run_bash
+    elif [[ $1 = "manage.py" ]]; then
+        docker_run_managepy $@
     elif [[ $1 = "run" ]]; then
         docker_run $@
     elif [[ $1 = "psql" ]]; then

+ 0 - 2
docker-compose.yaml

@@ -13,8 +13,6 @@ services:
     build: .
     command: python manage.py runserver 0.0.0.0:8000
     environment:
-      # Name of development project
-      - PROJECT_NAME=devproject
       # Postgres
       - POSTGRES_USER=misago
       - POSTGRES_PASSWORD=misago

+ 1 - 1
misago/bin/misago-start-devproject.py

@@ -11,7 +11,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__fil
 
 
 def main():
-    project_name = os.environ['PROJECT_NAME']
+    project_name = 'devproject'
 
     # Allow for overriding project name
     if len(sys.argv) > 1: