Skip to content

Commit

Permalink
fix: Vite now listens on port 9229 in container
Browse files Browse the repository at this point in the history
There seemed to be some issue when Vite was launched as a background
process (with `&` in the shell). When this was done, Vite would not
listen on port 9229; it would detect that port being taken and listen on
9230 instead.

To fix this, modify the docker-compose file so the development server is
given its own service.
  • Loading branch information
hyperupcall committed May 19, 2023
1 parent 9455185 commit eb0f709
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.yaml,*.yml]
indent_style = tab
indent_style = space
indent_size = 2
22 changes: 18 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ services:
# Uncomment the above lines to enable access to the PostgreSQL server
# from the host machine.
# Web service runs Node
dev-server:
# Comment out the this service for production
build:
context: ./
dockerfile: ./containers/web/Dockerfile
# Using a volume allows autorebuild to work.
volumes:
- ./:/usr/src/app
ports:
- "9229:9229"
depends_on:
- web
command:
[
"bash",
"./src/scripts/devStartVite.sh",
"${install_args:-}"
]
web:
# Configuration variables for the app.
environment:
Expand Down Expand Up @@ -56,16 +74,12 @@ services:
links:
- database
# Load the source code into the container.
# Using a volume allows autorebuild to work.
volumes:
- ./:/usr/src/app
# List ports the container should expose
# For production you might want to add "80:3000" in place of the "3000:3000" line below
ports:
- "3000:3000"
- "9229:9229" # Development port; should be commented out for production
- "9230:9230"

depends_on:
# Don't bring this up without the DB
- database
Expand Down
18 changes: 18 additions & 0 deletions src/scripts/devStartVite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# *
# * This Source Code Form is subject to the terms of the Mozilla Public
# * License, v. 2.0. If a copy of the MPL was not distributed with this
# * file, You can obtain one at http://mozilla.org/MPL/2.0/.
# *

# If we're in a container, pass '--host' flag so server remains
# accessible outside the container.
extra_args=
if [ -f /.dockerenv ]; then
# This is passed to vite, which exposts the port to the
# host (outside the container)
extra_args="--host"
fi

npm run client:dev -- $extra_args
10 changes: 0 additions & 10 deletions src/scripts/devstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@
# * file, You can obtain one at http://mozilla.org/MPL/2.0/.
# *

# If we're in a container, pass '--host' flag so server remains
# accessible outside the container.
extra_args=
if [ -f /.dockerenv ]; then
# This is passed to vite, which exposts the port to the
# host (outside the container)
extra_args="--host"
fi

# This script is mostly for use in containerized environments,
# but there's no reason not to use it in non-container ones.
# It starts the autorebuild in the background and then
# runs the server.
npm run vite:dev -- $extra_args &
npm run start:dev

0 comments on commit eb0f709

Please sign in to comment.