Skip to content

Commit 0c34db5

Browse files
committed
feat: production-ready post service with full test coverage and ESLint fixes
1 parent 7443541 commit 0c34db5

File tree

82 files changed

+21648
-4064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+21648
-4064
lines changed

.dockerignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,69 @@
1+
# Dependencies
12
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Coverage and testing
8+
coverage
9+
.nyc_output
10+
test
11+
**/*.spec.ts
12+
**/*.test.ts
13+
14+
# Build artifacts
15+
dist
16+
*.tgz
17+
18+
# Environment files
19+
.env
20+
.env.local
21+
.env.development
22+
.env.test
23+
.env.production
24+
25+
# IDE and editor files
26+
.vscode
27+
.idea
28+
*.swp
29+
*.swo
30+
*~
31+
32+
# OS generated files
33+
.DS_Store
34+
.DS_Store?
35+
._*
36+
.Spotlight-V100
37+
.Trashes
38+
ehthumbs.db
39+
Thumbs.db
40+
41+
# Git
42+
.git
43+
.gitignore
44+
README.md
45+
CHANGELOG.md
46+
47+
# Docker
48+
Dockerfile*
49+
docker-compose*
50+
.dockerignore
51+
52+
# Logs
53+
logs
54+
*.log
55+
56+
# Temporary files
57+
.tmp
58+
.cache
59+
60+
# Development tools
61+
eslint.config.mjs
62+
.eslintrc*
63+
.prettierrc*
64+
.husky
65+
lint-staged
66+
67+
# Documentation
68+
docs
69+
*.md

.env.docker

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# App
2-
APP_NAME=@backendworks/post
3-
APP_ENV=development
4-
APP_CORS_ORIGINS=*
1+
NODE_ENV="local"
2+
3+
APP_NAME="@backendworks/post"
4+
APP_CORS_ORIGINS="*"
55
APP_DEBUG=true
6-
APP_LOG_LEVEL=debug
76

8-
# HTTP
97
HTTP_ENABLE=true
10-
HTTP_HOST=0.0.0.0
8+
HTTP_HOST="0.0.0.0"
119
HTTP_PORT=9002
1210
HTTP_VERSIONING_ENABLE=true
1311
HTTP_VERSION=1
1412

15-
# Kafka
16-
KAFKA_BROKERS=kafka:9092
17-
KAFKA_CLIENT_ID=post_service
18-
KAFKA_CONSUMER_GROUP=post_service_group
19-
KAFKA_ADMIN_CLIENT_ID=bw_admin
20-
KAFKAJS_NO_PARTITIONER_WARNING=1
13+
SENTRY_DSN=""
14+
15+
DATABASE_URL="postgresql://admin:master123@postgres:5432/postgres?schema=public"
2116

22-
# Monitoring
23-
SENTRY_DSN=
17+
ACCESS_TOKEN_SECRET_KEY="EAJYjNJUnRGJ6uq1YfGw4NG1pd1z102J"
18+
ACCESS_TOKEN_EXPIRED="1d"
19+
REFRESH_TOKEN_SECRET_KEY="LcnlpiuHIJ6eS51u1mcOdk0P49r2Crwu"
20+
REFRESH_TOKEN_EXPIRED="7d"
2421

25-
# Database
26-
DATABASE_URL=postgresql://postgres:master123@postgres:5432/postgres?schema=post
22+
REDIS_URL="redis://redis:6379"
23+
REDIS_KEY_PREFIX="post:"
24+
REDIS_TTL=3600
2725

28-
# Redis
29-
REDIS_URL=redis://redis:6379
26+
GRPC_URL="0.0.0.0:50052"
27+
GRPC_PACKAGE="post"
28+
GRPC_AUTH_URL="0.0.0.0:50051"
29+
GRPC_AUTH_PACKAGE="auth"

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI (post)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- name: Install dependencies
22+
run: npm install --legacy-peer-deps
23+
working-directory: .
24+
- name: Run lint
25+
run: |
26+
if [ -f eslint.config.mjs ]; then
27+
npx eslint .
28+
fi
29+
working-directory: .
30+
- name: Run tests
31+
run: npm test
32+
working-directory: .

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ lerna-debug.log*
3333
!.vscode/tasks.json
3434
!.vscode/launch.json
3535
!.vscode/extensions.json
36-
3736
.env
38-
!.env.docker
37+

.prettierrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"singleQuote": true,
33
"trailingComma": "all",
4+
"semi": true,
5+
"printWidth": 100,
6+
"tabWidth": 4,
47
"useTabs": false,
5-
"tabWidth": 4
8+
"bracketSpacing": true,
9+
"bracketSameLine": false,
10+
"arrowParens": "avoid",
11+
"endOfLine": "lf"
612
}

Dockerfile

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
1-
FROM node:lts-alpine
1+
# Multi-stage build for optimal image size
2+
FROM node:lts-alpine AS base
23

4+
# Install dependencies only when needed
5+
FROM base AS deps
6+
RUN apk add --no-cache libc6-compat wget openssl
37
WORKDIR /app
48

5-
COPY package.json yarn.lock ./
6-
COPY prisma ./prisma
9+
# Copy package files
10+
COPY package.json yarn.lock* ./
11+
COPY prisma ./prisma/
712

8-
RUN yarn install --frozen-lockfile
13+
# Install dependencies
14+
RUN yarn --frozen-lockfile --production=false
915

16+
# Build the source code
17+
FROM base AS builder
18+
RUN apk add --no-cache wget openssl
19+
WORKDIR /app
20+
COPY --from=deps /app/node_modules ./node_modules
1021
COPY . .
1122

12-
EXPOSE 9002
23+
# Generate Prisma client and build application
24+
RUN yarn prisma:generate
25+
RUN yarn proto:generate
26+
RUN yarn build
27+
28+
# Production image, copy all the files and run the app
29+
FROM base AS runner
30+
RUN apk add --no-cache wget openssl
31+
WORKDIR /app
32+
33+
# Create non-root user for security
34+
RUN addgroup --system --gid 1001 nodejs
35+
RUN adduser --system --uid 1001 nestjs
36+
37+
# Copy necessary files from builder stage
38+
COPY --from=builder /app/dist ./dist
39+
COPY --from=builder /app/prisma ./prisma
40+
COPY --from=builder /app/src/protos ./src/protos
41+
COPY --from=builder /app/package.json ./package.json
42+
COPY --from=builder /app/yarn.lock ./yarn.lock
43+
44+
# Copy node_modules from deps stage (production only)
45+
COPY --from=deps /app/node_modules ./node_modules
46+
47+
# Change ownership to nestjs user
48+
RUN chown -R nestjs:nodejs /app
49+
USER nestjs
50+
51+
# Expose ports for HTTP and gRPC
52+
EXPOSE 9002 50052
1353

14-
CMD [ "yarn", "dev" ]
54+
CMD ["yarn", "start"]

0 commit comments

Comments
 (0)