Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startDevForDockerCompose.sh and use it in docker compose for auto npm install #14

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- .env
environment:
- NODE_ENV=development
command: "npm run dev"
command: "bash ./startDevForDockerCompose.sh"
depends_on:
- db

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install command is apparently deprecated, just husky does the job

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct.

"prepare": "husky"
},
"license": "MIT",
"dependencies": {
Expand Down
15 changes: 15 additions & 0 deletions startDevForDockerCompose.sh
Original file line number Diff line number Diff line change
@@ -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