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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
.env.example
dist/
ignore/
node_modules/*
12 changes: 12 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# For Docker
# Paste all this in your .env file and run it with docker-compose up -d

DATABASE_URL="postgresql://postgres:postgres@postgres:5432/postgres"
JWT_SECRET="secretjwt"
API_PORT=3000
POSTGRES_PORT=5432
POSTGRES_PATH=postgres-data
POSTGRES_HOST=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
STRIPE_SK_KEY=<YOUR STRIPE SK KEY>
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dist/
ignore/
prisma/data
.env
.env.*
! .env.example
.vscode
node_modules
17 changes: 0 additions & 17 deletions Dockerfile

This file was deleted.

27 changes: 27 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Stage 1: Installer Stage
FROM node:22-alpine3.20 AS installer

WORKDIR /usr/src/app

RUN corepack enable && corepack prepare pnpm@9.5.0 --activate
COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma

RUN apk add --no-cache make gcc g++ python3 && \
if [ -f pnpm-lock.yaml ]; then \
pnpm install --frozen-lockfile --ignore-scripts; \
else \
echo "pnpm-lock.yaml not found" && exit 1; \
fi && \
npm rebuild bcrypt --build-from-source && \
apk del make gcc g++ python3

COPY . .

# Stage 2: Development Stage
FROM node:22-alpine3.20 AS development

WORKDIR /usr/src/app
RUN corepack enable && corepack prepare pnpm@9.5.0 --activate
COPY --from=installer /usr/src/app/ ./
CMD ["pnpm", "run", "dev:docker"]
32 changes: 32 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Stage 1: Builder Stage
FROM node:22-alpine3.20 AS builder
WORKDIR /usr/src/app

RUN corepack enable && corepack prepare pnpm@9.5.0 --activate

COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma

RUN apk add --no-cache make gcc g++ python3 && \
if [ -f pnpm-lock.yaml ]; then \
pnpm install --frozen-lockfile --ignore-scripts; \
else \
echo "pnpm-lock.yaml not found" && exit 1; \
fi && \
npm rebuild bcrypt --build-from-source && \
apk del make gcc g++ python3

COPY . .

RUN DATABASE_URL=$DATABASE_URL pnpm run build

# Stage 2: Production Stage
FROM node:22-alpine3.20 AS production
WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules/ ./node_modules

EXPOSE 3000

CMD [ "node", "dist/index.js" ]
51 changes: 28 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
# docker-compose.yml

# THIS IS BROKEN RN

version: "3.9"
services:
postgres:
image: postgres:latest
environment:
POSTGRES_USER: jasper
POSTGRES_PASSWORD: jasper
ports:
- '5432:5432'
volumes:
- db:/var/lib/postgresql/data

api:
container_name: api-docker
build:
context: .
environment:
DB_SCHEMA: postgres
DB_USER: postgres
DB_PASSWORD: postgres
DB_HOST: postgres
dockerfile: Dockerfile.dev
env_file:
- .env
ports:
- ${API_PORT}:3000
depends_on:
- postgres
postgres:
condition: service_healthy
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules

postgres:
container_name: prisma-postgres
image: postgres:alpine
restart: always
env_file:
- .env
ports:
- '3000:3000'
- ${POSTGRES_PORT}:5432
volumes:
- ${POSTGRES_PATH}:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5

volumes:
db:
postgres-data:
external: false
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"packageManager": "pnpm@9.5.0",
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "node dist/index.js",
"postinstall": "npx prisma generate && tsc",
"watch-node": "nodemon dist/index.js",
Expand All @@ -22,7 +23,9 @@
"heroku-prebuild": "echo This runs before Heroku installs dependencies.",
"heroku-postbuild": "echo This runs after Heroku installs dependencies, but before Heroku prunes and caches dependencies.",
"heroku-cleanup": "echo This runs after Heroku prunes and caches dependencies.",
"prepare": "husky"
"prepare": "husky",
"prisma:docker": "npx prisma generate && npx prisma migrate dev",
"dev:docker": "pnpm prisma:docker && pnpm dev"
},
"keywords": [],
"author": "Jasper Mayone <me@jaspermayone.com>",
Expand All @@ -42,7 +45,8 @@
"puppeteer": "^22.15.0",
"request-ip": "^3.3.0",
"response-time": "^2.3.2",
"stripe": "^16.8.0"
"stripe": "^16.8.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand Down
Loading