6

I'm trying to build my project using gitlab ci feautures. According to this question I've done everything correcly. This is my .gitlab-ci.yml.

.gitlab-ci.yml

image: docker:latest

services:
  - docker:dind

stages:
  - build
  - release
  - deploy

variables:
  DOCKER_DRIVER: overlay
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"

cache:
  paths:
    - .m2/repository/
    - auth/target/

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

build:
  image: maven:latest
  stage: build
  script:
      - mvn $MAVEN_CLI_OPTS package

auth-release:
  stage: release
  when: on_success
  script:
    - docker build -f auth/Dockerfile -t "$CI_REGISTRY/$CI_PROJECT_PATH/auth" ./auth
    - docker push "$CI_REGISTRY/$CI_PROJECT_PATH/auth"

But console prints out an error:

Console output

Running with gitlab-runner 11.7.0-rc1 (6e20bd76)
  on docker-auto-scale ed2dce3a
Using Docker executor with image maven:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:067814781fbba30c17a86aa6159516660b6c210485ac9ac346d5101d6e4b70f0 for docker:dind ...
Waiting for services to be up and running...
Pulling docker image maven:latest ...
Using docker image sha256:3bc97dc2e7ba13887f5a850968419ad0e83fc482acd1cf0d9606882b665e39f3 for maven:latest ...
Running on runner-ed2dce3a-project-10090201-concurrent-0 via runner-ed2dce3a-srm-1547629674-aa23c547...
Cloning repository...
Checking out 10c9202f as master...
Skipping Git submodules setup
Checking cache for default...
FATAL: file does not exist                         
Failed to extract cache
$ docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
/bin/bash: line 76: docker: command not found
ERROR: Job failed: exit code 1

What am I doing wrong?

nllsdfx
  • 900
  • 14
  • 30

1 Answers1

4

You are confusing your build stages.

According to your log, you fail on build stage, which is executed using maven:latest image, as it is written in your yaml.

But you also have your before_script:

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

So, this script tries to execute on maven image and fails, because maven image does not have docker inside. Probably, you wanted to execute your before_script only for auth-release stage - it will work there, because auth-release uses docker:latest image, which in turn contains docker executable.

You are probably confused with your docker:dind service thinking it will provide you docker CLI in all images - that's not working so. docker:dind service provides you with docker daemon, but you still need docker CLI installed in all your images to interact with service.

grapes
  • 8,185
  • 1
  • 19
  • 31