使用 Vagrant 配置 Gitlab CI VirtualBox Runner

使用 Vagrant 配置 Gitlab CI VirtualBox Runner

1)背景

我正在使用 Gitlab 的 VirtualBox 运行器(Gitlab 版本 10.6.3)运行构建管道。当我手动创建基础映像(例如my-base-vm)时,构建可以在1-nGitlab-CI 创建的克隆上完美运行。

2)观测误差

但是,当我想使用 Vagrant(版本 2.2.2)配置基础映像时,我的作业的 Gitlab CI 构建输出显示以下内容:

Running with gitlab-runner 11.2.0 (35e8515d)
  on myproject-build-machine 1c8ab769
Using VirtualBox version 5.2.18_Ubuntur123745 executor...
Creating new VM...
ERROR: Preparation failed: ssh: handshake failed: read tcp 127.0.0.1:35542->127.0.0.1:34963: read: connection reset by peer
Will be retried in 3s ...
Using VirtualBox version 5.2.18_Ubuntur123745 executor...
Creating new VM...
ERROR: Job failed: execution took longer than 1h0m0s seconds

该图像基于基础图像ubuntu/bionic64

3)配置

不过,运行器(从 克隆my-base-vm)似乎具有正确的 NAT 规则( 的输出VBoxManage showvminfo my-base-vm-runner-1c8ab769-concurrent-0):

NIC 1 Rule(0):   name = guestssh, protocol = tcp, host ip = 127.0.0.1, host port = 32805, guest ip = , guest port = 22
NIC 1 Rule(1):   name = ssh, protocol = tcp, host ip = 127.0.0.1, host port = 2222, guest ip = , guest port = 22

Gitlabconfig.toml配置了正确的用户名 + 密码(vagrant:vagrant),并且 Vagrant 文件规定机器接受用户名和密码作为身份验证方式(摘自Vagrantfile):

config.vm.provision "shell", inline: <<-SHELL
        sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/g' /etc/ssh/sshd_config
        sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
        service ssh restart
    SHELL

相关内容