From b94a795189b9a7d38615ac356c9d7761f3174ab0 Mon Sep 17 00:00:00 2001
From: sadnub <josh@torchlake.com>
Date: Wed, 7 Apr 2021 10:54:00 -0400
Subject: [PATCH] specify names for the dev and prod containers and fix
 frontend web .env generation

---
 .devcontainer/docker-compose.yml | 16 ++++++++++++++--
 .devcontainer/entrypoint.sh      |  5 +++--
 docker/docker-compose.yml        | 16 ++++++++++++++--
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml
index 20b3dd86..f9582f8a 100644
--- a/.devcontainer/docker-compose.yml
+++ b/.devcontainer/docker-compose.yml
@@ -2,6 +2,7 @@ version: '3.4'
 
 services:
   api-dev:
+    container_name: trmm-api-dev
     image: api-dev
     restart: always
     build:
@@ -21,6 +22,7 @@ services:
           - tactical-backend
 
   app-dev:
+    container_name: trmm-app-dev
     image: node:14-alpine
     restart: always
     command: /bin/sh -c "npm install npm@latest -g && npm install && npm run serve -- --host 0.0.0.0 --port ${APP_PORT}"
@@ -36,6 +38,7 @@ services:
 
   # nats
   nats-dev:
+    container_name: trmm-nats-dev
     image: ${IMAGE_REPO}tactical-nats:${VERSION}
     restart: always
     environment:
@@ -55,6 +58,7 @@ services:
 
   # meshcentral container
   meshcentral-dev:
+    container_name: trmm-meshcentral-dev
     image: ${IMAGE_REPO}tactical-meshcentral:${VERSION}
     restart: always
     environment: 
@@ -77,6 +81,7 @@ services:
 
   # mongodb container for meshcentral
   mongodb-dev:
+    container_name: trmm-mongodb-dev
     image: mongo:4.4
     restart: always
     environment:
@@ -92,6 +97,7 @@ services:
 
   # postgres database for api service
   postgres-dev:
+    container_name: trmm-postgres-dev
     image: postgres:13-alpine
     restart: always
     environment:
@@ -107,6 +113,7 @@ services:
 
   # redis container for celery tasks
   redis-dev:
+    container_name: trmm-redis-dev
     restart: always
     image: redis:6.0-alpine
     networks:
@@ -115,6 +122,7 @@ services:
           - tactical-redis
 
   init-dev:
+    container_name: trmm-init-dev
     image: api-dev
     build:
       context: .
@@ -143,6 +151,7 @@ services:
 
   # container for celery worker service
   celery-dev:
+    container_name: trmm-celery-dev
     image: api-dev
     build:
       context: .
@@ -160,6 +169,7 @@ services:
 
   # container for celery beat service
   celerybeat-dev:
+    container_name: trmm-celerybeat-dev
     image: api-dev
     build:
       context: .
@@ -175,8 +185,9 @@ services:
       - postgres-dev
       - redis-dev
 
-  # container for celery beat service
+  # container for websockets communication
   websockets-dev:
+    container_name: trmm-websockets-dev
     image: api-dev
     build:
       context: .
@@ -194,8 +205,9 @@ services:
       - postgres-dev
       - redis-dev
 
-  nginx-dev:
   # container for tactical reverse proxy
+  nginx-dev:
+    container_name: trmm-nginx-dev
     image: ${IMAGE_REPO}tactical-nginx:${VERSION}
     restart: always
     environment:
diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh
index 904c74ed..0432c314 100644
--- a/.devcontainer/entrypoint.sh
+++ b/.devcontainer/entrypoint.sh
@@ -136,10 +136,11 @@ if [ "$1" = 'tactical-init-dev' ]; then
   webenv="$(cat << EOF
 PROD_URL = "${HTTP_PROTOCOL}://${API_HOST}"
 DEV_URL = "${HTTP_PROTOCOL}://${API_HOST}"
-APP_URL = https://${APP_HOST}
+APP_URL = "https://${APP_HOST}"
+DOCKER_BUILD = 1
 EOF
 )"
-  echo "${webenv}" | tee ${WORKSPACE_DIR}/web/.env > /dev/null
+  echo "${webenv}" | tee "${WORKSPACE_DIR}"/web/.env > /dev/null
 
   # chown everything to tactical user
   chown -R "${TACTICAL_USER}":"${TACTICAL_USER}" "${WORKSPACE_DIR}"
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 7f693265..c2b2fb06 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -22,6 +22,7 @@ volumes:
 services:
   # postgres database for api service
   tactical-postgres:
+    container_name: trmm-postgres
     image: postgres:13-alpine
     restart: always
     environment:
@@ -35,6 +36,7 @@ services:
 
   # redis container for celery tasks
   tactical-redis:
+    container_name: trmm-redis
     image: redis:6.0-alpine
     restart: always
     networks:
@@ -42,6 +44,7 @@ services:
 
   # used to initialize the docker environment
   tactical-init:
+    container_name: trmm-init
     image: ${IMAGE_REPO}tactical:${VERSION}
     restart: on-failure
     command: ["tactical-init"]
@@ -65,6 +68,7 @@ services:
   
   # nats
   tactical-nats:
+    container_name: trmm-nats
     image: ${IMAGE_REPO}tactical-nats:${VERSION}
     restart: always
     environment:
@@ -80,6 +84,7 @@ services:
 
   # meshcentral container
   tactical-meshcentral:
+    container_name: trmm-meshcentral
     image: ${IMAGE_REPO}tactical-meshcentral:${VERSION}
     restart: always
     environment: 
@@ -101,6 +106,7 @@ services:
 
   # mongodb container for meshcentral
   tactical-mongodb:
+    container_name: trmm-mongodb
     image: mongo:4.4
     restart: always
     environment:
@@ -114,6 +120,7 @@ services:
 
   # container that hosts vue frontend
   tactical-frontend:
+    container_name: trmm-frontend
     image: ${IMAGE_REPO}tactical-frontend:${VERSION}
     restart: always
     networks:
@@ -123,6 +130,7 @@ services:
 
   # container for django backend
   tactical-backend:
+    container_name: trmm-backend
     image: ${IMAGE_REPO}tactical:${VERSION}
     command: ["tactical-backend"]
     restart: always
@@ -135,8 +143,9 @@ services:
     depends_on:
       - tactical-postgres
 
-  # container for django backend
+  # container for django websockets connections
   tactical-websockets:
+    container_name: trmm-websockets
     image: ${IMAGE_REPO}tactical:${VERSION}
     command: ["tactical-websockets"]
     restart: always
@@ -150,8 +159,9 @@ services:
       - tactical-postgres
       - tactical-backend
 
-  tactical-nginx:
   # container for tactical reverse proxy
+  tactical-nginx:
+    container_name: trmm-nginx
     image: ${IMAGE_REPO}tactical-nginx:${VERSION}
     restart: always
     environment:
@@ -171,6 +181,7 @@ services:
 
   # container for celery worker service
   tactical-celery:
+    container_name: trmm-celery
     image: ${IMAGE_REPO}tactical:${VERSION}
     command: ["tactical-celery"]
     restart: always
@@ -186,6 +197,7 @@ services:
 
   # container for celery beat service
   tactical-celerybeat:
+    container_name: trmm-celerybeat
     image: ${IMAGE_REPO}tactical:${VERSION}
     command: ["tactical-celerybeat"]
     restart: always