Search code examples
dockernpmgitlabgitlab-cigitlab-ci-runner

How to have docker and npm in gitlab-ci-runner-docker


I am using gitlab-ci with docker:dind as a service.

problem

I am trying in Gitlab-CI run npm run build followed by docker build.

I am able this way to build using docker in docker this way:

This is my runner config.toml:

$ cat /etc/gitlab-runner/config.toml 
concurrent = 4
check_interval = 0

[[runners]]
  name = "developers_gitlab_school-gitlab-runner-docker"
  url = "https://school.domain.com"
  token = "cd09f40c6a4....a44751fec795e35"
  executor = "docker"
  builds_dir = "/mnt/mesos/sandbox/builds"
  cache_dir = "/mnt/mesos/sandbox/cache"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = true
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]

This is an example of .gitlab-ci.yml

image: docker:latest
# image: mcasimir/dind-node-build-runner:latest

variables:
  DOCKER_DRIVER: overlay2

services:
  - docker:dind

before_script:
  - docker info
  - docker --version
  - docker login -u ${REGISTRY_USERNAME} -p ${REGISTRY_PASSWORD} ${REGISTRY_URL}

stages:
  - build

# Job: Build
build_dev:
  stage: build
  script:
    - docker build -t group/mail-server/dev:${CI_JOB_ID} .
  only:
    - dev
  tags:
    - docker

build_master:
  stage: build
  script:
    - docker build -t domain/mail-server:${CI_JOB_ID} .
    - docker build -t domain/mail-server:latest .
  only:
    - master
  tags:
    - docker
  1. When I use an image with docker and npm for my build mcasimir/dind-node-build-runner:latest I have :

    Cannot connect to the Docker daemon. Is the docker daemon running on this host?. 
    
  2. When I use image docker:latest, docker-in-docker work fine but I still need npm.

question:

Because the Dockerfile of docker:latest is not public, and because I wasn't able to use apt-get from this image, I would like to know:

  • If there a way to have an image that can run docker and npm in gitlab-ci ?

Solution

  • Because it is an alpine-based image, you don't have apt-get, you have apk. So with the default docker:latest just add this apk --update add nodejs:

    before_script:
        - apk --update add nodejs npm
    

    And you are ready with dind, nodejs and npm.