Nuxt js high CPU usage on docker - docker

I used nuxt and Docker to develop the app,
but running Docker uses a lot of RAM and CPU
Please see my configs below and tell me your opinion
Do you have a solution?
package.json File
"name": "ladder",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
"lint:prettier": "prettier --check .",
"lint": "yarn lint:js && yarn lint:prettier",
"lintfix": "prettier --write --list-different . && yarn lint:js --fix",
"test": "jest"
},
}
nuxt.config.js File
target: 'static',
ssr: false,
head: {
title: 'ladder',
htmlAttrs: {
lang: 'en',
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ name: 'apple-mobile-web-app-status-bar-style', content: '#007ad5' },
],
},
css: [
],
plugins: [
],
components: true,
buildModules: [
'#nuxt/typescript-build',
'#nuxtjs/device',
'#nuxtjs/tailwindcss',
['#nuxtjs/vuetify']
],
modules: [
'nuxt-route-meta'
],
vuetify: {
treeShake: true,
defaultAssets: false
},
build: {},
watchers: {
webpack: {
ignored: /node_modules/
}
},
server: {
host: '0.0.0.0',
}
}
Dockerfile
FROM node:16
WORKDIR /portal
COPY package*.json ./
RUN yarn install
COPY . .
RUN yarn build
EXPOSE 3000
CMD ["yarn","dev"]
docker stats command
Image
Do you have a solution?

Related

Docker build getting stuck at npm run build step

I was trying to create a docker Image where it is getting stuck at the "npm run build" step. I could see the message as build completed successfully but it is not proceeding to the next step.
below the docker file. I m using node:16.13.1 as base Image
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY .npmrc ./
RUN npm install node-sass#latest
RUN npm install core-js#2.5.7
RUN npm install
COPY . /usr/src/app
# build web app
RUN npm run build
EXPOSE 8080
RUN chmod +x /usr/src/app/setup.sh
CMD ["/usr/src/app/setup.sh"]
Not proceeding after the below step,
Package.json file
{
"name": "full-kyc",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"format": "prettier --write \"**/*.{js,vue,html,json,md}\" && prettier-stylelint --write --quiet '**/*.{css,scss,vue}'",
"build:dev": "vue-cli-service build --mode development --watch",
"start:dev": "NODE_ENV=development nodemon bin/www | bunyan",
"start:prod": "node bin/www | bunyan"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,vue,html,json,md}": [
"prettier --write",
"git add"
],
"*.{css,scss,vue}": [
"prettier-stylelint --write --quiet",
"git add"
]
},
"dependencies": {
"#vue/babel-preset-app": "^4.5.15",
"axios": "^0.21.4",
"body-parser": "1.18.3",
"btoa": "^1.2.1",
"bunyan": "1.8.12",
"cookie-parser": "1.4.3",
"crypto": "^1.0.1",
"express": "4.16.3",
"express-http-proxy": "1.4.0",
"raven-js": "^3.27.2",
"vue": "2.5.17",
"vue-router": "3.0.1",
"vuex": "3.0.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.5.15",
"#vue/cli-plugin-eslint": "3.0.1",
"#vue/cli-service": "3.0.1",
"babel-eslint": "^10.1.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^6.15.0",
"eslint-loader": "^2.2.1",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-vue": "^5.2.3",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"node-sass": "^4.14.1",
"nodemon": "1.18.4",
"prettier": "^1.19.1",
"prettier-stylelint": "^0.4.2",
"sass-loader": "7.0.1",
"stylelint-config-recommended": "^2.2.0",
"vue-template-compiler": "2.5.17",
"vue-smooth-picker": "file:vue-smooth-picker",
"webpack-bundle-analyzer": "^4.5.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true,
"es6": true,
"browser": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"prettier/vue",
"plugin:prettier/recommended"
],
"rules": {
"vue/component-name-in-template-casing": [
"error",
"PascalCase"
]
},
"globals": {
"axios": "readonly"
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"stylelint": {
"rules": {
"no-descending-specificity": null
},
"extends": "stylelint-config-recommended"
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
change
RUN npm run build
to
CMD ["npm", "run", "build"]

db-migrate can't find heroku config vars at docker deploy

I'm trying to deploy a node Express app to Heroku using docker via a Gihub action ( uses: gonuit/heroku-docker-deploy#v1.3.3) and want to run db-migrate up in the Dockerfile.
It looks like db-migrate can't take into account the config vars (environment variables) provided by Heroku.
Dockerfile:
FROM node:16-alpine3.13
WORKDIR /app
COPY package.json ./
RUN yarn install --production
COPY . .
RUN yarn db-migrate up -e production
CMD ["yarn", "start"]
database.json:
{
"dev": {
"driver": "mysql",
"dialect": "mysql",
"multipleStatements": true,
"host": { "ENV": "DB_HOST" },
"user": { "ENV": "DB_USER" },
"password": { "ENV": "DB_PASSWORD" },
"database": { "ENV": "DB_NAME" },
"port": { "ENV": "DB_PORT" }
},
"production": {
"driver": "mysql",
"dialect": "mysql",
"multipleStatements": true,
"database_url": { "ENV": "CLEARDB_DATABASE_URL" },
"host": { "ENV": "DB_HOST" },
"user": { "ENV": "DB_USER" },
"password": { "ENV": "DB_PASSWORD" },
"database": { "ENV": "DB_NAME" }
},
"sql-file": true
}
Error:
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: connect ECONNREFUSED 127.0.0.1:3306
at module.exports (/app/node_modules/db-migrate/lib/commands/helper/assert.js:9:14)
at /app/node_modules/db-migrate/lib/commands/up.js:19:14
at /app/node_modules/db-migrate/connect.js:17:7
at /app/node_modules/db-migrate/lib/driver/index.js:95:9
at /app/node_modules/db-migrate-mysql/index.js:518:14
at Connection.<anonymous> (/app/node_modules/mysql2/lib/connection.js:775:13)
at Object.onceWrapper (node:events:510:26)
at Connection.emit (node:events:390:28)
at Connection._notifyError (/app/node_modules/mysql2/lib/connection.js:236:12)
at Connection._handleFatalError (/app/node_modules/mysql2/lib/connection.js:167:10)
at Connection._handleNetworkError (/app/node_modules/mysql2/lib/connection.js:180:10)
at Socket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
error Command failed with exit code 1.

How to run a task on stop event in debugging?

I tried the postDebugTask but it doesn't seem to run the task at all. I've skimmed this as well to no avail.
./.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Node.js in Docker",
"type": "docker",
"request": "launch",
"preLaunchTask": "run",
"platform": "node",
"removeContainerAfterDebug": true,
"postDebugTask": "stop"
}
]
}
./.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "run",
"command": "docker-compose up serve ; docker-compose rm -fsv serve",
},
{
"type": "shell",
"label": "stop",
"command": "echo test | docker-compose rm -fsv serve",
},
]
}
How can I make it so that docker-compose rm -fsv serve runs in parallel if the stop event occurs in the debug?

how to build electron app for windows in ubuntu using electron builder

I have created an electron app .Using electron-builder I created appImage in linux.I want build app for windows in linux .But it is throwing wine required error .please help to resolve this issue.
this is package.json
"name": "Gamer",
"version": "1.0.0",
"main": "main.js",
"repository": "https://github.com/XYX/GAME",
"dependencies": {
"#agm/core": "^1.0.0-beta.5",
...
"electron-builder-squirrel-windows": "^22.1.0",
"electron-packager": "^14.1.0",
"electron-reload": "^1.5.0",
"electron-store": "^5.1.0",
},
"devDependencies": {
...
"electron": "^7.1.1",
"electron-builder": "^22.1.0",
"electron-prebuilt": "^1.4.13",
"electron-updater": "^4.2.0",
...
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:electron": "ng build --base-href ./ && electron .",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build": "ng build --prod && electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"build:Win": "electron-builder --win",
"ship": "build",
"electron-packager": "electron-packager ./ --all."
},
"peerDependencies": {
"#angular/animations": "^7.2.15",
"#angular/cdk": "^7.3.7",
"#angular/material": "^7.3.7"
},
"author": "",
"license": "ISC",
"build": {
"appId": "com.electron.coxGamer",
"compression": "normal",
"extends": null,
"files": [
"*.js",
"build",
"dist"
],
"mac": {
"target": "zip"
},
"linux": {
"target": [
"AppImage",
"zip"
]
},
"win": {
"target": "NSIS"
},
"publish": {
"provider": "github",
"repo": "https://github.com/XYX/GAME",
"owner": "XYX"
}
}
}
Even the electron-updater throwing error for dev-update.yml not found.and also app-icon is not setting
const { app, BrowserWindow, Menu,ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const { autoUpdater } = require("electron-updater");
Menu.setApplicationMenu(null);
let mainWindow;
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1200,
height: 900
});
mainWindow.setMenuBarVisibility(false);
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file:',
slashes: true
}));
mainWindow.on('closed', () => {
mainWindow = null;
});
};
autoUpdater.on('update-downloaded', (info) => {
win.webContents.send('updateReady')
});
app.on('ready', () => {
createWindow();
autoUpdater.checkForUpdates();
});
ipcMain.on("quitAndInstall", (event, arg) => {
autoUpdater.quitAndInstall();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
Here is how I managed to build windows app from mac/linux. Maybe this can help you #Krazy.
First off all, I'm using the docker version of electron-builder
And then, here are the steps
1- Install electron builder dev in your project
npm install electron-builder —save-dev
2- In package.json add this to script
"dist": "electron-builder"
3- Launch Docker
4- In terminal, run
docker run --rm -ti \
--env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
--env ELECTRON_CACHE="/root/.cache/electron" \
--env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \
-v ${PWD}:/project \
-v ${PWD##*/}-node-modules:/project/node_modules \
-v ~/.cache/electron:/root/.cache/electron \
-v ~/.cache/electron-builder:/root/.cache/electron-builder \
electronuserland/builder:wine
5- cd into your project
6- type
yarn && yarn dist -w
This is how I build my first windows app in Linux.
1- Install electron builder dev in your project
npm install electron-builder
2- Create a builder.js file your should look like this.
const builder = require("electron-builder")
const Platform = builder.Platform
// Promise is returned
builder.build({
targets: Platform.WINDOWS.createTarget(),
config: {
'win': {
'files': [
// All your files you are using
'main.js',
],
'compression': 'store',
'asar': false
}
}
})
.then(() => {
// handle result
})
.catch((error) => {
// handle error
})
3- Launch your app.

error showing while creating a debian file from electronjs project

I am getting the below error while making deb file of electronjs
Error: could not find the Electron app binary at "dist/app-linux-x64/koriwallet". You may need to re-bundle the app using Electron Packager's "executableName" option.
My package.json file is
{
"name": "wallet",
"version": "1.0.0",
"description": "wallet",
"main": "src/main.js",
"scripts": {
"start": "electron .",
"build": "electron-packager . myapp",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"deb64": "electron-installer-debian --src dist/app-linux-x64/ --dest dist/installers/ --arch amd64"
},
"author": "wallet",
"license": "ISC",
"devDependencies": {
"asar": "^2.0.1",
"electron": "^5.0.6",
"electron-builder": "^21.1.1",
"electron-installer-debian": "^2.0.0",
"electron-packager": "^14.0.2"
},
"electronPackagerConfig": {
"packageManager": "npm",
"executableName": "kori"
},
"build": {
"appId": "wallet",
"linux": {
"category": "wallet"
}
},
"dependencies": {
"cookies": "^0.7.3",
"crypto": "^1.0.1",
"dpkg": "^1.0.0",
"jquery": "^3.4.1",
"jstorage": "^0.4.8"
}
}
My 2 cents. I'm making an Fedora 30 rpm and got:
An unhandled error has occurred inside Forge:
An error occured while making for target: rpm
could not find the Electron app binary at "/home/ajm/Documents/Projects/sunstealer.ets/out/sunstealer.ets product-linux-x64/sunstealer.ets". You may need to re-bundle the app using Electron Packager's "executableName" option.
Error: could not find the Electron app binary at "/home/ajm/Documents/Projects/sunstealer.ets/out/sunstealer.ets product-linux-x64/sunstealer.ets". You may need to re-bundle the app using Electron Packager's "executableName" option.
at error.wrapError (/home/ajm/Documents/Projects/sunstealer.ets/node_modules/electron-installer-common/src/installer.js:145:15)
Fix was update package.json from
"name": "sunstealer.ets",
"productName": "sunstealer.ets product",
to:
"name": "sunstealer.ets",
"productName": "sunstealer.ets",
i.e. same value. Then npm run make with:
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"certificateFile": "./certs/adam_mauger.pfx",
"certificatePassword": "REDACTED"
}
},
{
"name": "#electron-forge/maker-dmg",
"config": {
"format": "ULFO"
}
},
{
"name": "#electron-forge/maker-rpm",
"config": {
}
},
created sunstealer.ets-1.0.0-1.x86_64.rpm. Hope that helps.
my 5 cents)
so, launch npm from root folder. there exist node_modules.
app stored in root/src. there exist node_modules.
and in root and in root/src have package.json
check root/src/package.json file. maybe there parameter "name" have default value in lowercase

Resources