I have a TypeScript Node app. I have a dev and start npm scritps:
"dev": "ts-node-dev src/index.ts",
"build": "npm run test:ci && tsc",
"start": "node dist/index"
When developing I watch changes on the .ts files and when running in production I want to run the .js files from the dist dir (which is generated using the npm build script).
This is my Dockerfile:
FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i --only=prod
COPY . .
CMD ["npm", "run", "dev"]
When its running on dev env its good, but on production the CMD command should be like that:
CMD ["npm", "start"]
Also the RUN npm i --only-prod command also needs to be changed respectively.
How to make it adjustable to dev vs prod?
In kubernetes you can overwrite the default command args:
apiVersion: apps/v1
kind: Deployment
[...]
spec:
template:
spec:
containers:
- name: CONTAINER-NAME
image: IMAGE-NAME
args: [
"npm",
"start" ]
See the kubernetes documentation.
The detailed implementation depend on the deployment system you're using:
.yaml files, one for the development and one for the production environment.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With