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 -All2. 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 version3. create a folder that we'll work in
We'll create the following folder structure:
In PowerShell, run the following:teamcity-docker/
├── docker-compose.yml
├── Teamcity-Server/
│ ├── Dockerfile
│ └── advinst.msi
└── Teamcity-Agent/
└── Dockerfile
Code: Select all
mkdir C:\teamcity-docker\Teamcity-Server
mkdir C:\teamcity-docker\Teamcity-Agent
cd C:\teamcity-dockerCode: 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"5. create the server dockerfile (the dockerfile is just a plain text file with instructions for building a container image)copy "<path-to-your-advinst.msi>" "C:\teamcity-docker\Teamcity-Server\advinst.msi"
Code: Select all
New-Item -ItemType File -Path C:\teamcity-docker\Teamcity-Server\DockerfileCode: 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 -ForceCode: Select all
FROM jetbrains/teamcity-agent:latest-windowsservercore
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
USER ContainerAdministratorDocker 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=350m8. build and start the container
Code: Select all
cd C:\teamcity-docker
docker compose up -d --buildCode: Select all
http://<your-computer-ip>:8112For 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
FOLLOW US
Get the latest news in Application Packaging