Skip to content
Open
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
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "JetKVM Cloud API",
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "21.1.0"
}
}
}
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.github
.env*
.prettierrc
.gitignore
.dockerignore
*.md
Dockerfile
node_modules
publish_source.sh
9 changes: 7 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL="postgresql://jetkvm:jetkvm@localhost:5432/jetkvm?schema=public"
DATABASE_URL="postgresql://jetkvm:mysecretpassword@localhost:5432/jetkvm?schema=public" # hostname is postgres for docker development

GOOGLE_CLIENT_ID=XXX # Google OIDC Client ID
GOOGLE_CLIENT_SECRET=XXX # Google OIDC Client Secret
Expand All @@ -20,4 +20,9 @@ R2_CDN_URL=XXX # Any S3 compatible CDN URL
CORS_ORIGINS=https://app.jetkvm.com,http://localhost:5173 # Allowed CORS Origins, split by comma

REAL_IP_HEADER=XXX # Real IP Header for the reverse proxy (e.g. X-Real-IP), leave empty if not needed
ICE_SERVERS=XXX # ICE Servers for WebRTC, split by comma (e.g. stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302)
ICE_SERVERS=XXX # ICE Servers for WebRTC, split by comma (e.g. stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302)

# Uncomment these for development
#POSTGRES_USER=jetkvm
#POSTGRES_PASSWORD=mysecretpassword
#POSTGRES_DB=jetkvm
24 changes: 23 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
.env
.env.development

logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

.vscode/*
!.vscode/extensions.json
.idea
.env
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Base Stage
FROM node:22.14.0-bullseye-slim AS base
WORKDIR /app
COPY package.json package-lock.json ./

# Deps Stage
FROM base AS deps
RUN npm ci

# Build / Dev Stage
FROM deps AS dev
COPY . .
RUN npx prisma generate
RUN npm run build:prod
CMD ["sh", "-c", "npm run dev"]

# Production Stage
FROM node:22.14.0-bullseye-slim AS prod
WORKDIR /app
COPY --from=dev /app/dist ./dist
COPY --from=dev /app/prisma ./prisma
COPY --from=dev /app/package.json ./
COPY --from=dev /app/package-lock.json ./

# Install only production dependencies
RUN npm ci --omit=dev
USER node
EXPOSE 3000
CMD ["node", "./dist/index.js"]
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,32 @@ 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 with Node.JS, Prisma and Express.

To start the development server, run:

```bash
# For local development, you can use the following command to start a postgres instanc
# Copy the .env.example file to a new file .env.development and populate it with the correct values
cp .env.example .env.development

# For local development you can use docker compose to bring up your environment

# this will run docker-compose.yml with docker-compose.override.yml applied

docker compose up --build

# Or you can run a postgres container only

# Don't use in production
docker run --name jetkvm-cloud-db \
-e POSTGRES_USER=jetkvm \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=jetkvm \
-p 5432:5432 \
-d postgres

# Copy the .env.example file to .env and populate it with the correct values
cp .env.example .env

# Install dependencies
npm install

Expand Down
30 changes: 30 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
target: dev
args:
NODE_ENV: development
ports:
- "3000:3000"
env_file:
- .env.development
depends_on:
- postgres
volumes:
- .:/app
command: ["sh", "-c", "npm install && npm run dev"]
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- node_modules/
- action: rebuild
path: package.json

postgres:
env_file:
- .env.development
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
postgres: # be sure to update DATABASE_URL with this hostname
image: postgres:15
restart: always
env_file:
- .env
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U jetkvm"]
interval: 5s
retries: 5
timeout: 3s

app:
build:
context: .
dockerfile: Dockerfile
args:
NODE_ENV: production
env_file:
- .env
depends_on:
postgres:
condition: service_healthy
expose:
- "3000:3000"
command: ["sh", "-c", "until pg_isready -h postgres -U jetkvm; do sleep 2; done && npx prisma migrate deploy && exec node -r ts-node/register ./src/index.ts"]

volumes:
pgdata:
Loading