#Build never finish

43 messages · Page 1 of 1 (latest)

flat drift
#

running the command

nest build

never finishes
I'm using docker to build the api this is my docker config .

FROM node:16 as deps-installer
WORKDIR /usr/src/app/api
COPY package.json /usr/src/app/api/
COPY yarn.lock /usr/src/app/api/
RUN yarn install --legacy-peer-deps
#######  install the project ####### 

#######  development target ####### 
FROM deps-installer as development
CMD ["yarn", "start:dev"]
 
#######  builder target ####### 
FROM deps-installer as builder

WORKDIR /usr/src/app/api/
COPY . .
RUN yarn build

####### prod target ####### 
FROM node:16 as production
WORKDIR /usr/src/app/api/
COPY --from=builder /usr/src/app/api/tsconfig*.json ./
COPY --from=builder /usr/src/app/api/node_modules ./node_modules
COPY --from=builder /usr/src/app/api/package*.json ./
COPY --from=builder /usr/src/app/api/src/migrations ./src/migrations
COPY --from=builder /usr/src/app/api/dist ./dist
COPY --from=builder /usr/src/app/api/yarn.lock ./
EXPOSE 3000
CMD ["yarn", "start:prod"]```
#

my pacakge.json

  "name": "api",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
"scripts":{
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node --max-old-space-size=4096 dist/main.js",
},
"dependencies": {
    "@nestjs-modules/mailer": "^1.8.1",
    "@nestjs/axios": "^1.0.0",
    "@nestjs/common": "^9.2.1",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.2.1",
    "@nestjs/jwt": "^9.0.0",
    "@nestjs/passport": "^9.0.0",
    "@nestjs/platform-express": "^9.2.1",
    "@nestjs/platform-socket.io": "^9.2.1",
    "@nestjs/schedule": "^2.1.0",
    "@nestjs/sequelize": "^9.0.0",
    "@nestjs/serve-static": "^3.0.0",
    "@nestjs/swagger": "^6.1.4",
    "@nestjs/typeorm": "^9.0.1",
    "@nestjs/websockets": "^9.2.1",
    "bcrypt": "^5.1.0",
    "body-parser": "^1.20.1",
    "browser-image-compression": "^2.0.0",
    "cache-manager": "^5.1.4",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "cookie": "^0.5.0",
    "cookie-parser": "^1.4.6",
    "dotenv": "^16.0.3",
    "etag": "^1.8.1",
    "handlebars": "^4.7.7",
    "helmet": "^6.0.1",
    "lodash": "^4.17.21",
    "multer": "^1.4.4",
    "mv": "^2.1.1",
    "nestjs-typeorm-paginate": "^4.0.3",
    "nodemailer": "^6.8.0",
    "passport": "0.6.0",
    "passport-headerapikey": "^1.2.2",
    "passport-jwt": "^4.0.1",
    "passport-local": "^1.0.0",
    "pg": "^8.8.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.8.0",
    "swagger-ui-express": "^4.6.0",
    "typeorm": "^0.3.11",
    "uuid": "^9.0.0",
    "xlsx": "^0.18.5",
    "xml-js": "^1.6.11"
  }
#
  "devDependencies": {
    "@nestjs/cli": "^9.1.5",
    "@nestjs/schematics": "^9.0.3",
    "@nestjs/testing": "^9.2.1",
    "@types/bcrypt": "^5.0.0",
    "@types/cache-manager": "^4.0.2",
    "@types/cookie": "^0.5.1",
    "@types/cookie-parser": "^1.4.3",
    "@types/cron": "^2.0.0",
    "@types/etag": "^1.8.1",
    "@types/express": "^4.17.14",
    "@types/fs-extra": "^9.0.13",
    "@types/jest": "^29.2.4",
    "@types/lodash": "^4.14.191",
    "@types/multer": "^1.4.7",
    "@types/mv": "^2.1.2",
    "@types/node": "^18.11.11",
    "@types/nodemailer": "^6.4.7",
    "@types/passport": "^1.0.11",
    "@types/passport-http": "^0.3.9",
    "@types/passport-jwt": "^3.0.8",
    "@types/passport-local": "^1.0.34",
    "@types/sequelize": "^4.28.14",
    "@types/supertest": "^2.0.12",
    "@types/uuid": "^9.0.0",
    "@types/ws": "^8.5.3",
    "@typescript-eslint/eslint-plugin": "^5.46.0",
    "@typescript-eslint/parser": "^5.46.0",
    "eslint": "^8.29.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "^29.3.1",
    "nodemon": "^2.0.20",
    "prettier": "^2.8.1",
    "supertest": "^6.3.3",
    "ts-jest": "^29.0.3",
    "ts-loader": "^9.4.2",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.1.1",
    "typescript": "^4.9.4"
  }
analog musk
flat drift
# analog musk There's no need to copy the `node_modules` and typescript configuration files fr...
FROM node:18-alpine As development

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm ci
COPY . .

# BUILD FOR PRODUCTION

FROM node:18-alpine As build

WORKDIR /usr/src/app

COPY package*.json ./
COPY --from=development /usr/src/app/node_modules ./node_modules
COPY . .
RUN npm run build
ENV NODE_ENV production
RUN npm ci --only=production && npm cache clean --force

FROM node:18-alpine As production

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

EXPOSE 3000
CMD [ "node", "dist/main.js" ]

this is more simple i think.

analog musk
#

you're still copying the node_modules directory between the stages which is wrong

flat drift
analog musk
# flat drift what is the proper way ? .. i'e been looking for the most efficnent way to buil...
FROM node:18-slim as base

##################################
# Dev dependencies stage, only prepares node_modules, that are later reused
##################################

FROM base as devdependencies
USER node
WORKDIR /app
COPY --chown=node:node package.json yarn.lock ./

RUN yarn install

##################################
# Build stage, creates a /app/dist directory with the compiled app.
# We don't use this stage as production, because it needs dev dependencies for the build, but we don't
# need these to actually run the compiled app
##################################

FROM base as build

USER node
WORKDIR /app

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

COPY --chown=node:node --from=devdependencies /app .
COPY --chown=node:node . .

RUN yarn run build && ls -lah dist

##################################
# Production stage
# - installs only production dependencies (no devDependencies)
#      - this is achieved by setting NODE_ENV=production
# - copies the dist directory from build stage
# - sets default NODE_ENV to production
# - exposes $PORT (3000)
# - sets propper PATH
##################################

FROM base as production

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG PORT=3000
ENV PORT $PORT
EXPOSE $PORT

USER node
WORKDIR /app

COPY --chown=node:node package.json yarn.lock ./

# Install only production dependencies
RUN yarn install && yarn cache clean && (rm -rf /tmp/* || true)

ENV PATH /app/node_modules/.bin:$PATH

COPY --chown=node:node --from=build /app/dist ./dist

CMD [ "yarn", "start:prod" ]
flat drift
#

as for docker-compose.prod.yml

version: "3.1"

services:
  ke-api:
    container_name: ke-api
    restart: always
    networks:
      - ke-network
    build:
      target: production
      context: .
      dockerfile: DockerFile
    ports:
      - 3000:3000
    env_file:
      - .env
    volumes:
      - .:/usr/src/app
      - ./static:/usr/src/app/static

networks:
  ke-network:
    external: true

do i need to make any changes ?

analog musk
#
volumes:
- - .:/usr/src/app
-  - ./static:/usr/src/app/static
+  - ./static:/app/static

don't mount the project root in production

#

other than that it looks okay

flat drift
#

for some reason its still the same ...

analog musk
flat drift
#

i'm reverting to an older commits and see whats wrong.

flat drift
#

Thank you @analog musk for your help .
The issue was becouse i used

import * as xml2Json from "xml-js";

and changed it to

import {xml2Json}  from "xml-js";
somber tinsel
#

I have the same problem, but I'm not sure where the issue is

#

build never finishes

#

works on Windows, but not on MacOS/Ubuntu

#

I guess I'm gonna have to try removing some imports then, unless there is a better way 😄

#

changing imports in sadly not the solution for me :/

#

is it possible to see more in-depth build log somehow?

#

it seems like the dist folder is created and works when running, but the build process never "terminates"

#

I think that's the issue, any ideas?

somber tinsel
#

I tried different (newer) version of nest cli as well, no luck

#

@analog musk can you help please?

somber tinsel
#

hahaha, finally found the issue

#

turning off "watchAssets" i.e. setting it to false fixes it

#

I guess build process checks it for some reason

flat drift
#

@analog musk
EACCES: permission denied,

[Nest] 29  - 12/30/2022, 6:56:25 AM   ERROR [POST /api/v1/scene/1368/cameras] EACCES: permission denied, open 'static/uploads/cameras/eecb9d69gc6a3g463agaaf7ga83f2dd54fe4.png'
Error: EACCES: permission denied, open 'static/uploads/cameras/eecb9d69gc6a3g463agaaf7ga83f2dd54fe4.png'

after building the api. and publishing to prod . it stoped posting pictures .

analog musk
flat drift
#

the user is not root , it a diffrent user

#

i added

USER $USER

in production stage


FROM base as production

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG PORT=3000
ENV PORT $PORT
EXPOSE $PORT

USER node
WORKDIR /app/api

COPY --chown=node:node package.json yarn.lock ./

# Install only production dependencies
RUN yarn install && yarn cache clean && (rm -rf /tmp/* || true)

ENV PATH /app/api/node_modules/.bin:$PATH

COPY --chown=node:node --from=build /app/api/dist ./dist
USER $USER
CMD [ "yarn", "start:prod" ]

it seems to be working fine

#

it uploaded the image , but its inside the container not on the host machine

#

image from docker container .

analog musk
# flat drift

Because the workdir is /app/api but the mount location was /app/static

flat drift
#

volumes:
- ./static:/app/api/static

#

this is really confusing .

analog musk
flat drift
#

after uploading image , its not being stored at the host machine .

analog musk