How to configure a Docker container with a TeamCity server and Advanced Installer - Advanced Installer Community
Catalin
Posts: 7847
Joined: Wed Jun 13, 2018 7:49 am

How to configure a Docker container with a TeamCity server and Advanced Installer

Hello,

The ideea for this article started from the following thread:

TeamCity Agent getting stuck building Installer

Since I was not well versed into docker containers and since I spent quite some time investigating the customer's issue, I decided to make a how-to here, just in case anyone ever stumbles upon this scenario.

That being said, this guide is for anyone who has never used Docker before and wants to get a working TeamCity server and build agent running Advanced Installer.

By trying to keep this relatively short, I will not go into many details as to what Docker is, what a TeamCity server is, etc.

Instead, let's get rolling!

We'll be using PowerShell for most commands here.

The first step is to search for PowerShell and open that as administrator.

1. turn on the Windows Containers support

Code: Select all

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
Note: if prompted to restart, please go ahead and do so.

2. switch Docker Desktop to Windows Containers

By default, Docker Desktop runs Linux containers, so we need to change that over to Windows.

Look for the Docker Desktop icon in your system tray (bottom right of your screen, near the clock). Right click it and choose "Switch to Windows containers". Give it a minute, as Docker needs to restart its' engine to make the switch.

We can then check if it switched by running the following command:

Code: Select all

docker version
The result of that should be: windows/amd64

3. create a folder that we'll work in

We'll create the following folder structure:
teamcity-docker/
├── docker-compose.yml
├── Teamcity-Server/
│ ├── Dockerfile
│ └── advinst.msi
└── Teamcity-Agent/
└── Dockerfile
In PowerShell, run the following:

Code: Select all

mkdir C:\teamcity-docker\Teamcity-Server
mkdir C:\teamcity-docker\Teamcity-Agent
cd C:\teamcity-docker
and then:

Code: Select all

New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-server\data"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-server\logs"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-agent\conf"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-agent\system"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-agent\work"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-agent\output"
New-Item -ItemType Directory -Force -Path "C:\TeamCity\teamcity-agent\projects"
4. copy Advanced Installer setup into the folder we created above:
copy "<path-to-your-advinst.msi>" "C:\teamcity-docker\Teamcity-Server\advinst.msi"
5. create the server dockerfile (the dockerfile is just a plain text file with instructions for building a container image)

Code: Select all

New-Item -ItemType File -Path C:\teamcity-docker\Teamcity-Server\Dockerfile
After creating the file, open it with Notepad and populate it as follows:

Code: Select all

FROM jetbrains/teamcity-server:latest

USER ContainerAdministrator

SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY advinst.msi C:/temp/advinst.msi

RUN ["pwsh", "-Command", "$p = Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i','C:\\temp\\advinst.msi','/qn','/norestart' -Wait -PassThru; Write-Host \"MSIEXEC EXIT CODE: $($p.ExitCode)\""]

RUN Remove-Item C:/temp/advinst.msi -Force
6. create the agent dockerfile as well (use the same as above to create the Dockerfile, this time in th is path: C:\teamcity-docker\Teamcity-Agent\Dockerfile)

Code: Select all

FROM jetbrains/teamcity-agent:latest-windowsservercore

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

USER ContainerAdministrator
7. create the Docker-Compose file

Docker Compose lets us define both containers, and how they connect to each other, in one file.

Create a file called docker-compose.yml directly inside C:\teamcity-docker\

It should look like this:

Code: Select all

services:
  teamcity-server:
    build:
      context: ./Teamcity-Server
      dockerfile: dockerfile
    image: teamcity-server-advinst:latest
    ports:
      - 8112:8111
    volumes:
      - C:/TeamCity/teamcity-server/data:C:/ProgramData/JetBrains/TeamCity:rw
      - C:/TeamCity/teamcity-server/logs:C:/TeamCity/logs:rw
    mem_limit: 3g

  agent:
    build:
      context: ./Teamcity-Agent
      dockerfile: Dockerfile
    volumes:
      - C:/TeamCity/teamcity-agent/conf:C:/BuildAgent/conf:rw
      - C:/TeamCity/teamcity-agent/system:C:/BuildAgent/system:rw
      - C:/TeamCity/teamcity-agent/work:C:/BuildAgent/work:rw
      - C:/TeamCity/teamcity-agent/output:C:/BuildAgent/output:rw
      - C:/TeamCity/teamcity-agent/projects:C:/BuildAgent/projects:rw
    environment:
      - SERVER_URL=http://<your-computer-ip>:8112
      - TEAMCITY_SERVER_MEM_OPTS=-Xmx2g -XX:ReservedCodeCacheSize=350m
Note: you need to replace <your-computer-ip> with your actual computer's network address

8. build and start the container

Code: Select all

cd C:\teamcity-docker
docker compose up -d --build
9. open TeamCity in your browser:

Code: Select all

http://<your-computer-ip>:8112
10. install the Advanced Installer plugin for TeamCity

For more details regarding this, please see our article here: How to configure an Advanced Installer build step in a TeamCity pipeline

Hope you'll find this useful! :)

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Sample Projects”