Publish NPM package from inside docker container - node.js

I am desperately trying to publish my NPM package to our NPM repo.
I keep getting an error stating that my working directory is not clean and I can't get my head around it.
This is my Dockerfile:
FROM node:12
ARG VERSION
COPY .npmrc /root/.npmrc
COPY .gitconfig /root/.gitconfig
COPY .git-credentials /root/.git-credentials
WORKDIR /home/node/app/
COPY package.json package.json
RUN npm install
COPY . .
RUN npm run release:testless -- ${VERSION}
package.json:
"scripts": {
"prepare": "npm run prepare:util",
"prepare:util": "npm explore vl-ui-util -- npm run install:copy",
"test": "wct -l chrome,firefox --npm",
"release": "npm run release:prepare && np",
"release:prepare": "npm run release:prepare:build",
"release:prepare:build": "npm run build",
"release:prepare:commit": "git add -f vl-map.js && git commit --amend --no-edit && git pull",
"release:testless": "npm run release:prepare && np --yolo",
"demo": "npm run dev",
"dev": "concurrently \"npm:bundle:watch\" \"http-server\"",
"build": "npm run bundle:build",
"bundle:watch": "rollup --config rollup.config.js --watch",
"bundle:build": "rollup --config rollup.config.js"
}
This results in:
npm ERR! Git working directory not clean.

I solved it by cloning inside the container instead of letting Bamboo do the clone and copy all my source files into the container.

Related

Docker / Node.js / Vue.js -> error:0308010C:digital envelope routines::unsupported

I try to set up a docker image for a program based on Vue.js.
Unfortunately I get the Error: error:0308010C:digital envelope routines::unsupported
I already tried the following solutions, unfortunately without success:
Added "start": "react-scripts --openssl-legacy-provider start" in package.json RESULT: No Change, still error:0308010C
Added "build": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build" in package.json RESULT: Error changed to executor failed running [/bin/sh -c npm run build]: exit code: 127
changed dockerfile to use an older node.js version: FROM node:node:lts-alpine as build RESULT: Error changed to Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
What else can I try to get my Vue.js program into a docker image?
The script part of my package.json file (before my above mentioned unseccessfull changes) looks like this:
"scripts": {
"dev": "NODE_ENV=development nodemon -w backend/app.js backend/app.js & vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"start": "node backend/app.js"
},
The first lines of my dockerfile (before my above mentioned unseccessfull changes) looks like this:
FROM node:current-alpine as build
RUN ["mkdir", "-p", "/usr/src/app"]
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json", "/usr/src/app/"]
RUN apk add --no-cache git &&
npm install
COPY . .
RUN npm run build
Any help is highly welcome.

condition Script in package.json

I have two questions:
How I can do this npm run script --production instead npm run script --env=production
How I want to pass as an argument to another script something like, if you want to create database on development you just run npm run dev --development --create-database or if you wanna drop development database npm run dev --development --drop-database, this is because I want to add one script to handle create or drop database but if you are doing this in production database, it will throw you a warning..
This is what I have until now
"dev": "NODE_ENV=development nodemon src/serve.js",
"start": "NODE_ENV=production src/serve.js",
"test": "NODE_ENV=test jest --testTimeout=10000 --runInBand --detectOpenHandles",
"db:create": "NODE_ENV=$npm_config_env npm run db:condition",
"db:drop": "NODE_ENV=$npm_config_env npx sequelize-cli db:drop",
"db:condition": "if [[ ${NODE_ENV} == \"production\" ]]; then npm run warning; else npm run db:reset; fi",
"db:reset": "npx sequelize-cli db:drop && npx sequelize-cli db:create && npx sequelize-cli db:migrate && npx sequelize-cli db:seed:all",
"warning": "echo \"You can't do this on production\""
If you can see I only add condition for "db:create".

Failed to write to file: ENOENT: no such file or directory

I am trying to build a folder with the name of build which will gonna contains number of map files and JavaScript files. But i'm getting an issue shown below.
Code :
"scripts": {
"prestart": "d2-manifest package.json manifest.webapp",
"start": "webpack-dev-server",
"test": "echo Everything probably works great\\! ## karma start test/config/karma.config.js --single-run true",
"build": "rm -rf build && set NODE_ENV=production webpack --progress && npm run manifest",
"postbuild": "cp -r src/i18n icon.png ./build/",
"validate": "npm ls --depth 0",
"manifest": "d2-manifest package.json build/manifest.webapp",
"deploy": "npm run build && mvn clean deploy",
"lint": "echo Looks good."
}
Error :
(I'm ignoring the fact that you seem to run this on a Windows machine)
The set command does not do what you think it does. To set an environment variable for a command, use
VARIABLE=value cmd
or
env VARIABLE=value cmd
This means changing
set NODE_ENV=production webpack --progress
into
env NODE_ENV=production webpack --progress
With set NODE_ENV=production webpack --progress you just set the positional parameters of the current shell instance to NODE_ENV=production, webpack and --progress.

why package.json script works fine on local project but doesn't work on a dependency project

I have created a npm module(let call it ModuleA) and defined clean script in its package.json file like below:
"scripts": {
"test": "nyc mocha tests/ --opts mocha.opts",
"build": "babel -d dist/ src/",
"prepublish": "yarn run clean && yarn run build",
"postinstall": "yarn run clean && yarn run build",
"clean": "rimraf ./dist"
},
I use rimraf to remove the dist directory. This dependency is defined in devDependencies as "rimraf": "^2.6.1". It works fine on this project. But in one of my other project (let call it ModuleB) which has a dependency on this module, the yarn install doesn't work and I get below error:
$ rimraf ./dist
sh: 1: rimraf: not found
this error happens when npm/yarn is building the ModuleB. I have checked that rimraf exist in node_modules/.bin directory in ModuleB. It works fine if I install rimraf globally. I wonder how I can make the npm/yarn to use rimraf from node_modules/.bin/rimraf?
BTW, I also put the rimraf in devDependencies in ModuleB.
I tried to update the script in ModuleA to use rimraf from node_modules/.bin/rimraf as below:
"clean": "node_modules/.bin/rimraf ./dist"
it works fine on ModuleA. But I got below error when run yarn install on ModuleB:
$ node_modules/.bin/rimraf ./dist
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
sh: node_modules/.bin/rimraf: No such file or directory
error Command failed with exit code 127.
See those issues:
https://github.com/yarnpkg/yarn/issues/721 (postinstall hook doesn't appear to be run #721)
https://github.com/yarnpkg/yarn/issues/853 (preinstall and postinstall are not run #853)
https://github.com/yarnpkg/yarn/issues/614 (Bug: issue with postinstall scripts in git-hooks package)
Now make sure that yarn clean and npm clean works as expected.
For example this will not work if you didn't install rimraf globally:
$ rimraf ./dist
But this should work:
$ ./node_modules/.bin/rimraf ./dist
Test those commands first:
npm run clean
and:
yarn run clean
to use the "clean": "rimraf ./dist" script defined in package.json.
Note that ./node_modules/.bin is added to your PATH when you run package.json scripts.
Try running the commands from the simple ones where you run the script directly without npm or yarn, then test with both npmand yarn, and then finally try to narrow down the problem with postinstall hooks.

Npm scripts doesn't work the way I want

see below:
scripts": {
"build": "node_modules/.bin/babel sercer/src --out-dir server/dist ",
"build:watch": "node_modules/.bin/babel server/src --out-dir server/dist --watch",
"start:server": "node ./node_modules/nodemon/bin/nodemon.js ./server/dist/app.js",
"dev" : "(npm run build:watch) && (npm run start:server)"
}
you know, both of them can work well when I run npm run xxx , but when i conbian them like npm run dev does,the last one will not taking effect.what wrong with my script?
You could try
"dev" : "npm run build:watch && npm run start:server"
you can use the post- and pre- scripts that will be called before and after that script.
eg :
"build": "npm run build:css && npm run build:js",
"prebuild:js": "npm run lint"
In the above example build will execute both build:css and build:js - but not before running the lint task.

Resources