Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab: Mount /builds in build image as tmpfs

Tags:

gitlab

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
like image 660
tirithen Avatar asked Oct 31 '18 12:10

tirithen


1 Answers

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.

like image 191
tirithen Avatar answered Sep 29 '22 05:09

tirithen