https://github.com/twogg-git/ci-teamcity
  
  
    A setup tutorial to work with Java + TeamCity + Docker  
    https://github.com/twogg-git/ci-teamcity
  
docker maven teamcity testing-tools travis-ci-configuration
        Last synced: 2 months ago 
        JSON representation
    
A setup tutorial to work with Java + TeamCity + Docker
- Host: GitHub
 - URL: https://github.com/twogg-git/ci-teamcity
 - Owner: twogg-git
 - Created: 2018-01-22T19:49:41.000Z (almost 8 years ago)
 - Default Branch: master
 - Last Pushed: 2023-03-03T11:38:26.000Z (over 2 years ago)
 - Last Synced: 2025-03-23T02:01:52.580Z (8 months ago)
 - Topics: docker, maven, teamcity, testing-tools, travis-ci-configuration
 - Language: Java
 - Size: 5.32 MB
 - Stars: 0
 - Watchers: 0
 - Forks: 2
 - Open Issues: 4
 - 
            Metadata Files:
            
- Readme: README.md
 
 
Awesome Lists containing this project
README
          
## CI with Java, TeamCity, and Dokcer
[](https://travis-ci.org/twogg-git/ci-teamcity)
### Java REST App
Here is the Docker command to run the java app with a Tomcat 8.0 server. Please take care that we have to use Java 1.7 because of this specifical Tomcat version. I added the .war copy command to deployed automatically. 
```sh
docker run --rm -v /your_path/ci-teamcity/target/ci-teamcity.war:/usr/local/tomcat/webapps/ci-teamcity.war -it -p 8585:8080 --name=tomcat tomcat:8.0
```
If you need to check the deployment, logs, or setup of Tomcat container use this command:
```sh
docker exec -it tomcat /bin/bash
```
Test the app going to:
```sh
http://localhost:8585/ci-teamcity
```
I added two more rest services a dummy hello call */ci-teamcity/hello* and a test/id validation */ci-teamcity/test/1*.
### TeamCity Server 
First create two folders */data* and */logs* to storage what TC needs. This image will take a while to download (current local size used: 1.52GB).
```sh
docker run -it --name tcserver -v /your_path/teamcity/data:/data/teamcity_server/datadir -v /your_path/teamcity/logs:/opt/teamcity/logs -p 8111:8111 jetbrains/teamcity-server
```
I'm using the internal HSQLDB database provided by the image to avoid futher setup, if you have time use an external option!
To test and start TeamCity go to:
```sh
http://localhost:8111
```
### TeamCity Agent 
There is two version for agents standar and minimal, I used the standard one, you can try with the minimal both will work fine. The standard version is a heavy image to download, so be patient (current local size used: 1.03GB).
```sh
docker run --name tcagent -it -e SERVER_URL="your_ip:8111" -p 9090:9090 -v /your_path/teamcity/agent:/data/teamcity_agent/conf jetbrains/teamcity-agent
```
TeamCity Agents will not work with *localhost* as SERVER_URL, so please use your IP. If you need to change your IP or your network connection, don't forget to update the *serverUrl* inside buildAgent.properties then restart the docker.
```sh
docker start tcagent
```
#### Adding agents to the server
For the final step, you have to authorize manually your local agent here:
```sh
http://localhost:8111/agents.html?tab=unauthorizedAgents
```
## TeamCity Setup
### Create a new project
You can build from an URL, GitHub, Bitbucket, VisualStudioTeam, and a manually configurated repository. Here we are going to use GitHub. You will we asked to connect with your account, then select the repository. It's possible to build the same code in different TeamCity projects, for example master and QA branches. After you select the repository, you need to setup the  build steps. 
### Clean-Test
With this setup it will being executed the unit test configured in the source and by the configuration in the pom.xml file. I'm using Junit 4.12 version.

### Package
After being successfully executed the test, we create a .war file to be deployed. 

You can access the artifact created in the overview page. 

### Deploy
In the new version of TeamCity is possible to deploy the artifact created or the result of a previous step. Here we are setting up a deploy in a Tomcat container running locally. 

### Local Tomcat container
To deploy locally, we are going to use the same Tomcat 8.0 image from the beginning, but adding context and user setup. Go to */tomcat* folder and then build the Dockerfile.
```sh
docker build -t twogg/tomcat .
```
Now run the container, we are using admin/admin as user and password, and 8787 is going to be our deploy port for TeamCity.
```sh
docker run -d -p 8787:8080 --name tctomcat twogg/tomcat
```
Test the new artifact in: 
```sh
http://localhost:8787/ci-teamcity
```