In our GitLab CI environment we have a build server with lots of RAM but mechanical disks, running npm install takes a long time (I have added cache but it still needs to chew through existing packages so cache cannot solve all of this alone).
I want to mount /builds in the builder docker image as tmpfs but I'm having a hard time figuring out where to put this configuration. Can I do that in the builder image itself or maybye in .gitlab-ci.yml for each project?
Currently my gitlab-ci.yml looks like this:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
cache:
key: node_modules-${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
stages:
- test
test:
image: docker-builder-javascript
stage: test
before_script:
- npm install
script:
- npm test
I figured out that this was possible to solve by using the mount command straight in the before_script section, although this requires you to copy the source code over I managed to reduce the test time quite a lot.
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- test
test:
image: docker-builder-javascript
stage: test
before_script:
# Mount RAM filesystem to speed up build
- mkdir /rambuild
- mount -t tmpfs -o size=1G tmpfs /rambuild
- rsync -r --filter=":- .gitignore" . /rambuild
- cd /rambuild
# Print Node.js npm versions
- node --version
- npm --version
# Install dependencies
- npm ci
script:
- npm test
Since I'm now using the npm ci
command instead of npm install
I have no use of the cache anymore since it's clearing the cache at each run anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With