I want to setup a CD pipeline for a typescript/node API. I am using a Dockerfile to upload images to AWS ECR manually and it works as expected.
FROM node:11-slim
EXPOSE 8080
WORKDIR /usr/src/app
RUN mkdir /usr/src/app/src
COPY ./node_modules node_modules
COPY ./dist dist
COPY ./package.json package.json
ENV PORT=8080
USER node
CMD ["node", "./dist/app.js"]
To upload images to AWS ECR I am using the following Dockerfile:
FROM node:11-slim
EXPOSE 8080
WORKDIR /usr/src/app
RUN mkdir /usr/src/app/src
COPY ./package.json package.json
RUN npm add -g typescript
RUN npm install tsc -g
RUN npm install
RUN sh -c tsc -p .
ENV PORT=8080
USER node
CMD ["node", "./dist/app.js"]
I use the RUN sh -c tsc -p . command to build my project. Even if the build succeeds, it does not contain the dist folder which contains the built project in the image.
Here is an excerpt from my projects package.json file:
"scripts": {
"start": "node dist/app.js",
"install": "yarn install",
"postinstall": "tsc -p .",
"watch": "tsc -w -p .",
"debug": "nodemon --watch ./dist --inspect=0.0.0.0:9222 --nolazy ./dist/app.js",
"docker-debug": "sudo tsc && docker-compose up --build"
},
When I use RUN npm run postinstall, the compiler errors: missing script postinstall.