moleculerjs / moleculer-template-project-typescript

Typescript project template for Moleculer microservices framework.
MIT License
123 stars 45 forks source link

App run on dockers succesfully exits. #39

Closed olivinesguerra closed 3 years ago

olivinesguerra commented 3 years ago

Hi.

I'm using this template for my backend project. I successfully run the app locally by running "npm run dev" but when I tried to deploy using kubernetes/docker with this commands

  1. Npm start

and in the config file. "start": "moleculer-runner services/**".

Screen Shot 2020-10-01 at 12 16 21 PM

olivinesguerra commented 3 years ago

BTW guys. this is a logs from one of my deployments.

olivinesguerra commented 3 years ago

I tried running this

moleculer-runner --instances=4 services/*/.service.ts

and returns an error on docker

![Uploading Screen Shot 2020-10-02 at 8.57.50 PM.png…]() Failed to load service '/app/services/api.service.ts' /app/services/api.service.ts:1 import {IncomingMessage} from "http";

icebob commented 3 years ago

@devalexandre could you help him?

olivinesguerra commented 3 years ago

Thnks @icebob .

Also just for helping debug the error.

I changes my start command on package.json.

Screen Shot 2020-10-02 at 9 09 37 PM "start": "moleculer-runner --instances=4 services",

oanhnn commented 3 years ago

@olivinesguerra Can you show your package.json, Dockerfile, docker-compose.yml or kubernetes.yml?

olivinesguerra commented 3 years ago

Hi @oanhnn .

This is the json file.

{ "name": "backend", "version": "1.0.0", "description": "My Moleculer-based microservices project", "scripts": { "build": "tsc --build tsconfig.json", "dev": "ts-node ./node_modules/moleculer/bin/moleculer-runner.js --hot --repl --config moleculer.config.ts services/*/.service.ts", "start": "moleculer-runner.js", "cli": "moleculer connect Redis", "ci": "jest --watch", "test": "jest --coverage", "lint": "eslint --ext .js,.ts .", "dc:up": "docker-compose up --build -d", "dc:logs": "docker-compose logs -f", "dc:down": "docker-compose down" }, "keywords": [ "microservices", "moleculer" ], "author": "", "devDependencies": { "eslint": "^6.8.0", "eslint-plugin-import": "^2.20.2", "@typescript-eslint/eslint-plugin": "^2.26.0", "@typescript-eslint/parser": "^2.26.0", "eslint-plugin-prefer-arrow": "^1.2.2", "jest": "^25.1.0", "jest-cli": "^25.1.0", "moleculer-repl": "^0.6.2", "ts-jest": "^25.3.0", "ts-node": "^8.8.1" }, "dependencies": { "@types/jest": "^25.1.4", "@types/mkdirp": "^1.0.0", "@types/node": "^13.9.8", "axios": "^0.20.0", "dotenv": "^8.2.0", "firebase": "^7.21.1", "firebase-admin": "^9.2.0", "geolib": "^3.3.1", "ioredis": "^4.14.1", "kleur": "^4.1.2", "moleculer": "^0.14.0", "moleculer-db": "^0.8.4", "moleculer-db-adapter-mongo": "^0.4.7", "moleculer-web": "^0.9.0", "moment": "^2.29.0", "protobufjs": "^6.10.1", "typescript": "^3.8.3" }, "engines": { "node": ">= 10.x.x" }, "jest": { "coverageDirectory": "/coverage", "testEnvironment": "node", "moduleFileExtensions": [ "ts", "tsx", "js" ], "transform": { "^.+\.(ts|tsx)$": "ts-jest" }, "testMatch": [ "*/.spec.(ts|js)" ], "globals": { "ts-jest": { "tsConfig": "tsconfig.json" } } } }

Dockerfile:

FROM node:12.0.0

ENV export NODE_ENV=production

Working directory

RUN mkdir /app WORKDIR /app

Install dependencies

COPY package.json package-lock.json tsconfig.json ./ COPY .env.default .env

RUN npm ci --quiet --only=production

Copy source

COPY . .

Build and cleanup

ENV NODE_ENV=production RUN npm run build \ && npm prune

EXPOSE 3000

Start server

RUN npm start

docker-compose.yml

version: "3.3"

services:

api: build: context: . image: backend env_file: docker-compose.env environment: SERVICES: api PORT: 3000 labels:

networks: internal:

olivinesguerra commented 3 years ago

@oanhnn or just create an empty project. and run npm start . Thanks

oanhnn commented 3 years ago

@olivinesguerra Please edit your comment follow markdown syntax https://www.markdownguide.org/basic-syntax/#code-blocks It look like you using Typescript template (old template) with Redis transporter. Can you try with latest Typescript template? It run success with Redis https://github.com/moleculerjs/moleculer-template-project-typescript/runs/1219539367?check_suite_focus=true

devalexandre commented 3 years ago

@devalexandre could you help him?

yes, your docker compose this without identification @olivinesguerra