Browse Source

refactor: Remove unnecessary configuration options

Owen Diffey 2 weeks ago
parent
commit
30cd87d945

+ 0 - 12
.env.example

@@ -1,31 +1,19 @@
 COMPOSE_PROJECT_NAME=musare
-RESTART_POLICY=unless-stopped
 DOCKER_COMMAND=docker
 CONTAINER_MODE=production
 
 APP_ENV=production
 
-BACKEND_HOST=127.0.0.1
-BACKEND_PORT=8080
-
-FRONTEND_HOST=127.0.0.1
-FRONTEND_PORT=80
 FRONTEND_CLIENT_PORT=80
 FRONTEND_DEV_PORT=81
 FRONTEND_PROD_DEVTOOLS=false
 
-MONGO_HOST=127.0.0.1
-MONGO_PORT=27017
 MONGO_ROOT_PASSWORD=PASSWORD_HERE
 MONGO_USER_USERNAME=musare
 MONGO_USER_PASSWORD=OTHER_PASSWORD_HERE
-MONGO_DATA_LOCATION=.db
 MONGO_VERSION=6
 
-REDIS_HOST=127.0.0.1
-REDIS_PORT=6379
 REDIS_PASSWORD=PASSWORD
-REDIS_DATA_LOCATION=.redis
 
 BACKUP_LOCATION=
 BACKUP_NAME=

+ 0 - 11
.github/workflows/automated-tests.yml

@@ -4,23 +4,12 @@ on: [ push, pull_request, workflow_dispatch ]
 
 env:
     COMPOSE_PROJECT_NAME: musare
-    RESTART_POLICY: unless-stopped
     APP_ENV: development
-    BACKEND_HOST: 127.0.0.1
-    BACKEND_PORT: 8080
-    FRONTEND_HOST: 127.0.0.1
-    FRONTEND_PORT: 80
-    MONGO_HOST: 127.0.0.1
-    MONGO_PORT: 27017
     MONGO_ROOT_PASSWORD: PASSWORD_HERE
     MONGO_USER_USERNAME: musare
     MONGO_USER_PASSWORD: OTHER_PASSWORD_HERE
-    MONGO_DATA_LOCATION: .db
     MONGO_VERSION: 5.0
-    REDIS_HOST: 127.0.0.1
-    REDIS_PORT: 6379
     REDIS_PASSWORD: PASSWORD
-    REDIS_DATA_LOCATION: .redis
 
 jobs:
     tests:

+ 0 - 11
.github/workflows/build.yml

@@ -4,23 +4,12 @@ on: [ push, pull_request, workflow_dispatch ]
 
 env:
     COMPOSE_PROJECT_NAME: musare
-    RESTART_POLICY: unless-stopped
     APP_ENV: production
-    BACKEND_HOST: 127.0.0.1
-    BACKEND_PORT: 8080
-    FRONTEND_HOST: 127.0.0.1
-    FRONTEND_PORT: 80
-    MONGO_HOST: 127.0.0.1
-    MONGO_PORT: 27017
     MONGO_ROOT_PASSWORD: PASSWORD_HERE
     MONGO_USER_USERNAME: musare
     MONGO_USER_PASSWORD: OTHER_PASSWORD_HERE
-    MONGO_DATA_LOCATION: .db
     MONGO_VERSION: 5.0
-    REDIS_HOST: 127.0.0.1
-    REDIS_PORT: 6379
     REDIS_PASSWORD: PASSWORD
-    REDIS_DATA_LOCATION: .redis
 
 jobs:
     build:

+ 0 - 11
.github/workflows/lint.yml

@@ -4,23 +4,12 @@ on: [ push, pull_request, workflow_dispatch ]
 
 env:
     COMPOSE_PROJECT_NAME: musare
-    RESTART_POLICY: unless-stopped
     APP_ENV: development
-    BACKEND_HOST: 127.0.0.1
-    BACKEND_PORT: 8080
-    FRONTEND_HOST: 127.0.0.1
-    FRONTEND_PORT: 80
-    MONGO_HOST: 127.0.0.1
-    MONGO_PORT: 27017
     MONGO_ROOT_PASSWORD: PASSWORD_HERE
     MONGO_USER_USERNAME: musare
     MONGO_USER_PASSWORD: OTHER_PASSWORD_HERE
-    MONGO_DATA_LOCATION: .db
     MONGO_VERSION: 5.0
-    REDIS_HOST: 127.0.0.1
-    REDIS_PORT: 6379
     REDIS_PASSWORD: PASSWORD
-    REDIS_DATA_LOCATION: .redis
 
 jobs:
     lint:

+ 11 - 15
.wiki/Configuration.md

@@ -25,28 +25,17 @@ machine, even though the application within the container is listening on `21017
 | Property | Description |
 | --- | --- |
 | `COMPOSE_PROJECT_NAME` | Should be a unique name for this installation, especially if you have multiple instances of Musare on the same machine. |
-| `RESTART_POLICY` | Restart policy for Docker containers, values can be found [here](https://docs.docker.com/config/containers/start-containers-automatically/). |
 | `DOCKER_COMMAND` | Should be either `docker` or `podman`.  |
 | `CONTAINER_MODE` | Should be either `production` or `local`.  |
 | `APP_ENV` | Should be either `production` or `development`.  |
-| `BACKEND_HOST` | Backend container host. Only used for development mode. |
-| `BACKEND_PORT` | Backend container port. Only used for development mode. |
-| `FRONTEND_HOST` | Frontend container host. |
-| `FRONTEND_PORT` | Frontend container port. |
 | `FRONTEND_CLIENT_PORT` | Should be the port on which the frontend will be accessible from, usually port `80`, or `443` if using SSL. Only used when running in development mode. |
 | `FRONTEND_DEV_PORT` | Should be the port where Vite's dev server will be accessible from, should always be port `81` for Docker since nginx listens on port 80, and is recommended to be port `80` for non-Docker. Only used when running in development mode. |
 | `FRONTEND_PROD_DEVTOOLS` | Whether to enable Vue dev tools in production builds. [^1] |
-| `MONGO_HOST` | Mongo container host. |
-| `MONGO_PORT` | Mongo container port. |
 | `MONGO_ROOT_PASSWORD` | Password of the root/admin user for MongoDB. |
 | `MONGO_USER_USERNAME` | Application username for MongoDB. |
 | `MONGO_USER_PASSWORD` | Application password for MongoDB. |
-| `MONGO_DATA_LOCATION` | The location where MongoDB stores its data. Usually the `.db` folder inside the `Musare` folder. |
 | `MONGO_VERSION` | The MongoDB version to use for scripts and docker compose. Must be numerical. Currently supported MongoDB versions are 4.0+. Always make a backup before changing this value. |
-| `REDIS_HOST` | Redis container host. |
-| `REDIS_PORT` | Redis container port. |
 | `REDIS_PASSWORD` | Redis password. |
-| `REDIS_DATA_LOCATION` | The location where Redis stores its data. Usually the `.redis` folder inside the `Musare` folder. |
 | `BACKUP_LOCATION` | Directory to store musare.sh backups. Defaults to `/backups` in script location. |
 | `BACKUP_NAME` | Name of musare.sh backup files. Defaults to `musare-$(date +"%Y-%m-%d-%s").dump`. |
 | `MUSARE_SITENAME` | Should be the name of the site. [^1] |
@@ -173,13 +162,20 @@ For more information on configuration files please refer to the
 You may want to override the docker-compose files in some specific cases.  
 For this, you can create a `docker-compose.override.yml` file.
 
-For example, to expose the backend port:
+For example, to expose the frontend port:
 
 ```yml
 services:
-  backend:
+  frontend:
     ports:
-      - "${BACKEND_HOST}:${BACKEND_PORT}:8080"
+      - "127.0.0.1:1234:80"
 ```
 
-This assumes that you have also set `BACKEND_PORT` inside your `.env` file.
+...and to expose the backend debug port:
+
+```yml
+services:
+  backend:
+    ports:
+      - "127.0.0.1:9229:9229"
+```

+ 4 - 0
Dockerfile

@@ -34,6 +34,8 @@ COPY --chown=musare:musare --link --from=backend_node_modules /opt/app/node_modu
 
 ENTRYPOINT npm run prod
 
+EXPOSE 8080
+
 # Frontend node modules
 FROM common_base AS frontend_node_modules
 
@@ -77,3 +79,5 @@ FROM nginx AS frontend
 
 COPY --chown=root:root --link frontend/nginx.prod.conf /etc/nginx/conf.d/default.conf
 COPY --from=frontend_build --chown=nginx:nginx --link /opt/app/build /usr/share/nginx/html
+
+EXPOSE 80

+ 4 - 0
Dockerfile.dev

@@ -34,6 +34,8 @@ COPY --chown=musare:musare --link --from=backend_node_modules /opt/app/node_modu
 
 ENTRYPOINT sh /opt/app/entrypoint.dev.sh
 
+EXPOSE 8080
+
 # Frontend node modules
 FROM common_base AS frontend_node_modules
 
@@ -76,3 +78,5 @@ COPY --chown=musare:musare --link frontend /opt/app
 COPY --chown=musare:musare --from=frontend_node_modules --link /opt/app/node_modules node_modules
 
 ENTRYPOINT sh /opt/app/entrypoint.dev.sh
+
+EXPOSE 80

+ 11 - 10
docker-compose.dev.yml

@@ -2,8 +2,6 @@ services:
   backend:
     build:
       dockerfile: ./Dockerfile.dev
-    ports:
-      - "${BACKEND_HOST:-0.0.0.0}:${BACKEND_PORT:-8080}:8080"
     environment:
       - APP_ENV=${APP_ENV:-development}
 
@@ -12,11 +10,14 @@ services:
       dockerfile: ./Dockerfile.dev
     environment:
       - APP_ENV=${APP_ENV:-development}
-
-  mongo:
-    ports:
-      - "${MONGO_HOST:-0.0.0.0}:${MONGO_PORT:-27017}:${MONGO_PORT:-27017}"
-
-  redis:
-    ports:
-      - "${REDIS_HOST:-0.0.0.0}:${REDIS_PORT:-6379}:6379"
+      - FRONTEND_CLIENT_PORT=${FRONTEND_CLIENT_PORT:-80}
+      - FRONTEND_DEV_PORT=${FRONTEND_DEV_PORT:-81}
+      - FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS:-false}
+      - MUSARE_SITENAME=${MUSARE_SITENAME:-Musare}
+      - MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR:-#03a9f4}
+      - MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION:-true}
+      - MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE:-false}
+      - MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL:-false}
+      - MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH:-true}
+      - MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT:-true}
+      - MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT:-true}

+ 0 - 4
docker-compose.local.yml

@@ -12,7 +12,3 @@ services:
       - ./common:/opt/common
       - ./types:/opt/types
       - ./frontend:/opt/app
-
-  redis:
-    volumes:
-      - ${REDIS_DATA_LOCATION:-./redis}:/data

+ 11 - 22
docker-compose.yml

@@ -6,7 +6,7 @@ services:
       context: .
       dockerfile: ./Dockerfile
       target: backend
-    restart: ${RESTART_POLICY:-unless-stopped}
+    restart: unless-stopped
     volumes:
       - ./backend/config:/opt/app/config
     environment:
@@ -42,43 +42,32 @@ services:
         MUSARE_DEBUG_GIT_BRANCH: ${MUSARE_DEBUG_GIT_BRANCH:-true}
         MUSARE_DEBUG_GIT_LATEST_COMMIT: "${MUSARE_DEBUG_GIT_LATEST_COMMIT:-true}"
         MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT: "${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT:-true}"
-    restart: ${RESTART_POLICY:-unless-stopped}
-    ports:
-      - "${FRONTEND_HOST:-0.0.0.0}:${FRONTEND_PORT:-80}:80"
-    environment:
-      - FRONTEND_PORT=${FRONTEND_PORT:-80}
-      - FRONTEND_CLIENT_PORT=${FRONTEND_CLIENT_PORT:-80}
-      - FRONTEND_DEV_PORT=${FRONTEND_DEV_PORT:-81}
-      - FRONTEND_PROD_DEVTOOLS=${FRONTEND_PROD_DEVTOOLS:-false}
-      - MUSARE_SITENAME=${MUSARE_SITENAME:-Musare}
-      - MUSARE_PRIMARY_COLOR=${MUSARE_PRIMARY_COLOR:-#03a9f4}
-      - MUSARE_DEBUG_VERSION=${MUSARE_DEBUG_VERSION:-true}
-      - MUSARE_DEBUG_GIT_REMOTE=${MUSARE_DEBUG_GIT_REMOTE:-false}
-      - MUSARE_DEBUG_GIT_REMOTE_URL=${MUSARE_DEBUG_GIT_REMOTE_URL:-false}
-      - MUSARE_DEBUG_GIT_BRANCH=${MUSARE_DEBUG_GIT_BRANCH:-true}
-      - MUSARE_DEBUG_GIT_LATEST_COMMIT=${MUSARE_DEBUG_GIT_LATEST_COMMIT:-true}
-      - MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT=${MUSARE_DEBUG_GIT_LATEST_COMMIT_SHORT:-true}
+    restart: unless-stopped
     links:
       - backend
 
   mongo:
     image: docker.io/mongo:${MONGO_VERSION}
-    restart: ${RESTART_POLICY:-unless-stopped}
+    restart: unless-stopped
     environment:
       - MONGO_INITDB_ROOT_USERNAME=admin
       - MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
       - MONGO_INITDB_DATABASE=musare
-      - MONGO_PORT=${MONGO_PORT:-27017}
       - MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
       - MONGO_USER_USERNAME=${MONGO_USER_USERNAME}
       - MONGO_USER_PASSWORD=${MONGO_USER_PASSWORD}
     volumes:
       - ./tools/docker/setup-mongo.sh:/docker-entrypoint-initdb.d/setup-mongo.sh
-      - ${MONGO_DATA_LOCATION:-./db}:/data/db
+      - database:/data/db
 
   redis:
     image: docker.io/redis:7
-    restart: ${RESTART_POLICY:-unless-stopped}
+    restart: unless-stopped
     command: "--notify-keyspace-events Ex --requirepass ${REDIS_PASSWORD} --appendonly yes"
     volumes:
-      - /data
+      - cache:/data
+
+volumes:
+  database:
+
+  cache:

+ 0 - 20
musare.sh

@@ -201,29 +201,15 @@ case $1 in
         echo -e "${CYAN}Musare | Reset Services${NC}"
         servicesString=$(handleServices "backend frontend mongo redis" "${@:2}")
         if [[ ${servicesString:0:1} == 1 && ${servicesString:2:4} == "all" ]]; then
-            echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} and ${MONGO_DATA_LOCATION} directories.${NC}"
             echo -e "${GREEN}Are you sure you want to reset all data? ${YELLOW}[y,n]: ${NC}"
             read -r confirm
             if [[ "${confirm}" == y* ]]; then
                 runDockerCommand "$(basename "$0") $1" stop
                 ${dockerCompose} rm -v --force
-                if [[ -d $REDIS_DATA_LOCATION ]]; then
-                    rm -rf "${REDIS_DATA_LOCATION}"
-                fi
-                if [[ -d $MONGO_DATA_LOCATION ]]; then
-                    rm -rf "${MONGO_DATA_LOCATION}"
-                fi
             else
                 echo -e "${RED}Cancelled reset${NC}"
             fi
         elif [[ ${servicesString:0:1} == 1 ]]; then
-            if [[ "${servicesString:2}" == *redis* && "${servicesString:2}" == *mongo* ]]; then
-                echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} and ${MONGO_DATA_LOCATION} directories.${NC}"
-            elif [[ "${servicesString:2}" == *redis* ]]; then
-                echo -e "${RED}Resetting will remove the ${REDIS_DATA_LOCATION} directory.${NC}"
-            elif [[ "${servicesString:2}" == *mongo* ]]; then
-                echo -e "${RED}Resetting will remove the ${MONGO_DATA_LOCATION} directory.${NC}"
-            fi
             echo -e "${GREEN}Are you sure you want to reset all data for $(echo "${servicesString:2}" | tr ' ' ',')? ${YELLOW}[y,n]: ${NC}"
             read -r confirm
             if [[ "${confirm}" == y* ]]; then
@@ -231,12 +217,6 @@ case $1 in
                 runDockerCommand "$(basename "$0") $1" stop ${servicesString:2}
                 # shellcheck disable=SC2086
                 ${dockerCompose} rm -v --force ${servicesString}
-                if [[ "${servicesString:2}" == *redis* && -d $REDIS_DATA_LOCATION ]]; then
-                    rm -rf "${REDIS_DATA_LOCATION}"
-                fi
-                if [[ "${servicesString:2}" == *mongo* && -d $MONGO_DATA_LOCATION ]]; then
-                    rm -rf "${MONGO_DATA_LOCATION}"
-                fi
             else
                 echo -e "${RED}Cancelled reset${NC}"
             fi