我尝试在本地运行gitlab pipeline作业,以便进行测试和调试。下面是我所做的:
1.在本地机器上安装了gitlab-runner。
sudo gitlab-runner exec docker --docker-privileged --builds-dir /tmp/builds --docker-volumes /home/fox/Work/docker/core-application:/core-application Rspec
这给出:
Runtime platform arch=amd64 os=linux pid=632331 revision=8fa89735 version=13.6.0
Running with gitlab-runner 13.6.0 (8fa89735)
Preparing the "docker" executor
Using Docker executor with image docker:19.03.6 ...
Starting service docker:19.03.6-dind ...
Pulling docker image docker:19.03.6-dind ...
Using docker image sha256:a33335bfe8302f4d8a7688bc1fa539f2aba787ec724119be53adc4681702a3e7 for docker:19.03.6-dind with digest docker@sha256:a4f33d003b7ec9133c2a1ff61f4e80305b329c0fa8b753140b9ab2808f28328c ...
WARNING: Service docker:19.03.6-dind is already created. Ignoring.
Waiting for services to be up and running...
*** WARNING: Service runner--project-0-concurrent-0-aef5122f9d27e6f0-docker-0 probably didn't start properly.
Health check error:
service "runner--project-0-concurrent-0-aef5122f9d27e6f0-docker-0-wait-for-service" timeout
Health check container logs:
....
*********
Pulling docker image docker:19.03.6 ...
Using docker image sha256:6512892b576811235f68a6dcd5fbe10b387ac0ba3709aeaf80cd5cfcecb387c7 for docker:19.03.6 with digest docker@sha256:3eb67443c54436650bd4f1e97ddf9ab1797d75e15d685c791f6c6397edaa6d82 ...
Preparing environment
Running on runner--project-0-concurrent-0 via fox...
Getting source from Git repository
Fetching changes...
Initialized empty Git repository in /tmp/builds/project-0/.git/
Created fresh repository.
fatal: not a git repository: /home/fox/Work/docker/core-application/../.git/modules/core-application
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
ERROR: Failed to cleanup volumes
ERROR: Job failed: exit code 1
FATAL: exit code 1
然后我尝试在本地机器上使用gitlab-runner图像:docker run --name=runner --privileged -t --rm -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/.gitlab-runner/:/etc/gitlab-runner -v ${PWD}:${PWD} --workdir $PWD gitlab/gitlab-runner exec docker --builds-dir /tmp/builds/ Rspec
我得到:
Runtime platform arch=amd64 os=linux pid=7 revision=8fa89735 version=13.6.0
fatal: not a git repository: /home/fox/Work/docker/core-application/../.git/modules/core-application
WARNING: You most probably have uncommitted changes.
WARNING: These changes will not be tested.
fatal: not a git repository: /home/fox/Work/docker/core-application/../.git/modules/core-application
FATAL: exit status 128
下面是gitlab文档的内容:
如果你想在exec命令中使用docker executor,请在docker-machine shell或boot 2docker shell的上下文中使用。这是正确Map本地目录到Docker容器内目录所必需的。
我在谷歌上搜索了一下,但是没有关于docker+machine和gitlab-runner的结果。
有人能告诉我怎么做才正确吗?有没有样品?
谢谢。
2条答案
按热度按时间dddzy1tm1#
你必须从你的git repository/project的根文件夹执行命令:
你正在使用docker命令,这是不应该的,因为gitlab-runner已经在后台使用了这些命令。有关该命令的更多信息,请参阅
$ gitlab-runner exec docker --help
。2izufjch2#
我在远程容器和Docker Desktop(WSL 2)中使用VS Code时也遇到了类似的问题。
我通过添加一个
--pre-get-sources-script=ls -l "repo_directory"
来调试这个问题,即在OP的情况下:在我的例子中,目录列表(
ls -l ...
)显示为空!我假设它将目录作为卷挂载在容器中,并使用相同的名称(/fubar:/fubar
),在我的例子中,这不会起作用,因为它是带有vscode远程容器的Docker Desktop。我的解决方法是将我的命名卷作为参数添加到辅助目录,然后设置
--clone-url
指向该目录。比如:
我最初尝试将
--pre-get-sources-script
更改为cp -R /workspace2/fubar /workspace/
,但抱怨目标目录是只读的。使用--clone-url=file:///workspace2/fubar
工作,所以我保持这种方式。