rpadovani rpadovani - 1 year ago 811
AngularJS Question

Angularjs + grunt + bower + Gitlab CI. Setup for testing

I've a GitLab CI runner that runs every time I push code in my branch.
The problem is: I use npm+bower to have all dependencies I need, but I don't want to download all dependencies for each test: it's a waste of network and time.

So I came up with this script. Does it make any sense?

touch ~/.bash_profile
npm config set prefix ~/npm
export PATH="~/npm/bin:$PATH"
source ~/.bash_profile
npm install
rm -f ~/bower/bower.json
cp bower.json ~/bower
pushd ~/bower
bower update
bower install
mkdir bower_components
cp -r ~/bower/bower_components bower_components
grunt test

Anyway, a problem I'm facing is it always goes on timeout with bower:

bower angular-cookies#1.2.16 ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/angular/bower-angular-cookies.git", exit code of #128 fatal: unable to connect to github.com: github.com[0:]: errno=Connection timed out

Also, it didn't finish once, so I'm not sure, but it seems it re-download all packages every time.

I tried to search on the net, but I didn't find anything. There is a way to achieve what I'm trying to achieve? (Also with a completely different strategy. I also have ssh access to the runner)

Answer Source


GitLab runners now use .gitlab-ci.yml that has support for cache.

This is our script now:

image: *****/frontend

  - test
  - deploy

  - npm prune
  - npm install
  - bower prune --allow-root
  - bower install --allow-root

    - node_modules/
    - bower_components/
  key: "$CI_BUILD_REPO"

  stage: test
    - grunt build
    - grunt test
    - grunt jscs --force
    - grunt jshint --force

  stage: deploy
    - master
    - development
    - grunt build babel uglify:dist
      - dist/

Now, the interesting thing is key: "$CI_BUILD_REPO" in the cache section - this set the cache to be the same for all the build in the repo. This is why we use npm prune and bower prune - to be sure only modules we really need are in the build at the end


So, at the end I use this script:

rm -f ~/bower/bower.json
rm -f ~/bower/package.json
cp bower.json ~/bower
cp package.json ~/bower
pushd ~/bower
npm install
bower install
cp -r ~/bower/bower_components .
cp -r ~/bower/node_modules .
grunt build
grunt test

Also, to avoid timeout from github I use https instead of git to download code, with the command

git config --global url."https://".insteadOf git://
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download