diff --git a/README.md b/README.md index 8ee08f8..e3c1cdb 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,6 @@ Make sure [Docker](https://www.docker.com/get-started/) is installed and running and Node.js and npm are installed. -In the project directory, type - -```bash -npm install -``` - -This will install `node_modules`. - ## Run Before running, copy the `.env.example` into `.env` @@ -32,33 +24,6 @@ Then start the Docker containers by typing docker compose up --detach ``` -The first time Node.js might not start. - -```bash -docker logs badgehub-api-node-1 -``` - -If the logs say something like - -```text -node:internal/modules/run_main:115 - triggerUncaughtException( - ^ -Error [TransformError]: -``` - -Then node_modules have to be install from inside the container. type: - -```bash -docker exec -it badgehub-api-node-1 npm install -``` - -and restart the service: - -```bash -docker compose restart -``` - Then visit [http://localhost:8001/](http://localhost:8001/) for the development BadgeHub homepage. Visit [http://localhost:8002/](http://localhost:8002/) for the pgAdmin interface. @@ -86,6 +51,16 @@ Or, to stop BadgeHub and delete all volumes (to start fresh) docker compose down --volumes ``` +### Applying commands to only 1 container from the compose file + +Container commands like `stop`, `start`, `restart` and `logs` can also be sent to one of the containers from the compose file. For example + +```bash +docker compose restart node +``` + +will restart the node container only. + ## Database schema At the moment, this is the database schema: diff --git a/docker-compose.yml b/docker-compose.yml index e82bd20..7ccbe5f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: - .env environment: - NODE_ENV=development - command: "npm run dev" + command: "bash ./startDevForDockerCompose.sh" depends_on: - db diff --git a/package.json b/package.json index 46f7d6d..0fe4e39 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "dev": "node --import tsx --watch src/index.ts", "backup": "docker exec -it badgehub-api-db-1 /usr/bin/pg_dump --username badgehub badgehub -f /var/backup/data-backup-`date +\"%Y-%m-%dT%H:%m\"`.sql", "test": "vitest --coverage.enabled true", - "prepare": "husky install" + "prepare": "husky" }, "license": "MIT", "dependencies": { diff --git a/startDevForDockerCompose.sh b/startDevForDockerCompose.sh new file mode 100755 index 0000000..992d45b --- /dev/null +++ b/startDevForDockerCompose.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Check if node_modules directory exists +if ! ls "node_modules" >/dev/null 2>&1; then + echo "node_modules not found. Running npm ci..." + npm ci --no-audit --no-fund +else + if ! ls node_modules/@rollup/rollup-linux* >/dev/null 2>&1; then + echo "Warning! rollup does not seem to be installed correctly for docker, so we are reinstalling node_modules!" + npm ci --no-audit --no-fund + fi + echo "node_modules already exists. Skipping npm ci." +fi + +npm run dev