Skip to content
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
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,52 @@ The best place to search for answers is our [Documentation](https://jetkvm.com/d

If you've found an issue and want to report it, please check our [Issues](https://github.com/jetkvm/cloud-api/issues) page. Make sure the description contains information about the firmware version you're using, your platform, and a clear explanation of the steps to reproduce the issue.


## Development

This project is built on Node.JS using Prisma and Express.

To start the development server, run:
This project is built with Node.js, Prisma, and Express.

```bash
# For local development, you can use the following command to start a postgres instanc
# Don't use in production
docker run --name jetkvm-cloud-db \
-e POSTGRES_USER=jetkvm \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=jetkvm \
-d postgres

# Copy the .env.example file to .env and populate it with the correct values
# Start the database
docker compose -f compose.development.yaml up -d

# Copy and configure environment variables
cp .env.example .env

# Install dependencies
npm install

# Deploy the existing database migrations
npx prisma migrate deploy
# Run database migrations
npm run prisma-dev-migrate

# Start the production server on port 3000
# Seed development data (optional)
npm run seed

# Start the development server with hot reload
npm run dev

# Run tests
npm test
```

## Production
## Self-Hosting

For self-hosting, use the default compose file which runs the complete stack:

```bash
# Copy the .env.example file to .env and populate it with the correct values
# Copy and configure environment variables
cp .env.example .env

# Install dependencies
npm install
# Start everything (database, migrations, and app)
docker compose up -d
```

The app will be available on port 3000. Configure a reverse proxy (nginx, Caddy, etc.) for TLS termination.

# Deploy the existing database migrations
# Needs to run on new release
npx prisma migrate deploy
### Updating

# Start the production server on port 3000
npm run start
```bash
git pull
docker compose up -d --build
```

Database migrations run automatically on startup.
24 changes: 24 additions & 0 deletions compose.development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: jetkvm-cloud-api-dev

services:
db:
image: postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: jetkvm
POSTGRES_USER: jetkvm
POSTGRES_DB: jetkvm
healthcheck:
test: ["CMD-SHELL", "pg_isready -U jetkvm -d jetkvm"]
interval: 5s
timeout: 5s
retries: 10
start_period: 5s
ports:
- "5432:5432"
volumes:
- postgresql:/var/lib/postgresql

volumes:
postgresql:
driver: local
32 changes: 20 additions & 12 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ networks:
services:
db:
image: postgres
restart: always
restart: unless-stopped
environment:
POSTGRES_PASSWORD: jetkvm
POSTGRES_USER: jetkvm
Expand All @@ -25,27 +25,35 @@ services:
volumes:
- postgresql:/var/lib/postgresql

app: &app
# Run database migrations before starting the apps
app-migrate:
build: .
environment:
PORT: 5172
DATABASE_URL: postgres://jetkvm:jetkvm@db:5432/jetkvm
depends_on:
db:
condition: service_healthy
ports:
- "5172:5172"
command: ["sh", "-c", "npx prisma migrate deploy"]
networks:
- jetkvm

# Trigger prisma migration
# This can be done in the app container as well, but is generally discouraged.
app-migrate:
<<: *app
command: ["sh", "-c", "npx prisma generate && npx prisma migrate deploy"]
ports: []
restart: no

app:
build: .
restart: unless-stopped
environment:
PORT: 3000
DATABASE_URL: postgres://jetkvm:jetkvm@db:5432/jetkvm
depends_on:
db:
condition: service_healthy
app-migrate:
condition: service_completed_successfully
ports:
- "3000:3000"
networks:
- jetkvm

volumes:
postgresql:
driver: local
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"prisma-dev": "prisma generate --watch",
"prisma-dev-migrate": "prisma migrate dev",
"prisma-migrate": "prisma migrate deploy",
"seed": "NODE_ENV=development node -r ts-node/register --env-file=.env.development ./scripts/seed.ts",
"build": "tsc",
"test": "vitest run",
"test:watch": "vitest",
Expand Down
Loading