1

I'm currently facing a problem with the gitlab.com shared-runners. What I'm trying to archieve in my pipeline is:
- NPM install and using grunt to make some uncss, minimize and compress tasks
- Cleaning up - Building a docker container with the app included
- Moving the container to gitlab registry

Unfortunateley I don't get it running since a long time! I tried a lot of different gitlab.ci configs - without success. The problem is, that I have to use the "image: docker:latest" to have all the docker-tools running. But then I don't have node and grunt installed in the container.
Also the other way around is not working. I was trying to use image: centos:latest and install docker manually - but this is also not working as I always just get a Failed to get D-Bus connection: Operation not permitted
Does anyone has some more experience on the gitlab-ci using docker build commands in a docker shared runner?
Any help is highly appreciated!!

Thank you
Jannik

1 Answer 1

2

Gitlab can be a bit tricky :) I dont have an example based on CentOS, but I have one based on Ubuntu if that helps you. Here is some copy paste of a working gitlab pipeline of mine which uses gulp (you should be easily able to adjust it to work with your grunt).

The .gitlab-ci.yml looks like this (adjust the CONTAINER... variables at the beginning):

variables:
  CONTAINER_TEST_IMAGE: registry.gitlab.com/psono/psono-client:$CI_BUILD_REF_NAME
  CONTAINER_RELEASE_IMAGE: registry.gitlab.com/psono/psono-client:latest

stages:
  - build

docker-image:
  stage: build
  image: ubuntu:16.04
  services:
    - docker:dind
  variables:
    DOCKER_HOST: 'tcp://docker:2375'
  script:
    - sh ./var/build-ubuntu.sh
    - docker info
    - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" registry.gitlab.com
    - docker build -t $CONTAINER_TEST_IMAGE .
    - docker push $CONTAINER_TEST_IMAGE

in addition i have a this "./var/build-ubuntu.sh" which you can adjust a bit according to your needs, replace some ubuntu dependencies or switch gulp for grunt as needed:

#!/usr/bin/env bash
apt-get update && \
apt-get install -y libfontconfig zip nodejs npm git apt-transport-https ca-certificates curl openssl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -  && \
add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable" && \
apt-get update && \
apt-get install -y docker-ce && \
ln -s /usr/bin/nodejs /usr/bin/node && \
npm install && \
node --version && \
npm --version
Sign up to request clarification or add additional context in comments.

6 Comments

Hi! Thank you for the fast answer. I was using ubuntu image and docker:dind under services - But still no success :( Every task concerning node is working but the moment I want to use docker-tools I get this answer: /bin/bash: line 59: docker: command not found What am I doing wrong? why is it working for you? :(
Glad I could help.
Give me a second, I can reproduce the problem.
Ok, I have upated my answer with something that works. Its a little bit "brute force" but does the trick.
seems like you are a real genius! I was trying and trying since weeks to get this running .. I never thought that my use-case is so "unusual" .. Anyhow, thank you very much for the fast and correct answer!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.