From dd74cca414092c49f4e39d94042525e800b86ba0 Mon Sep 17 00:00:00 2001 From: Francis Duvivier Date: Mon, 7 Oct 2024 21:11:17 +0200 Subject: [PATCH 1/4] Add installation of node modules to start in case of using docker compose --- README.md | 35 ----------------------------------- docker-compose.yml | 2 +- package.json | 2 +- startDevFromDocker.sh | 2 ++ 4 files changed, 4 insertions(+), 37 deletions(-) create mode 100755 startDevFromDocker.sh diff --git a/README.md b/README.md index 8ee08f8..a61afd4 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. diff --git a/docker-compose.yml b/docker-compose.yml index e82bd20..e4753ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: - .env environment: - NODE_ENV=development - command: "npm run dev" + command: "sh ./startDevFromDocker.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/startDevFromDocker.sh b/startDevFromDocker.sh new file mode 100755 index 0000000..3751505 --- /dev/null +++ b/startDevFromDocker.sh @@ -0,0 +1,2 @@ +npm i --no-fund --package-lock-only --no-audit &&\ +npm run dev From c7e7a3906a43ca2ca6ef42b4a0345742f6b0498e Mon Sep 17 00:00:00 2001 From: Francis Duvivier Date: Mon, 7 Oct 2024 21:20:47 +0200 Subject: [PATCH 2/4] rename to startDevForDockerCompose.sh --- docker-compose.yml | 2 +- startDevFromDocker.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100755 startDevFromDocker.sh diff --git a/docker-compose.yml b/docker-compose.yml index e4753ae..7ccbe5f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: - .env environment: - NODE_ENV=development - command: "sh ./startDevFromDocker.sh" + command: "bash ./startDevForDockerCompose.sh" depends_on: - db diff --git a/startDevFromDocker.sh b/startDevFromDocker.sh deleted file mode 100755 index 3751505..0000000 --- a/startDevFromDocker.sh +++ /dev/null @@ -1,2 +0,0 @@ -npm i --no-fund --package-lock-only --no-audit &&\ -npm run dev From 37ccee91da4d5e5fabf5b8a577d7c1e66e0dcafb Mon Sep 17 00:00:00 2001 From: Francis Duvivier Date: Mon, 7 Oct 2024 21:24:19 +0200 Subject: [PATCH 3/4] Update README.md with info regarding individual container manipulation from the compose --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index a61afd4..e3c1cdb 100644 --- a/README.md +++ b/README.md @@ -51,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: From 8936b1bc2a76ace56ff0409bd91c112e3157e940 Mon Sep 17 00:00:00 2001 From: Francis Duvivier Date: Mon, 7 Oct 2024 21:55:35 +0200 Subject: [PATCH 4/4] Fix installation in ./startDevForDockerCompose.sh and rollup bin check. --- startDevForDockerCompose.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 startDevForDockerCompose.sh 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