Gitlab CI-运行程序-如何在同一服务器上配置多个docker executor

时间:2020-07-03 16:49:17

标签: docker docker-compose gitlab gitlab-ci-runner

我试图在同一台服务器(D.O.云)上基于docker设置两个不同的环境,一次用于登台,一次用于生产。

两个环境脱离了进程,并且已将部署分配给gitlab ci / cd管道。

我的目标是在同一台服务器上运行两个不同的ci管道,一次用于登台,一次用于生产

一开始我的conf是一个与docker executor赛跑的人,但我通知在管道执行后(无论是来自暂存还是生产标签),只有一个env仍然存在。

正如我提到的,我的目标是同时启用两个环境,然后我想注册一个新的运行器,以便为一个环境(和标签)映射一个运行器。

两个都拥有docker executor的跑步者。

这是我的最后配置

.gitlab.ci.yml

image: tmaier/docker-compose:latest

stages:
  - deploy-on-staging
  - deploy-on-prod

services:
  - docker:dind
  

before_script:
  - docker info
  - docker-compose --version

#job runs automatically for tags:staging
step-staging:
  stage: deploy-on-staging
  environment:
    name: staging  # must match the vars env 
    url: staging.mysite.com$STAGING_HTTP_PORT
  only:
    - staging
  tags:
    - staging
  script:
    - docker-compose -f docker/remote/docker-compose.yml -f docker/remote/docker-compose.staging.yml up -d 
  after_script:
    - docker exec -i mysql_staging sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/db.sql'
    - docker exec mysql_staging sh -c 'exec mysql -u gu -p"$MYSQL_PASSWORD" -D dbname < /opt/somequeries.sql'

#job runs automatically for tags:production
step-prod:
  stage: deploy-on-prod
  environment:
    name: production # must match the vars env  
    url: mysite.com
  only:
    - master
  tags:
    - production
  script:
    - docker-compose -f docker/remote/docker-compose.yml -f docker/remote/docker-compose.override.yml up -d
  after_script:
    - docker exec -i mysql_prod sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/db.sql'
    - docker exec mysql_prod sh -c 'exec mysql -u gu -p"$MYSQL_PASSWORD" -D dbname < /opt/somequeries.sql'
  when: manual

config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner"
  url = "https://gitlab.com"
  token = "xxxxxxxxxxxxxxxxxxxx"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache", "/builds:/builds"]
    shm_size = 0
    memory = "128m"
    memory_swap = "256m"
    memory_reservation = "128m"

[[runners]]
  name = "staging_runner"
  url = "https://gitlab.com"
  token = "xxxxxxxxxxxxxxxxxxxx"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache", "/builds:/builds"]
    shm_size = 0
    memory = "128m"
    memory_swap = "256m"
    memory_reservation = "128m"

我尚未达到目标。另外,现在登台管道会给我这样的错误

error during connect: Get [http://docker:2378/v1.40/containers/mysql_staging/json:](http://docker:2378/v1.40/containers/mysql_staging/json:) dial tcp: lookup docker on XX.XXX.XX.X:53: no such host

我的设计是否正确才能达到目标?

如果是,我是否配置有误?

预先感谢您的帮助。

0 个答案:

没有答案