我们在本地 TeamCity 服务器上使用 2017.1.5(内部版本 47175),并使用适用于 ubuntu 的最新 teamcity-docker-agent。
启动 teamcity-docker-agent 时我们添加:
-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker
使 docker 在容器内可用。
在 docker 容器中运行示例 gradle 构建时,由于权限问题,无法运行 /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh。
有人在 teamcity-docker-agent 中使用 docker 时没有出现这些问题吗?
root@99decd9a0703:/# ll /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
-rw-r--r-- 1 root root 225 Oct 18 06:08 /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
构建日志:
[06:08:17][Step 1/1] Starting: /bin/sh -c docker pull openjdk && docker run --rm -w /opt/buildagent/work/472d663c385d6aef -v /opt/buildagent/work/472d663c385d6aef:/opt/buildagent/work/472d663c385d6aef -v /opt/buildagent/temp/agentTmp:/opt/buildagent/temp/agentTmp -v /opt/buildagent/temp/buildTmp:/opt/buildagent/temp/buildTmp -v /opt/buildagent/system:/opt/buildagent/system -v /opt/buildagent/lib:/opt/buildagent/lib:ro -v /opt/buildagent/tools:/opt/buildagent/tools:ro -v /opt/buildagent/plugins:/opt/buildagent/plugins:ro --env-file /opt/buildagent/temp/agentTmp/docker-wrapper-3086677386325386164.env --entrypoint /bin/sh openjdk /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
[06:08:17][Step 1/1] in directory: /opt/buildagent/work/472d663c385d6aef
[06:08:17][Step 1/1] Using default tag: latest
[06:08:19][Step 1/1] latest: Pulling from library/openjdk
[06:08:19][Step 1/1] Digest: sha256:9745ed74401b23fb845b4eb7ae07ecb7dc2d40bece6bdb089975a20f76766401
[06:08:19][Step 1/1] Status: Image is up to date for openjdk:latest
[06:08:20][Step 1/1] /bin/sh: 0: Can't open /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
[06:08:20][Step 1/1] Process exited with code 127
[06:08:20][Step 1/1] Process exited with code 127
[06:08:20][Step 1/1] Step Gradle failed
我也遇到过类似的问题。这就是我目前(2017 年 3 月)正在做的事情。
<brackets>
中的项目应替换为您的相关信息,并且实际上不应在您的终端请求中包含括号。 (即将 AGENT_NAME="<your-new-tcagent-container-name>"
替换为 AGENT_NAME="my-agent-container"
为了便于阅读,我添加了换行符。在粘贴到终端之前,您应该删除换行符。
您还需要确保在 Docker > 首选项 > 文件共享中的 Docker 文件共享中列出了这些目录:
/Users
、/Volumes
、/private
和/tmp
docker run -it --name <your-new-tcAgent-CONTAINER-name>
-e SERVER_URL="<your-local-tcServer-CONTAINER-name>:8111"
-e AGENT_NAME="<your-new-tcAgent-name-to-appear-in-tcserver>"
-v /var/run/docker.sock:/var/run/docker.sock
-v /opt/buildagent/work:/opt/buildagent/work
-v /opt/buildagent/temp:/opt/buildagent/temp
-v </where/you/wanna/store/local/configs>:/data/teamcity_agent/conf
--link <your-local-tcServer-container-name>
<name-of-tcAgent-IMAGE-you-are-using>
这个想法是给予代理权限而不是挂载数据目录。
以下组合创建服务器和代理,设置目录并提供本地IP。
compose.yml
name: tdd
services:
tc-server:
image: jetbrains/teamcity-server
container_name: tc-server
volumes:
- $HOME/Projects/teamcity/server/data:/data/teamcity_server/datadir
- $HOME/Projects/teamcity/server/logs:/opt/teamcity/logs
ports:
- "8111:8111"
environment:
- TEAMCITY_SERVER_OPTS=-Dteamcity.startTmsInBackground=true
restart: always
tc-agent-1:
image: jetbrains/teamcity-agent:2024.07.2-linux-arm64-sudo
container_name: tc-agent-1
environment:
- SERVER_URL=http://192.168.1.24:8111
- DOCKER_IN_DOCKER=start
volumes:
- $HOME/Projects/teamcity/agents/agent-1/config:/data/teamcity_agent/conf
privileged: true
restart: always
tc-agent-2:
image: jetbrains/teamcity-agent:2024.07.2-linux-arm64-sudo
container_name: tc-agent-2
environment:
- SERVER_URL=http://192.168.1.24:8111
- DOCKER_IN_DOCKER=start
volumes:
- $HOME/Projects/teamcity/agents/agent-2/config:/data/teamcity_agent/conf
privileged: true
restart: always
以分离模式运行
docker compose up -d;