lerna bootstrap command does not install the local yarn packages - docker

I am trying to install my local npm packages (using yarn workspaces) in my docker container but it does not seem to be installing the local packages. Though it does install the global packages successfully.
Also, when I bash into the container and run "lerna bootstrap", that installs my local packages successfully. I have been searching all over the internet why is this happening.
My docker file's content looks like
FROM node:12.4.0-alpine
RUN apk add --no-cache bash
RUN apk add --no-cache yarn
WORKDIR "/app"
RUN yarn global add lerna
COPY . .
RUN yarn install
RUN lerna bootstrap
CMD ["npm", "run", "dev"]
My root package.json file looks like
{
"name": "my-test",
"version": "1.0.0",
"description": "Test",
"main": "app.js",
"private": true,
"workspaces": [
"packages/**"
],
"scripts": {
"start": "node app.js",
"dev": "nodemon -L app.js"
},
"author": "Phantom",
"license": "ISC",
"dependencies": {
"config": "3.0.1",
"dotenv": "7.0.0",
"express": "4.16.4",
"node-locale": "2.0.0",
},
"devDependencies": {
"lerna": "^3.15.0",
"#lerna/bootstrap": "3.8.5",
"nodemon": "1.18.10",
}
}
My lerna.json file looks like
{
"version": "1.0.0",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": ["packages/*"]
}
As a workaround, I am runing the following docker command once the container is up.
docker exec -w /app <my-container-name> lerna bootstrap
I know this is not a proper solution, so can someone please help me out?

Related

Can not get cypress to work in docker container

I want to run cypress in docker container and for this purpose i created.
For this i followed some guides and tutorials
e2e directory that has Dockerfile
FROM cypress/base:14
WORKDIR /app
# dependencies will be installed only if the package files change
COPY package.json .
COPY cypress.json .
RUN npm install
RUN npx cypress open
RUN npx cypress verify
cypress.json
{
"baseUrl": "http://localhost:3000",
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/output.xml"
}
}
package.json
{
"name": "e2e",
"version": "1.0.0",
"description": "Cypress tests",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"private": true,
"devDependencies": {
"cypress": "9.5.0"
}
}
and .npmrc
registry=http://registry.npmjs.org/
save-exact=true
progress=false
package-lock=true
modified docker-compose.yml at the root to be
version: '3.8'
services:
nextjsApp:
// rest
cypress:
image: "cypress/included:3.2.0"
depends_on:
- nextjs
environment:
- CYPRESS_baseUrl=http://nextjs:3000
working_dir: /e2e
command: npx cypress run
volumes:
- ./:/e2e
networks:
backend:
external: true```
Running docker-compose build does not cause or show any errors
But when i run docker-compose up i get
cypress_1 | Could not find any tests to run.
cypress_1 |
cypress_1 | We looked but did not find a cypress.json file in this folder: /e2e
How can this be solved ?

When deploy github action "npm ERR! command sh -c" error raise

I am using github actions, dockerfile to deploy container to AWS ecs.
But npm ERR is always raised after deploy task-definition to ECR.
I checked ECS container on EC2 instance with ssh. And I can API call in a few seconds but container stop soon.
I watched cloudwatch and find logs below.
I tried installing ts-node global, removing node_modules and npm cache... but error not disappear.
How to solve this? And where is the 2021-11-10T13_02_58_148Z-debug.log? I can not find this on container...
npm ERR! path /test
2021-11-10T22:02:58.147+09:00 npm ERR! command failed
2021-11-10T22:02:58.147+09:00 npm ERR! signal SIGTERM
2021-11-10T22:02:58.147+09:00 npm ERR! command sh -c NODE_ENV=prod ts-node app.ts
2021-11-10T22:02:58.156+09:00 npm ERR! A complete log of this run can be found in:
2021-11-10T22:02:58.156+09:00 npm ERR! /root/.npm/_logs/2021-11-10T13_02_58_148Z-debug.log
package.json
{
"name": "test-package",
"version": "1.0.0",
"description": "",
"dependencies": {
"#types/express": "^4.17.13",
"#types/node": "^16.11.7",
"ajv": "^6.12.6",
"aws-sdk": "^2.1015.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"hardhat": "^2.6.6",
"power-di": "^2.4.14",
"tslint": "^6.1.3",
"typescript": "^4.4.4"
},
"scripts": {
"start:prod": "NODE_ENV=prod ts-node app.ts",
},
"devDependencies": {
"#types/chai": "^4.2.22",
"#types/mocha": "^9.0.0",
"#types/supertest": "^2.0.11",
"chai": "^4.3.4",
"mocha": "^9.1.3",
"supertest": "^6.1.6"
}
}
FROM node:16-alpine
RUN mkdir /test
WORKDIR /test
COPY . /test
RUN npm update
RUN npm i
RUN npm i -g ganache-cli
RUN npm i -g ts-node
EXPOSE 3000
ENTRYPOINT ["npm", "run", "start:prod"]

Nodemon doesn't reload my app.js on my docker container

I decided to make a server with Express in a container and installed nodemon to watch and reload my code modifications, but, for some reason, the nodemon on container doesn't reload when I modify my code. How can I fix that?
My Dockerfile:
FROM node:14-alpine
WORKDIR /usr/app
RUN npm install -g nodemon
COPY . .
EXPOSE 3000
CMD ["npm","start"]
My package.json:
{
"name": "prog-web-2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/willonf/prog-web-2.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/willonf/prog-web-2/issues"
},
"homepage": "https://github.com/willonf/prog-web-2#readme",
"dependencies": {
"express": "^4.17.1"
}
}
My app.js:
const express = require("express")
const app = express()
app.get("/", (req, res) => {
res.end("Hello, World!")
});
app.listen(3000);
You are copying all of your files into the docker container.
COPY . .
So when you modify your local file, you are not modifying the file inside the docker container and the nodemon inside the docker container can't detect any changes.
It is possible to get the behavior you want using Docker Volumes. You can configure them, so that the docker container shares the working directory with the host system. If you change a file on the host nodemon would detect changes in this case.
The answer in this post is showing an example on how to accomplish that.

Docker - Module not found: Can't resolve 'react-plotly.js'

This question is specific to my docker configuration.
Super new to Docker and hence this problem.
I tried all the possible solutions on the internet, but none of them worked.
Closest Question: React.js Docker - Module not found
Dockerization of React App
Below are my docker files
Dockerfile
FROM node:10
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install dependencies
COPY package*.json ./
RUN npm install --silent
RUN npm install react-scripts -g --silent
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
My system has node version 10.15.3
docker-compose.yml
version: '3'
services:
django:
build: ./api
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
volumes:
- ./api:/app
ports:
- "8000:8000"
frontend:
build: ./frontend
volumes:
- ./frontend:/app
- /app/node_modules
ports:
- "3000:3000"
volumes:
node-modules:
Folder Structure:
api and frontend both have Dockerfile in it, but it's just the frontend Dockerfile that is causing the issue.
Cache messages
package.json
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"moment": "^2.29.1",
"react": "^17.0.1",
"react-big-calendar": "^0.28.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I faced the same issue but below steps helped me solve the issue.
While adding a new package to our React project and running it with docker-compose following these steps:
Stop any docker-composeif running, with docker-compose down -v
Now add your npm module in your react application, npm install react-plotly.js (in your case)
docker-compose up -d --build
After looking at your docker file it looks fine to me, so I think it's the way you're installing the package is causing the issue.

docker: removing file/image dependencies on other docker images

How do you remove files dependencies from a docker image? Everytime I build and upload a new docker image it takes layers and information from past images. How do I remove this connection so that all docker builds are independent from all others images.
Eg: I had a working file, and when I reuploaded it with no changes it stopped working and since then, I can't reupload a working file.
dockerfile:
FROM 10.119.222.132:5000/node:8.5.0-wheezy
ENV http_proxy=http://www-proxy.abc.ca:3128/
ENV https_proxy=http://www-proxy.abc.ca:3128/
ENV PORT 5000
RUN apt-get update
WORKDIR /usr/src/app
COPY package.json /usr/src/app
COPY . .
CMD ["node", "server.js"]
package.json:
{
"name": "api-proxy",
"version": "1.0.0",
"description": "API Gateway",
"main": "server.js",
"dependencies": {
"body-parser": "^1.17.2",
"crypto": "^1.0.1",
"cors": "^2.8.4",
"express": "^4.15.4",
"jsonwebtoken": "^7.4.2",
"mongodb": "^2.2.31",
"request": "^2.81.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC"
}
You could build it using
docker build --no-cache my_new_image:v1.0.0 .

Resources