Gitlab运行程序克隆在traefik之后的超时(相对路径)

时间:2019-03-21 01:04:16

标签: git docker gitlab gitlab-ci-runner traefik

我正在尝试获取 Gitlab 的实例在Traefik代理后面的相对路径(/ dev / git /)上运行。
Gitlab本身就像一个魅力,但是我对向项目添加Runner感到不走运。

Runner ist的注册成功,但是当它抢到工作时,克隆存储库失败,并显示超时错误

Cloning into '/builds/dev/git/root/ci-test'...
fatal: unable to access 'https://gitlab-ci- 
token:xxxxxxxxxxxxxxxxxxxx@SUBDOMAIN.DOMAIN.de/dev/git/root/ci-test.git/': Failed to connect to SUBDOMAIN.DOMAIN.de port 443: Operation timed out

Gitlab在https://SUBDOMAIN.DOMAIN.de/dev/git/下可用

Docker-Config “ docker-compose.yml”

version: "2.1"
services:
  proxy1:
    container_name: proxy1
    image: traefik:latest
    restart: always
    networks:
      - web
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /srv/docker/config/proxy1/acme.json:/acme.json
      - /srv/docker/config/proxy1/traefik.toml:/traefik.toml
    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.basic.frontend.rule=Host:SUBDOMAIN.DOMAIN.de;PathPrefixStrip:/traefik/"
      - "traefik.basic.port=8080"
      - "traefik.basic.protocol=http"
  gitlab1:
    container_name: gitlab1
    image: gitlab/gitlab-ce:latest
    restart: always
    networks:
      - web
    volumes:
      - /srv/docker/volumes/gitlab1/config:/etc/gitlab
      - /srv/docker/volumes/gitlab1/log:/var/log/gitlab
      - /srv/docker/volumes/gitlab1/data:/var/opt/gitlab
    labels:
      - "traefik.docker.network=web"
      - "traefik.enable=true"
      - "traefik.basic.frontend.rule=Host:SUBDOMAIN.DOMAIN.de;PathPrefix:/dev/git/"
      - "traefik.basic.port=80"
      - "traefik.basic.protocol=http"
  gitlab-runner1:
    container_name: gitlab-runner1
    image: gitlab/gitlab-runner:latest
    restart: always
    networks:
      - web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /srv/docker/volumes/runner1/config:/etc/gitlab-runner
networks:
  web:

Traefik配置“ traefik.toml”

debug = true

logLevel = "ERROR"
defaultEntryPoints = ["https", "http"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
  [entryPoints.https.tls]

[retry]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "SUBDOMAIN.DOMAIN.de"
watch = true
exposedByDefault = false

[acme]
email = "MAIL@EXAMPLE.de"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"

[api]
entryPoint = "traefik"
dashboard = true

Gitlab配置为在处理SSL的代理后面侦听HTTP。
Gitlab配置“ gitlab.rb”

external_url "https://SUBDOMAIN.DOMAIN.de/dev/git/"
nginx['redirect_http_to_https'] = true
nginx['listen_port'] = 80 
nginx['listen_https'] = false
nginx['proxy_set_headers'] = {
 "Host" => "$http_host",
 "X-Real-IP" => "$remote_addr",
 "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
 "X-Forwarded-Proto" => "https",
 "X-Forwarded-Ssl" => "on"
}

Gitlab-Runner配置“ config.toml”

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner1"
  url = "http://gitlab1/dev/git/"
  token = "TOKEN"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

如果您可以帮助我,那将是我的荣幸。我在互联网上搜索了很多内容,但找不到任何已经解决此问题的人。
非常感谢您的每一个回答。

1 个答案:

答案 0 :(得分:0)

我想出了一个解决方案:

正在gitlab-runner上运行的作业不会连接到web网络,而是连接到标准bridge网络。

所以我不得不重新配置gitlab运行程序,然后添加:

[[runners]]
url = "http://gitlab1/dev/git/"
clone_url = "http://gitlab1/dev/git/"
[runners.docker]
    network_mode = "docker_gitlab"
    privileged = true

docker_gitlab是网络的名称,我将其添加到上面的docker-compose文件中以连接gitlab和gitlab-runner。

新的docker-compose.yml

gitlab1:
  container_name: gitlab1
  image: gitlab/gitlab-ce:latest
  restart: always
  networks:
    - gitlab
    - web
  volumes:
    - /srv/docker/volumes/gitlab1/config:/etc/gitlab
    - /srv/docker/volumes/gitlab1/log:/var/log/gitlab
    - /srv/docker/volumes/gitlab1/data:/var/opt/gitlab
  hostname: SUBDOMAIN.DOMAIN.de
  labels:
    - "traefik.enable=true"
    - "traefik.docker.network=docker_web"
    - "traefik.port=80"
    - "traefik.backend=gitlab"
    - "traefik.frontend.rule=Host:SUBDOMAIN.DOMAIN.de;PathPrefix:/dev/git/"
gitlab-runner1:
  container_name: gitlab-runner1
  image: gitlab/gitlab-runner:latest
  restart: always
  networks:
    - gitlab
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /srv/docker/volumes/runner1/config:/etc/gitlab-runner
  links:
    - gitlab1
  labels:
    - "traefik.enable=false"