diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index a4b74cc..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,42 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose -{ - "name": "Existing Docker Compose (Extend)", - - // Update the 'dockerComposeFile' list if you have more compose files or use different names. - // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. - "dockerComposeFile": [ - "../docker-compose.yml", - "../test-compose.yml", - "docker-compose.yml" - ], - - // The 'service' property is the name of the service for the container that VS Code should - // use. Update this value and .devcontainer/docker-compose.yml to the real service name. - "service": "admin", - - // The optional 'workspaceFolder' property is the path VS Code should open by default when - // connected. This is typically a file mount in .devcontainer/docker-compose.yml - "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" - - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Uncomment the next line if you want start specific services in your Docker Compose config. - // "runServices": [], - - // Uncomment the next line if you want to keep your containers running after VS Code shuts down. - // "shutdownAction": "none", - - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "cat /etc/os-release", - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "devcontainer" -} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index 93bf054..0000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,26 +0,0 @@ -version: '3' -services: - # Update this to the name of the service you want to work with in your docker-compose.yml file - admin: - # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer - # folder. Note that the path of the Dockerfile and context is relative to the *primary* - # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" - # array). The sample below assumes your primary file is in the root of your project. - # - # build: - # context: . - # dockerfile: .devcontainer/Dockerfile - - volumes: - # Update this to wherever you want VS Code to mount the folder of your project - - ..:/workspaces:cached - - # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. - # cap_add: - # - SYS_PTRACE - # security_opt: - # - seccomp:unconfined - - # Overrides default command so things don't shut down after the process ends. - command: /bin/sh -c "while sleep 1000; do :; done" - diff --git a/README.md b/README.md index 24d3aa8..971c250 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,15 @@ You can then browser to: *Interesting Note*: Safari 13+ does not like the **.test** TLD and doesn't seem to want to store cookies from the TLD. It seems to work fine in production when you are using a real TLD. I guess use Chrome for local testing or a different TLD for testing, like local. https://stackoverflow.com/questions/62023857/sharing-cookies-across-test-sub-domains-in-safari-13-not-possible +### Debugging Node Servers using Dev Containers + +VS Code makes it easy to work on code running in a Docker container - whether it is on your machine or on a remote host. The [Dev Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension lets you edit files running inside a Docker container. Install the [Remote Explorer](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer) extension to work with remote hosts over SSH. + +If you are editing on a remote host, first use the Remote Explorer to get to that machine. + +Now, launch all of the containers using `./docker-test.sh up -d`. The **Account**, **Admin**, **Frontend** and **Backend** node servers will all be started using [Nodemon](https://nodemon.io). When you make a change to any of the server related files, the server will reload. This makes it easy to edit and test against running code in a full deployment. To go to one of these Containers, open the Remote Explorer extension from the sidebar, select Dev Containers from the dropdown in the upper right of the sidebar, and then choose the Container you wish to work on. + + ### Debugging React Apps using Hot Reloading If you are trying to make changes to any of react frontends, it is a huge pain to have to compile to site and rebuild the container each time you make a change. Instead, simply run the react app in development mode. This will work for the frontends for the: - admin frontend diff --git a/account/Dockerfile b/account/Dockerfile index d1bbfdf..46c492f 100644 --- a/account/Dockerfile +++ b/account/Dockerfile @@ -22,6 +22,7 @@ COPY ./package.json /tmp RUN cd /tmp && npm install RUN cp -a /tmp/node_modules /app RUN env +RUN npm install -g nodemon WORKDIR /app COPY server /app COPY --from=build /app/build /app/public diff --git a/admin/Dockerfile b/admin/Dockerfile index 0b20871..070e663 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -20,6 +20,7 @@ RUN mkdir -p /app/public COPY ./package.json /tmp RUN cd /tmp && npm install RUN cp -a /tmp/node_modules /app +RUN npm install -g nodemon WORKDIR /app COPY server /app COPY --from=build /app/build /app/public diff --git a/backend/Dockerfile b/backend/Dockerfile index 6108eff..1882353 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -22,6 +22,6 @@ RUN mkdir -p /home/app/upload && cp -a /tmp/node_modules /home/app WORKDIR $HOME/ COPY . $HOME/ - +RUN npm install -g nodemon # Run the command on container startup CMD node index.js diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 158cde7..3ffe02a 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -18,6 +18,7 @@ RUN mkdir -p /app/public COPY ./package.json /tmp RUN cd /tmp && npm install RUN cp -a /tmp/node_modules /app +RUN npm install -g nodemon WORKDIR /app COPY server /app COPY --from=build /app/build /app/public diff --git a/test-compose.yml b/test-compose.yml index 5eba8de..e2b3b83 100644 --- a/test-compose.yml +++ b/test-compose.yml @@ -17,24 +17,28 @@ services: driver: "json-file" options: tag: "backend" + command: ["nodemon", "index.js"] admin: logging: driver: "json-file" options: tag: "admin" + command: ["nodemon", "index.js"] account: logging: driver: "json-file" options: tag: "account" + command: ["nodemon", "index.js"] frontend: logging: driver: "json-file" options: tag: "frontend" + command: ["nodemon", "index.js"] networks: proxy: