Skip to content

Commit 427d3c8

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

8 files changed

+155
-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+
}

.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
.github
3+
.env*
4+
.prettierrc
5+
.gitignore
6+
.dockerignore
7+
*.md
8+
Dockerfile
9+
node_modules
10+
publish_source.sh

.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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM node:21.1.0-alpine AS base
2+
3+
ARG NODE_ENV=production
4+
ENV NODE_ENV=${NODE_ENV}
5+
6+
WORKDIR /app
7+
8+
RUN apk add --no-cache libc6-compat
9+
10+
COPY package.json package-lock.json ./
11+
12+
# Development Stage
13+
FROM base AS dev
14+
15+
RUN npm install
16+
17+
COPY . .
18+
19+
RUN npx prisma generate
20+
21+
RUN chown -R node:node /app
22+
23+
USER node
24+
25+
EXPOSE 3000
26+
27+
# Run development server
28+
CMD ["sh", "-c", "npx prisma migrate dev && npm run dev"]
29+
30+
#Production Stage
31+
FROM base AS prod
32+
33+
ENV NODE_ENV=production
34+
35+
RUN npm ci --omit=dev
36+
37+
COPY --from=dev /app/node_modules ./node_modules
38+
COPY --from=dev /app/prisma ./prisma
39+
COPY --from=dev /app/src ./src
40+
COPY --from=dev /app/package.json ./
41+
42+
RUN npx prisma generate
43+
44+
RUN chown -R node:node /app
45+
46+
USER node
47+
48+
EXPOSE 3000
49+
50+
# Run Prisma migrations & start the app in production mode
51+
CMD ["sh", "-c", "npx prisma migrate deploy && exec npm run start"]
52+

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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
target: dev
7+
args:
8+
NODE_ENV: development
9+
ports:
10+
- "3000:3000"
11+
env_file:
12+
- .env.development
13+
depends_on:
14+
- postgres
15+
volumes:
16+
- .:/app
17+
command: ["sh", "-c", "npm install && npx prisma migrate dev && npm run dev"]
18+
develop:
19+
watch:
20+
- action: sync
21+
path: ./src
22+
target: /app/src
23+
ignore:
24+
- node_modules/
25+
- action: rebuild
26+
path: package.json
27+
28+
postgres:
29+
env_file:
30+
- .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)