Last active
December 25, 2019 07:31
-
-
Save NewbMiao/b494bf080a764321811fadb3b384f2e2 to your computer and use it in GitHub Desktop.
For teamcity local test(support docker in agent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# For teamcity local test(support docker in agent) | |
homeDir=$(env | grep ^HOME= | cut -d '=' -f2) | |
TC_DIR=$homeDir/teamcity | |
TC_NAME_PREFIX=teamcity-server- | |
TC_AGENT_NAME=${TC_NAME_PREFIX}agent | |
TC_SERVER_NAME=${TC_NAME_PREFIX}instance | |
action=$1 | |
case $action in | |
"server" ) | |
echo "start server: $TC_SERVER_NAME in background, use logServer to see log\n(see more in https://hub.docker.com/r/jetbrains/teamcity-server/)" | |
serverCID=$(docker ps -a|grep $TC_SERVER_NAME|cut -d ' ' -f1) | |
[ "$serverCID" != "" ] && docker start $TC_SERVER_NAME && echo "container exist just use it" && exit 0 | |
echo "Gonna use dir: $TC_DIR to mount for teamcity..." | |
docker run -d --name $TC_SERVER_NAME \ | |
-v $TC_DIR/data:/data/teamcity_server/datadir \ | |
-v $TC_DIR/logs:/opt/teamcity/logs \ | |
-p 8111:8111 \ | |
jetbrains/teamcity-server | |
;; | |
"agent" ) | |
echo "start agent:$TC_AGENT_NAME in background, use logAgent to see log\n(see more in https://hub.docker.com/r/jetbrains/teamcity-agent/)" | |
agentCID=$(docker ps -a|grep $TC_AGENT_NAME|cut -d ' ' -f1) | |
[ "$agentCID" != "" ] && docker start $TC_AGENT_NAME && echo "container exist just use it" && exit 0 | |
echo "Gonna use dir: $TC_DIR to mount for teamcity..." | |
LIP=$(ifconfig | grep inet | grep -v inet6 | grep -v 127 | cut -d ' ' -f2|head -n1) | |
echo "get local ip: $LIP" | |
docker start $TC_AGENT_NAME || \ | |
docker run -d --name $TC_AGENT_NAME -e SERVER_URL="http://$LIP:8111" \ | |
-v $TC_DIR/agent_conf:/data/teamcity_agent/conf \ | |
-v $TC_DIR/docker_volumes:/var/lib/docker \ | |
--privileged -e DOCKER_IN_DOCKER=start \ | |
jetbrains/teamcity-agent | |
;; | |
"stop" ) | |
tContainers=$(docker ps |grep $TC_NAME_PREFIX) | |
[ "$tContainers" = "" ] && echo "already stoped." && exit 0 | |
echo "Gonna stop container:\n"$tContainers | |
docker stop $(docker ps |grep $TC_NAME_PREFIX|cut -d ' ' -f1) | |
;; | |
"logServer" ) | |
echo "Gonna show log in server..." | |
serverCID=$(docker ps|grep $TC_SERVER_NAME|cut -d ' ' -f1) | |
[ "$serverCID" != "" ] && docker logs -ft $serverCID | |
;; | |
"logAgent" ) | |
echo "Gonna show log in agent..." | |
agentCID=$(docker ps|grep $TC_AGENT_NAME|cut -d ' ' -f1) | |
[ "$agentCID" != "" ] && docker logs -ft $agentCID | |
;; | |
"commit" ) | |
echo "Gonna commit server..." | |
serverCID=$(docker ps -a|grep $TC_SERVER_NAME|cut -d ' ' -f1) | |
[ "$serverCID" != "" ] && docker commit -m "local teamcity server" $serverCID jetbrains/teamcity-server | |
echo "Gonna commit agent..." | |
agentCID=$(docker ps -a|grep $TC_AGENT_NAME|cut -d ' ' -f1) | |
[ "$agentCID" != "" ] && docker commit -m "local teamcity server" $agentCID jetbrains/teamcity-agent | |
;; | |
* ) | |
echo "Unknown command, Available commands: server, agent, stop, logServer, logAgent, commit" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment