首页 文章

Gitlab CI与docker-compose

提问于
浏览
0

有一个项目https://github.com/codeship-library/nodejs-express-todoapp

我需要做的是使用docker在Gitlab中实现一个管道并查看应用程序以获取任何分支的链接,如http://feature_ * . $ projectname.example.com . 此外,每个构建都应该放在本地docker注册表中(它已经配置好) .

如果我的方向错误,请给出提示 . 哪个跑步者应该使用“shell”或“docker”?

这些配置使用shell runner运行一次,但后来我开始获得权限问题,我认为当git正在进行清理时 .

实现这个的最佳方法是什么?

.gitlab-ci.yml

image: node:7.7.2-alpine

stages:
  - build
  - test
  - review
  - deploy

variables:
  TEST_IMAGE: registry.gitlab.example.com:4567/root/nodejs-express-todoapp:$CI_COMMIT_REF_NAME

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

build:
  stage: build
  script:
    - echo "BUILD"
    - docker-compose build
    - docker-compose push

test:
  stage: test
  script:
    - echo "TEST"
  allow_failure: true

review:
  stage: review
  script:
    - echo "REVIEW"
  when: manual

deploy_dev:
  tags:
    - dev
  stage: deploy
  script:
    - echo "DEPLOY"
    - docker-compose up -d
  environment:
    name: dev
    url: http://$CI_COMMIT_REF_NAME.$CI_PROJECT_NAME.$GITLAB_USER_LOGIN.projects.example.com:3000
  only:
  - branches

undeploy_dev:
  tags:
    - dev
  stage: deploy
  script:
    - docker-compose stop
  when: manual
  environment:
    name: dev
    action: stop

Dockerfile

FROM node:7.7.2-alpine

WORKDIR /usr/app

RUN apk update && apk add postgresql

COPY package.json .
RUN npm install --quiet

COPY . .

泊坞窗,compose.yml

version: '3'
services:
  web:
    build: .
    command: npm run dev
    volumes:
    - .:/usr/app/
    - /usr/app/node_modules
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    environment:
      DATABASE_URL: postgres://todoapp@postgres/todos
    image: registry.gitlab.example.com:4567/root/nodejs-express-todoapp

  postgres:
    image: healthcheck/postgres:alpine
    environment:
      POSTGRES_USER: todoapp
      POSTGRES_DB: todos

1 回答

  • 0

    如果是你的跑步者, dockerdocker-in-docker 服务(dind),这是最好的选择 .

    您需要拥有跑步者,因为您需要激活 privileged 模式 .

    为此,在您的跑步者的 config.toml 中,在 runners.docker 配置中插入 privileged = true .

    [[runners]]
      [runners.docker]
        privileged = true
    

    By enabling privileged, you are effectively disabling all of the security mechanisms of containers and exposing your host to privilege escalation which can lead to container breakout.

    无论如何,对于其他方式,请参阅公共文档 . 无论如何,我建议你阅读它,它有很多有用的信息!

    https://docs.gitlab.com/ce/ci/docker/using_docker_build.html

相关问题