Gitlab CI失败并显示错误:作业失败:退出代码1

时间:2020-02-24 04:18:04

标签: docker gitlab gitlab-ci-runner

我对gitlab ci还是很陌生,我有一个项目,它具有预先存在的gitlab配置,运行正常,但是在进行了一些代码更改之后,它现在完全停止了工作,我不知道为什么。这是.gitlab-ci.yml

stages:
  - build
  - deploy

variables:
  DOCKER_HOST: tcp://localhost:2375

assets:
  stage: build
  image: node:10-alpine
  script:
    - npm ci
    - NODE_ENV=production npm run build
  artifacts:
    expire_in: 1 day
    paths:
      - public/assets
  tags:
    - docker

package:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    - php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    - php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    - php -r "unlink('composer-setup.php');"
  script:
    - composer install --prefer-dist --no-progress --optimize-autoloader --no-scripts
    - rm -fr .git
  artifacts:
    expire_in: 1 day
    paths:
      - .
  tags:
    - docker

docker:
  stage: deploy
  image: docker:latest
  services:
    - docker:18-dind
  dependencies:
    - assets
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:latest
  only:
    - master
  tags:
    - docker

deploy:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - curl -LO https://deployer.org/deployer.phar
    - mv deployer.phar /usr/local/bin/dep
    - chmod +x /usr/local/bin/dep
    - apk add --update openssh rsync
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan -t rsa domain.co.uk >> /root/.ssh/known_hosts
  script:
    - dep deploy -p --tag="$CI_COMMIT_TAG"
  only:
    - tags
  tags:
    - docker

我一直遇到以下错误,我想知道发生了什么变化,是否是服务器或gitlab-ci导致了以下问题。我检查了服务器,它运行正常,但是那里没有安装docker,并且我认为不应将docker安装在服务器上,以尝试执行该操作吗?

Checking out a50d58fd as master...
 Skipping Git submodules setup
Downloading artifacts for assets (447059035)...
00:01
 Downloading artifacts from coordinator... ok        id=447059035 responseStatus=200 OK token=cp4GCzgJ
$ docker build -t $CI_REGISTRY_IMAGE:latest .
00:02
 time="2020-02-24T03:53:41Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp [::1]:2375: connect: connection refused"
 error during connect: Post http://localhost:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=sja0dvuf6gm0w8tneigulo3ha&shmsize=0&t=registry.gitlab.com%2Fnir.npl%2Fbrayleys-honda%3Alatest&target=&ulimits=null&version=1: context canceled
 ERROR: Job failed: exit code 1

1 个答案:

答案 0 :(得分:2)

检查是否类似于this thread from a year ago

似乎docker更新了其最新的稳定映像,而gitlab尚未更新其运行程序,将映像更改为18个主要修复了这些问题,例如:

image: docker:18-git

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

services:
  - docker:18-dind

对于您而言,一年之后,该值为docker:19-dind,尤其是如果您使用的是image: docker:latest,这不是一个好习惯,因为“最新”可能随时变化。
image: docker:19-git是更可取的。