Gitlab - 在docker共享的跑步者

时间:2016-09-22 12:21:21

标签: gitlab gitlab-ci gitlab-ci-runner gitlab-8

尝试使用共享运行器构建docker镜像,下面是CI配置

image: osrg/dind-ubuntu-vivid

services:
  - docker:dind

stages:
    - build
    - test
    - release

variables:
  CONTAINER_TEST_IMAGE: registry.gitlab.com/somasundaramsekar/ci-test:$CI_BUILD_REF_NAME
  CONTAINER_RELEASE_IMAGE: registry.gitlab.com/somasundaramsekar/ci-test:latest

before_script:
  - apt-get update -y >/dev/null 2>&1
  - apt-get install -y --fix-missing software-properties-common python-software-properties >/dev/null 2>&1
  - apt-get update -y >/dev/null 2>&1
  - apt-get install -y openjdk-8-jdk >/dev/null 2>&1
  - apt-get install apt-transport-https -y >/dev/null 2>&1
  - wget www.scala-lang.org/files/archive/scala-2.11.7.deb >/dev/null 2>&1
  - dpkg -i scala-2.11.7.deb >/dev/null 2>&1
  - scala -version
  - echo "deb https://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
  - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823 >/dev/null 2>&1
  - apt-get update >/dev/null 2>&1
  - apt-get install -y sbt >/dev/null 2>&1
  - wget https://downloads.typesafe.com/typesafe-activator/1.3.10/typesafe-activator-1.3.10.zip >/dev/null 2>&1
  - apt-get install -y unzip >/dev/null 2>&1
  - unzip typesafe-activator-1.3.10.zip >/dev/null 2>&1
  - export ACTIVATOR_HOME="$(pwd)/activator-dist-1.3.10"
  - export PATH=$PATH:$ACTIVATOR_HOME/bin
  - service docker start
  - docker ps
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com

build:
  stage: build
  script:
    - sbt clean compile


test:
  stage: test  
  script:
    - sbt clean coverage test coverageReport

release:
    stage: release
    script:
     - activator dist
     - docker build --pull -t $CONTAINER_TEST_IMAGE .
     - docker push $CONTAINER_TEST_IMAGE 


But when the job runs it fails like below
 * Starting Docker: docker
   ...done.
$ docker ps
Get http:///var/run/docker.sock/v1.19/containers/json: dial unix /var/run/docker.sock: no such file or directory. Are you trying to
     

连接到没有TLS的启用TLS的守护程序?       错误:构建失败:退出代码1

在我的本地使用相同的基本泊坞窗图片尝试docker psservice docker start

我想打包应用程序并在同一个作业中创建docker镜像,感谢任何帮助

1 个答案:

答案 0 :(得分:0)

为每个阶段使用不同的图像,在您的情况下使用{{1}}进行构建和测试,并使用dind服务在发布阶段使用docker镜像。请检查此thread