On successfully building using below dockerfile, I am unable to deploy my application on eks.
FROM node:12
# Create app directory
WORKDIR /usr/src/app
COPY udagram-feed/package*.json ./
RUN npm ci
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "run", "prod" ]
on fetching logs from cluster, this is what i get:
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module '/usr/src/app/www/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! udagram-user@1.0.0 prod: `tsc && node ./www/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the udagram-user@1.0.0 prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-20T19_11_45_220Z-debug.log
running the image locally, i have the below file structure:
the src/ directory contains the serves.ts sequelize.ts and other files. Clearly there is no www/ directory. Why is kubernetes looking for files in this directory? Any help is appreciated. I have been stuck on this for days now, don't know what to do. For file structure, please see the github repo Github
First, your Dockerfile created a 1GB image. I modified it to create a 240MB image. This Dockerfile can be further optimized; you can refer here and here for examples on creating a multi-stage Dockerfile.:
FROM node:12-alpine
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN apk add --no-cache --virtual .gyp \
python \
make \
g++ \
&& npm ci \
&& apk del .gyp
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "run", "prod" ]
Here's the docker image sizes:
REPOSITORY TAG IMAGE ID CREATED SIZE
udagram-feed-alpine latest 185478b5eabc 11 seconds ago 247MB
udagram-feed latest fbf32e67d4fa 4 minutes ago 1.07GB
Secondly, your package.json is referring to ./www/server.js
file