用gitlab ci共享跑步者建立码头图像

时间:2016-12-06 18:16:09

标签: gitlab gitlab-ci

我在设置Gitlab CI以构建docker镜像并将其推送到Gitlab注册表时遇到了一些麻烦。我正在尝试使用Gitlab提供的共享运行器。从我所读过的内容来看,这应该是可能的,但是,无论我尝试什么,一旦构建到达任何“码头工人”,命令失败,显示以下消息:

  $ docker build --pull -t $CONTAINER_TEST_IMAGE .
/bin/bash: line 54: docker: command not found

我使用以下CI配置:

image: "ruby:2.3"

services:
  - docker:dind
  - postgres:latest

variables:
  POSTGRES_DB: test-db
  CONTAINER_TEST_IMAGE: registry.gitlab.com/pha3l/gitlab-ci-test-project:$CI_BUILD_REF_NAME
  CONTAINER_RELEASE_IMAGE: registry.gitlab.com/pha3l/gitlab-ci-test-project:latest

cache:
  paths:
    - vendor/ruby

stages:
  - build
  - test
  - release
  - deploy


before_script:
  - ruby -v                               
  - gem install bundler  --no-ri --no-rdoc  
  - bundle install -j $(nproc) --path vendor

rubocop:
  script:
  - rubocop

rails:
  variables:
    DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
  script:
  - bundle exec rake db:migrate
  - bundle exec rake db:seed
  - bundle exec rake test

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

release-image:
  stage: release
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
    - docker push $CONTAINER_RELEASE_IMAGE
  only:
    - master

deploy:
  stage: deploy
  script:
    - echo 'Do the deploy!'
  only:
    - master

1 个答案:

答案 0 :(得分:1)

似乎是这些行

services:
  - docker:dind

不要将docker二进制文件添加到您的图像中,只允许您在docker中运行docker。您可能必须基于ruby创建自己的映像:2.3并明确添加docker实用程序。 Dockerfile应如下所示:

FROM ruby:2.3
MAINTAINER maintaner

# install docker
RUN apt-get update && \
    apt-get install -y apt-transport-https ca-certificates gnupg2

RUN apt-key adv \
    --keyserver hkp://p80.pool.sks-keyservers.net:80 \
    --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main" | tee /etc/apt/sources.list.d/docker.list
RUN apt-get update && \
    apt-get install -y docker-engine