docker - Gitlab CI中的Docker执行程序被错误的URL传递给Git存储库

标签 docker gitlab-ci gitlab-ci-runner

我在内部服务器的http://gitlab.example.com之类的域上安装了Gitlab服务器。我还已经使用shell executor注册了一个运行程序,也使用docker executor注册了一个运行程序,它们都与Gitlab服务器在同一台机器上。

我有这个非常基本的.gitlab-ci.yml文件

runtest:
    script:
        - npm install

当我使用shell executor通过运行程序运行时,一切正常。存储库已 checkout ,并运行npm安装。

但是,当我通过配置为docker executor的运行器运行此文件时。我收到以下错误:
Running with gitlab-ci-multi-runner 9.4.2 (6d06f2e)
  on Test runner (fe943c63)
Using Docker executor with image node:6 ...
Using docker image 
sha256:81e132bdd65c157234d121b7c1743360c0d0d60f9bb6322f75ffa87c8f561ad8 for 
predefined container...
Pulling docker image node:6 ...
Using docker image node:6 
ID=sha256:3d258692b9fa0ba9568a891e1c702eee61d43e35286bec1b6fb0964700ca1dea for 
build container...
Running on runner-fe943c63-project-5-concurrent-0 via gitlab...
Cloning repository...
Cloning into '/builds/internal/boilerplate'...
fatal: repository 'http://example.com/internal/boilerplate.git/' not found
ERROR: Job failed: exit code 1

问题是,我的Gitlab服务器位于一个名为gitlab.example.com的子域上,并且运行程序尝试从http://example.com check out 代码。好像docker executor传递了错误的服务器url,因此无法正确 check out Git存储库。

我无法弄清楚为什么两个跑步者之间会有区别,以及在哪里配置Gitlab以为所有跑步者使用正确的git repo路径?

编辑:这是运行ps aux | grep gitlab的输出

git 373 1.5 9.5 657036 385916吗? Sl 13:08 0:04 unicorn worker [0] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb / opt / gitlab / embedded / service / gitlab-rails / config。 RU
gitlab- + 389 0.0 0.7 1121208 30444吗? Ss 13:08 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 406 0.0 0.5 1115624 23832吗? Ss 13:09 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 407 0.0 0.5 1116772 24104吗? Ss 13:09 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 409 0.0 0.6 1116852 24784吗? Ss 13:09 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 412 0.0 0.6 1117364 24644吗? Ss 13:09 0:00 postgres:gitlab gitlabhq_production [local]空闲
根615 0.0 0.0 4252 1120? SS 8月14日0:00运行vdir -P / opt / gitlab / service日志:.................................. ................................................... ................................................... ................................................... ............ $
根674 0.0 0.0 4100 644? SS 8月14日0:00 runsv gitlab-monitor
根680 0.0 0.0 4100 676? Ss Aug14 0:00 runsv gitlab-workhorse
根689 0.0 0.0 4244 1156? S Aug14 0:00 svlogd -tt / var / log / gitlab / prometheus
根707 0.0 0.0 4244 1236? S Aug14 0:00 svlogd -tt / var / log / gitlab / gitaly
根708 0.0 0.0 4244 1240? S Aug14 0:01 svlogd -tt / var / log / gitlab / gitlab-workhorse
根709 0.0 0.0 4244 1068 S Aug14 0:00 svlogd -tt / var / log / gitlab / unicorn
根710 0.0 0.0 4244 1228? S Aug14 0:00 svlogd -tt / var / log / gitlab / sidekiq
根711 0.0 0.0 4244 1064? S Aug14 0:00 svlogd -tt / var / log / gitlab / logrotate
根712 0.0 0.0 4244 696 S Aug14 0:00 svlogd -tt / var / log / gitlab / nginx
根713 0.0 0.0 4244 1216? S Aug14 0:00 svlogd -tt / var / log / gitlab / postgresql
根714 0.0 0.0 4244 1156? S Aug14 0:00 svlogd -tt / var / log / gitlab / redis-exporter
根715 0.0 0.0 4244 1128? S Aug14 0:00 svlogd -tt / var / log / gitlab / postgres-exporter
根716 0.0 0.0 4244 1228? S Aug14 0:00 svlogd -tt / var / log / gitlab / gitlab-monitor
根717 0.0 0.0 4244 1244? S Aug14 0:00 svlogd -tt / var / log / gitlab / node-exporter
根739 0.0 0.0 4244 1060? S Aug14 0:00 svlogd -tt / var / log / gitlab / redis
gitlab- + 1546 0.0 0.5 1115740 21052吗? Ss 13:14 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 1547 0.0 0.4 1114536 18512吗? Ss 13:14 0:00 postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 1548 0.0 0.4 1114884 19224吗? Ss 13:14 0:00 postgres:gitlab gitlabhq_production [local]空闲
srv 1565 0.0 0.0 0.0 12740 2248点/ 0 S + 13:14 0:00 grep gitlab
根27235 0.1 0.4 56260 20132? Ssl 12:30 0:03 / usr / bin / gitlab-ci-multi-runner run --working-directory / home / gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner
git 27266 0.0 0.3 130316 14280吗? Ssl 12:30 0:00 / opt / gitlab / embedded / bin / gitaly /var/opt/gitlab/gitaly/config.toml
git 27271 0.1 0.7 311376 32044吗? ssl 12:30 0:04 / opt / gitlab / embedded / bin / ruby​​ / opt / gitlab / embedded / bin / gitlab-mon web -c /var/opt/gitlab/gitlab-monitor/gitlab-monitor.yml
git 27274 0.0 0.3 228128 15244吗? Ssl 12:30 0:01 / opt / gitlab / embedded / bin / gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr / var / opt / gitlab / gitlab-workhorse / socket -authBackend http:// localhost:8080 -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -docum $
根27282 0.0 0.0 4340 1576? Ss 12:30 0:00 / bin / sh / opt / gitlab / embedded / bin / gitlab-logrotate-wrapper
根27288 0.0 0.1 42056 5532? SS 12:30 0:00 Nginx:主进程/ opt / gitlab / embedded / sbin / nginx -p / var / opt / gitlab / nginx
gitlab- + 27289 0.0 0.1 46688 7700吗? S 12:30 0:00 Nginx:工作进程
gitlab- + 27290 0.0 0.0 42260 3088? S 12:30 0:00 Nginx:缓存管理器进程
gitlab- + 27293 0.0 0.3 119656 14768? Ssl 12:30 0:01 / opt / gitlab / embedded / bin / node_exporter -web.listen-address = localhost:9100 -collector.textfile.directory = / var / opt / gitlab / node-exporter / textfile_collector
gitlab- + 27298 0.0 0.2 116904 11336? Ssl 12:30 0:00 / opt / gitlab / embedded / bin / postgres_exporter -web.listen-address = localhost:9187 -extend.query-path = / var / opt / gitlab / postgres-exporter / queries.yaml
gitlab- + 27305 0.0 1.2 1103620 52328吗? Ss 12:30 0:00 / opt / gitlab / embedded / bin / postgres -D / var / opt / gitlab / postgresql / data
gitlab- + 27307 0.0 0.7 1103736 29220? Ss 12:30 0:00 Postgres:检查指针过程
gitlab- + 27308 0.0 0.2 1103620 10880吗? Ss 12:30 0:00 Postgres:编写者进程
gitlab- + 27309 0.0 0.5 1103620 20664吗? Ss 12:30 0:00 Postgres:Wal编写器过程
gitlab- + 27310 0.0 0.1 1104192 6284? Ss 12:30 0:00 Postgres:自动清理启动程序
gitlab- + 27311 0.0 0.0 31808 3952吗? Ss 12:30 0:00 Postgres:统计信息收集程序
gitlab- + 27314 0.2 1.4 370924 59220? Ssl 12:30 0:05 / opt / gitlab / embedded / bin / prometheus -web.listen-address = localhost:9090 -storage.local.path = / var / opt / gitlab / prometheus / data -storage.local.chunk -encoding-version = 2 -storage.local.target-heap-size = 109384826 -config.file = / var / opt / gitlab $
gitlab- + 27323 0.4 0.1 41556 5648吗? SSL 12:30 0:12 / opt / gitlab / embedded / bin / redis-server 127.0.0.1:0
gitlab- + 27328 0.0 0.2 39396 10968? Ssl 12:30 0:00 / opt / gitlab / embedded / bin / redis_exporter -web.listen-address = localhost:9121 -redis.addr = unix:///var/opt/gitlab/redis/redis.socket
git 27333 1.7 9.7 714348 396880吗? Ssl 12:30 0:46 sidekiq 5.0.0 gitlab-rails [0 of 25繁忙]
git 27357 0.0 0.0 20124 2956吗? Ss 12:30 0:00 / bin / bash / opt / gitlab / embedded / bin / gitlab-unicorn-wrapper
git 27376 0.5 7.8 577152 320180吗? Sl 12:30 0:14 unicorn主站-D -E生产-c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
gitlab- + 27382 0.0 0.4 1115236 18844吗? Ss 12:30 0:01 postgres:gitlab-psql postgres [local]空闲
git 27485 0.4 9.9 687964 405976吗? Sl 12:31 0:10 unicorn worker [1] -D -E生产-c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb / opt / gitlab / embedded / service / gitlab-rails / config。 RU
gitlab- + 27517 0.0 0.9 1130316 39788? Ss 12:31 0:00 Postgres:gitlab gitlabhq_production [local]空闲
gitlab- + 30455 0.0 0.6 1117852 26280? Ss 12:50 0:00 postgres:gitlab gitlabhq_production [local]空闲

最佳答案

这是由运行程序上的网络设置引起的。在主机和docker executor之间自动设置的网桥位于本地网络“外部”。因此,docker容器无法看到url gitlab.example.com

我通过添加解决了

network_mode = "host"

到docker运行程序的config.toml。

这样,运行程序便与主机共享相同的网络,从而拥有所需的访问权限。

关于docker - Gitlab CI中的Docker执行程序被错误的URL传递给Git存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45671274/

相关文章:

android - Gitlab CI :- How to create the Shared Runner in Gitlab which does not depend on the any system?

inheritance - 在 GitLab CI 中使用 `extends` 时,哪些作业属性会被合并或覆盖?

gitlab-ci - 如何向 .gitlab-ci.yaml 文件添加注释?

nexus - 将 Gitlab CI.Runner 构建的包推送到 Nexus 存储库

linux - GitLab-Runner "listen_address not defined"错误

docker - docker 中 Windows 上的 gitlab-runner 无法运行,出现错误的 OSType 错误

windows - Golang Docker容器无法在Windows Home上启动

Docker 在容器中监听,但在外部不应答,为什么?

docker - 无法在 Kubernetes 中的 Grafana 仪表板中获取 Prometheus 数据

bash - 如何使用 docker-compose 环境变量来填充配置文件