Reputation: 3990
I'd like to configure runner that automaticaly builds and deploys an Angular app. For that, I'd have to install the project dependencies with npm install
before building or deploying, because those are not stored in the repo. The thing is that it is a very slow process, so I'd have to wait for like 5 minutes for that process to complete and the app to be deployed.
Is it possible to avoid this somewhat? A possibility in to install all project dependencies globally, but it is far from ideal.
Upvotes: 0
Views: 787
Reputation: 3990
I was facing the same problem, and what I ended up doing is:
node_modules
and package.json
in an external folder, that is not overwritten in each commitnode_modules
in the project root's folder pointing to the external node_modules
folderpackage.json
and the one in the external location. If they are different, I run npm install
and update the external node_modules
and package.json
--preserve-symlinks
option to your build or serve commandsWith this setting I am now having a build time of 47s compared de 3+ min before.
Upvotes: 0
Reputation: 2145
Meet GitLab's CI cache!
You can use it e.g. to share your node_modules
folder. Running npm install
once the dependencies are there, will just update if needed.
Here you have an example project with Angular of using:
cache:
paths:
- node_modules/
Where you can compare the execution time of the 2 stages (https://gitlab.com/solidgear-projects/GitlabCI/pipelines/11759264):
Successfully extracted cache
"Note that cache
is only to share stuff between jobs (you mentioned you have one for build and one for deploy).
To share stuff between different builds (pipelines), I'd recommend you to read on https://about.gitlab.com/2017/07/11/dockerizing-review-apps/ which gives some hints on how to use docker images to bundle all your app's dependencies in a base image and reuse it in the future for your builds. e.g.
build_base:
stage: build
image: docker
services:
- docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
- docker pull registry.gitlab.com/your-name/your-project:base
script:
- docker build -t registry.gitlab.com/your-name/your-project .
- docker push registry.gitlab.com/your-name/your-project:base
when: manual
Upvotes: 1