2

I am trying to use docker in order to run npm & bower install.

Here is my configuration:

./package.json

{
  "name": "bignibou-client",
  "version": "0.1.0",
  "engines": {
    "node": "0.10.x"
  },
  "devDependencies": {
    "bower": "1.3.12",
    "grunt": "~0.4.5",
    "grunt-contrib-uglify": "~0.6.0",
    "grunt-contrib-concat": "~0.5.0",
    "karma": "~0.12.23",
    "grunt-karma": "~0.9.0",
    "karma-junit-reporter": "~0.2.2",
    "karma-jasmine": "~0.1.5",
    "karma-phantomjs-launcher": "~0.1.4",
    "phantomjs": "~1.9.11",
    "grunt-mkdir": "~0.1.2",
    "grunt-contrib-cssmin": "~0.10.0",
    "grunt-contrib-clean": "~0.6.0",
    "grunt-contrib-copy": "~0.7.0",
    "karma-htmlfile-reporter": "~0.1.2",
    "grunt-filerev": "~2.1.2",
    "grunt-usemin": "~2.6.2",
    "grunt-protractor-runner": "~1.1.4",
    "protractor": "~1.4.0",
    "flow": "~0.2.3",
    "assemble-less": "~0.7.0"
  },
  "scripts": {
    "postinstall": "node_modules/bower/bin/bower install"
  }
}

.bowerrc

{
    "json": "bower.json", "directory": "bignibou-client/src/bower_components"
}

My command:

docker run --privileged=true -it --rm \
   -w /usr/src/app \
   -v $(pwd)/package.json:/usr/src/app/package.json  \
   -v $(pwd)/.bowerrc:/usr/src/app/.bowerrc \
   -v $(pwd)/./bower.json:/usr/src/app/bower.json  \
   -v ./build/npm.tmp/node_modules:/usr/src/app/node_modules  \
   -v ./build/npm.tmp/bignibou-client/src/bower_components:/usr/src/app/bignibou-client/src/bower_components \
   digitallyseamless/nodejs-bower-grunt npm install

I just get the following console output:

npm WARN package.json bignibou-client@0.1.0 No description
npm WARN package.json bignibou-client@0.1.0 No repository field.
npm WARN package.json bignibou-client@0.1.0 No README data
npm WARN package.json bignibou-client@0.1.0 No license field.

and nothing is generated on the host...

Can someone please provide advice as to how to get it working or an alternative solution?

edit:

Running the following command:

docker run --privileged=true -it --rm \
-w /usr/src/app \
-v $(pwd):/usr/src/app \
digitallyseamless/nodejs-bower-grunt npm install

results in:

npm WARN package.json bignibou-client@0.1.0 No repository field.
npm WARN package.json bignibou-client@0.1.0 No license field.
npm WARN cannot run in wd bignibou-client@0.1.0 node_modules/bower/bin/bower install (wd=/usr/src/app)
balteo
  • 23,602
  • 63
  • 219
  • 412

1 Answers1

2

-v $(pwd)/package.json:/usr/src/app/package.json

this flag will create a package.json directory but not the file.

Here is how your command should look like:

docker run --privileged=true -it --rm \
-w /usr/src/app \
-v $(pwd):/usr/src/app\
digitallyseamless/nodejs-bower-grunt bash -c "npm install && bower --allow-root install"

And after this script create node_modules and bower_components in current directory on HOST mashine and you can manipulate with result as you wish.

Andrey Romashin
  • 3,194
  • 1
  • 12
  • 15
  • Thanks Andrey. I have edited my post to take into account your reply. – balteo Sep 01 '15 at 07:04
  • You have no necessary to install _bower_, because it already installed in `digitallyseamless/nodejs-bower-grunt` as **global**. And after removing from package.json the `postinstall` section and replacing `npm install` from docker command to `bash -c "npm install && bower --allow-root install"` the error **npm WARN cannot run in wd** should be resolwed – Andrey Romashin Sep 01 '15 at 07:51
  • Thanks. It works now. I will just have to find a way to sort out one small remaining issue: the postinstall section is required by my production environment (Heroku buildpack). – balteo Sep 01 '15 at 07:58
  • if you really need a postinstall section you can do folowing: Replace postinstall section as this `"postinstall": "bower install"` Change docker command to `bash -c "npm install --unsafe-perm"` – Andrey Romashin Sep 01 '15 at 08:49
  • 1
    Hi again. I have left the postinstall script in package.json and added this: `--ignore-scripts` to the docker command. It works a charm! Thanks again. – balteo Sep 01 '15 at 08:51