Skip to content

Commit 08030a6

Browse files
committed
refactoring the domains of the project into services and align with docker file
1 parent 4c5b26a commit 08030a6

254 files changed

Lines changed: 13067 additions & 13346 deletions

File tree

Some content is hidden

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

.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Dependencies (reinstalled in container)
2+
node_modules/
3+
4+
# Build output (rebuilt in container)
5+
dist/
6+
7+
# Environment and secrets (never bake into image)
8+
.env
9+
.env.*
10+
!.env.example
11+
12+
# Git and IDE
13+
.git/
14+
.gitignore
15+
.vscode/
16+
.idea/
17+
18+
# Tests and coverage (not needed in image)
19+
tests/
20+
coverage/
21+
*.test.ts
22+
vitest.config.ts
23+
24+
# Docs and misc
25+
*.md
26+
!public/**/README.md
27+
docs/
28+
.eslintrc.json
29+
eslint.config.mjs
30+
.husky/
31+
32+
# Logs and local
33+
*.log
34+
*.local

.github/workflows/ci-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151

5252
- name: Extract repo name
5353
id: repo
54-
run: echo "REPO_NAME=$(echo ${{ github.repository }} | awk -F'/' '{print $2}')" >> $GITHUB_ENV
54+
run: echo "REPO_NAME=$(echo ${{ github.repository }} | awk -F'/' '{print tolower($2)}')" >> $GITHUB_ENV
5555

5656
- name: Build and push Docker image
5757
uses: docker/build-push-action@v5

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ dist/
1717
.idea/
1818

1919
# Local files
20-
*.local
20+
*.local
21+
22+
farming-product-REST-api/docs/
23+
docs/
24+
25+
26+

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn format
4+
yarn format && yarn lint && yarn test && yarn build

Dockerfile

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1-
# Use official Node.js 20 image
1+
# ============== Stage 1: Build ==============
22
FROM node:20-alpine AS builder
33

44
WORKDIR /app
55

6-
# Copy package files first
6+
# Install deps (devDependencies needed for TypeScript build)
77
COPY package.json yarn.lock ./
88
RUN yarn install --frozen-lockfile
99

10-
# Copy source files and configs
1110
COPY . .
12-
13-
# Verify files exist
14-
RUN ls -la && \
15-
echo "Contents of tsconfig.json:" && \
16-
cat tsconfig.json
17-
18-
# Build the app
1911
RUN yarn build
2012

21-
# Production image
13+
# ============== Stage 2: Production (minimal, non-root) ==============
2214
FROM node:20-alpine AS prod
15+
16+
# Non-root user (UID/GID 1001 to avoid conflict with node:20-alpine's default 1000)
17+
RUN addgroup -g 1001 appgroup && \
18+
adduser -u 1001 -G appgroup -s /bin/sh -D appuser
19+
2320
WORKDIR /app
2421

25-
# Copy only the necessary files
26-
COPY --from=builder /app/package.json ./
27-
COPY --from=builder /app/yarn.lock ./
28-
COPY --from=builder /app/node_modules ./node_modules
22+
ENV NODE_ENV=production
23+
ENV PORT=5003
24+
# DATABASE_URL is not set in the image (secrets stay out of the build).
25+
# Pass it at runtime: docker run -e DATABASE_URL="postgresql://..." or use --env-file .env
26+
27+
# Production deps only; clean cache in same layer to avoid bloating image
28+
COPY package.json yarn.lock ./
29+
RUN yarn install --frozen-lockfile --production --ignore-optional && \
30+
yarn cache clean
31+
32+
# Copy built artifacts from builder
2933
COPY --from=builder /app/dist ./dist
3034
COPY --from=builder /app/migrations ./migrations
35+
COPY --from=builder /app/public ./public
36+
37+
# Own all app files as non-root user
38+
RUN chown -R appuser:appgroup /app
39+
40+
USER appuser
41+
42+
EXPOSE 5003
3143

32-
EXPOSE 3000
33-
CMD ["node", "dist/app.js"]
44+
CMD ["node", "dist/app.js"]

0 commit comments

Comments
 (0)