Docker ~ Hello TeamCity 🙌

Teepob Harutaipree
Bright Days
Published in
4 min readJan 9, 2021

--

Want to have you own TeamCity (server+agents) sandbox ? See how to setup the whole environment in 5 minute with docker !!

Things to cover:

  • Run Docker TeamCity image + docker-compose file
  • TeamCity Setup
  • SSH Keys on TeamCity Server to access GitHub repo

Spawning server:

docker run -dit --name server  \
-v ~/Desktop/teamcity/server/data:/data/teamcity_server/datadir \
-v ~/Desktop/teamcity/server/logs:/opt/teamcity/logs \
-p 8111:8111 \
jetbrains/teamcity-server

-v mount the volume of server data and logs into host disk
**Please make sure ~/Desktop/teamcity/server/data and ../logs exists !!

This will make sure server data/config persist on the disk

-p expose port 8111 to host

Navigate to http://localhost:8111

Accept terms and agreement and hit next.

Login with the previous credentials

On the top left menu Click dropdown > Add new Projects

Hit create Project

Enter Your Repository URL (github repo)

Spawning agent:

docker run -dit --name agents1 \
-v ~/Desktop/teamcity/agents1:/data/teamcity_agent/conf \
-e SERVER_URL=http://server:8111 \
--link server \
jetbrains/teamcity-agent

-v mount the volume of agents data and logs into host disk
**Please make sure ~/Desktop/teamcity/agents1 exists !!

-e set environment variable for the agent docker image to connect to the above server with the linked server url and expose port

--link will create alias of the network link to the server container we created earlier

Enable Agents

Click on the menu tab Agents > Unauthorized

Hit Authorize Connected Agent > Authorize

If you want to try the agent try Add new Build Configuration in your Project.

Try run some build on default branch

Optimize Run Command (Docker Compose)

  • We will run both containers : server and agents (start and stop) within one command using docker-compose

To start : copy the following scripts and paste into any working directory ./docker-compose.yml

The setting above is quite similar to the command we run earlier but now we save them in one place.

No try…

  • Run : inside same directory rundocker-compose up -d
  • Stop all the services run docker-compose down

If docker-compose command is not working you might need to install docker-compose first.

Running 2 agents : just create new folder agents2 inside ~/Desktop/teamcity and uncomment the whole agent2 part of docker-compose file

[Extra] SSH Keys to Access Git

  • First we need to generate the private and public keys then upload private key into Teamcity server project.
  • Then we copy the public key content inside Github repo.

Generate Keys

  • Generate using ssh-keygen

On prompt enter the filename (teamcity_deploy)

  • Leave password blank
ssh-keygen -t rsa -m PEM

Upload Key

Root Project > SSH Keys : Select the key to upload here
(Select: ~/.ssh/teamcity_deploy)

Add Keys

Copy the public key to clipboard using command:

pbcopy < ~/.ssh/teamcity_deploy.pub# Or use clip for windows git bash

We will need to paste the public key into your github repo:

Go to Repo URL Hit Settings

Click Deploy keys

Paste the copied key > Click Add Key

🎉 Hope you find your way to experiment some cool stuff on TeamCity.

Photo by Quinten de Graaf on Unsplash

References

--

--

Teepob Harutaipree
Bright Days