-
Notifications
You must be signed in to change notification settings - Fork 0
Chore/align dockerfile #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Dependencies (reinstalled in container) | ||
| node_modules/ | ||
|
|
||
| # Build output (rebuilt in container) | ||
| dist/ | ||
|
|
||
| # Environment and secrets (never bake into image) | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
|
|
||
| # Git and IDE | ||
| .git/ | ||
| .gitignore | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| # Tests and coverage (not needed in image) | ||
| tests/ | ||
| coverage/ | ||
| *.test.ts | ||
| vitest.config.ts | ||
|
|
||
| # Docs and misc | ||
| *.md | ||
| !public/**/README.md | ||
| docs/ | ||
| .eslintrc.json | ||
| eslint.config.mjs | ||
| .husky/ | ||
|
|
||
| # Logs and local | ||
| *.log | ||
| *.local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,10 @@ dist/ | |
| .idea/ | ||
|
|
||
| # Local files | ||
| *.local | ||
| *.local | ||
|
|
||
| farming-product-REST-api/docs/ | ||
| docs/ | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/sh | ||
| . "$(dirname "$0")/_/husky.sh" | ||
|
|
||
| yarn format | ||
| yarn format && yarn lint && yarn test && yarn build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,44 @@ | ||
| # Use official Node.js 20 image | ||
| # ============== Stage 1: Build ============== | ||
| FROM node:20-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy package files first | ||
| # Install deps (devDependencies needed for TypeScript build) | ||
| COPY package.json yarn.lock ./ | ||
| RUN yarn install --frozen-lockfile | ||
|
|
||
| # Copy source files and configs | ||
| COPY . . | ||
|
|
||
| # Verify files exist | ||
| RUN ls -la && \ | ||
| echo "Contents of tsconfig.json:" && \ | ||
| cat tsconfig.json | ||
|
|
||
| # Build the app | ||
| RUN yarn build | ||
|
|
||
| # Production image | ||
| # ============== Stage 2: Production (minimal, non-root) ============== | ||
| FROM node:20-alpine AS prod | ||
|
|
||
| # Non-root user (UID/GID 1001 to avoid conflict with node:20-alpine's default 1000) | ||
| RUN addgroup -g 1001 appgroup && \ | ||
| adduser -u 1001 -G appgroup -s /bin/sh -D appuser | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy only the necessary files | ||
| COPY --from=builder /app/package.json ./ | ||
| COPY --from=builder /app/yarn.lock ./ | ||
| COPY --from=builder /app/node_modules ./node_modules | ||
| ENV NODE_ENV=production | ||
| ENV PORT=5003 | ||
| # DATABASE_URL is not set in the image (secrets stay out of the build). | ||
| # Pass it at runtime: docker run -e DATABASE_URL="postgresql://..." or use --env-file .env | ||
|
|
||
| # Production deps only; clean cache in same layer to avoid bloating image | ||
| COPY package.json yarn.lock ./ | ||
| RUN yarn install --frozen-lockfile --production --ignore-optional && \ | ||
| yarn cache clean | ||
|
|
||
| # Copy built artifacts from builder | ||
| COPY --from=builder /app/dist ./dist | ||
| COPY --from=builder /app/migrations ./migrations | ||
| COPY --from=builder /app/public ./public | ||
|
|
||
| # Own all app files as non-root user | ||
| RUN chown -R appuser:appgroup /app | ||
|
|
||
| USER appuser | ||
|
|
||
| EXPOSE 5003 | ||
|
|
||
| EXPOSE 3000 | ||
| CMD ["node", "dist/app.js"] | ||
| CMD ["node", "dist/app.js"] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docker port mismatch breaks container networking
High Severity
The
DockerfilesetsENV PORT=5003andEXPOSE 5003, butapp.tsdefaults to port5002, theREADME.mddocumentsdocker run -p 5002:5002, and the Swagger config hardcodeshttp://localhost:5002/api/v2. When running in Docker, the app listens on 5003 inside the container, but users following the README map host port 5002 to container port 5002 — where nothing is listening — so the container is unreachable.Additional Locations (2)
README.md#L99-L104app.ts#L16-L17