Skip to content

Commit 6e10356

Browse files
feat(Docker): Added Docker file + compose for local dev
1 parent e9191d7 commit 6e10356

File tree

7 files changed

+107
-8
lines changed

7 files changed

+107
-8
lines changed

.devcontainer/devcontainer.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "JetKVM Cloud API",
3+
"image": "mcr.microsoft.com/devcontainers/base:debian",
4+
"features": {
5+
"ghcr.io/devcontainers/features/node:1": {
6+
"version": "21.1.0"
7+
}
8+
}
9+
}

.env.example

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DATABASE_URL="postgresql://jetkvm:jetkvm@localhost:5432/jetkvm?schema=public"
1+
DATABASE_URL="postgresql://jetkvm:mysecretpassword@localhost:5432/jetkvm?schema=public"
22

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

2222
REAL_IP_HEADER=XXX # Real IP Header for the reverse proxy (e.g. X-Real-IP), leave empty if not needed
23-
ICE_SERVERS=XXX # ICE Servers for WebRTC, split by comma (e.g. stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302)
23+
ICE_SERVERS=XXX # ICE Servers for WebRTC, split by comma (e.g. stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302)
24+
25+
# Uncomment these for development
26+
#POSTGRES_USER=jetkvm
27+
#POSTGRES_PASSWORD=mysecretpassword
28+
#POSTGRES_DB=jetkvm

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.idea
3-
.env
3+
.env
4+
.env.development

Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:21.1.0
2+
3+
WORKDIR /app
4+
5+
# Define NODE_ENV as a build argument with a default value
6+
ARG NODE_ENV=production
7+
ENV NODE_ENV=${NODE_ENV}
8+
9+
COPY package.json package-lock.json ./
10+
11+
# Install dependencies
12+
RUN npm install
13+
14+
# copy schemas and generate client
15+
COPY prisma ./prisma
16+
RUN npx prisma generate
17+
18+
COPY . .
19+
20+
EXPOSE 3000
21+
22+
# migrate schemas, then start app
23+
CMD npx prisma migrate deploy && exec node -r ts-node/register ./src/index.ts

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,32 @@ The best place to search for answers is our [Documentation](https://jetkvm.com/d
2323

2424
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.
2525

26-
2726
## Development
2827

2928
This project is built with Node.JS, Prisma and Express.
3029

3130
To start the development server, run:
3231

3332
```bash
34-
# For local development, you can use the following command to start a postgres instanc
33+
# Copy the .env.example file to a new file .env.development and populate it with the correct values
34+
cp .env.example .env.development
35+
36+
# For local development you can use docker compose to bring up your environment
37+
38+
# this will run docker-compose.yml with docker-compose.override.yml applied
39+
40+
docker compose up --build
41+
42+
# Or you can run a postgres container only
43+
3544
# Don't use in production
3645
docker run --name jetkvm-cloud-db \
3746
-e POSTGRES_USER=jetkvm \
3847
-e POSTGRES_PASSWORD=mysecretpassword \
3948
-e POSTGRES_DB=jetkvm \
49+
-p 5432:5432 \
4050
-d postgres
4151

42-
# Copy the .env.example file to .env and populate it with the correct values
43-
cp .env.example .env
44-
4552
# Install dependencies
4653
npm install
4754

docker-compose.override.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
args:
7+
NODE_ENV: development
8+
ports:
9+
- "3000:3000"
10+
env_file:
11+
- .env.development
12+
depends_on:
13+
- postgres
14+
volumes:
15+
- .:/app
16+
- /app/node_modules
17+
command: ["sh", "-c", "npm install && npx prisma migrate dev && npm run dev"]
18+
19+
postgres:
20+
env_file:
21+
- .env.development

docker-compose.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
postgres:
3+
image: postgres:15
4+
restart: always
5+
env_file:
6+
- .env
7+
ports:
8+
- "5432:5432"
9+
volumes:
10+
- pgdata:/var/lib/postgresql/data
11+
healthcheck:
12+
test: ["CMD-SHELL", "pg_isready -U jetkvm"]
13+
interval: 5s
14+
retries: 5
15+
timeout: 3s
16+
17+
app:
18+
build:
19+
context: .
20+
dockerfile: Dockerfile
21+
args:
22+
NODE_ENV: production
23+
env_file:
24+
- .env
25+
depends_on:
26+
postgres:
27+
condition: service_healthy
28+
expose:
29+
- "3000:3000"
30+
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"]
31+
32+
volumes:
33+
pgdata:

0 commit comments

Comments
 (0)