[JAVA] Add the JDK to the TeamCity build agent container

Purpose

You can prepare a container for the build agent environment that suits your environment.

Build agent configuration policy

There are two policies for building agent configuration.

1: Rich build agent

There are up to two build agents in the free tier, so for small project use you'll want one agent to have multiple build environments (unless you pay). Probably the same for personal use.

2: Minimal build agent

By minimizing the build agent, you can easily set up your build environment and keep your Dockerfile small. On the other hand, you have to manage the agent manually.

Base study

Unless you have a specific requirement, it's a good idea to start with the regular agent container (https://github.com/JetBrains/teamcity-docker-agent). It seems that the environment setup for .NET build and Docker deployment is also done. On the other hand, if you have a hard project use and want to make the container as small as possible, or if you don't want to put in extra things for complete management, [Minimum Agent Container](https://github.com/JetBrains/teamcity- docker-minimal-agent) may be used.

In any case, Java 8 is included as the execution environment of the agent itself. (It seems that you are using Amazon Coretto derived from OpenJDK)

Main subject: Addition of JDK

This time, I decided to add the JDK starting from Minimum Agent Container. The container used is the latest of the linux (Ubuntu) tag.

Where to add Java

If you refer to Automatic detection of Java environment of agent, it will be automatically detected in the following directories. .. After that, it seems that you can set the search destination path in the configuration file.

Unix

The following directories are searched for Java subdirectories:

/usr/local/java /usr/local /usr/java /usr/lib/jvm /usr

Sample: Amazon Correto 11

Dockerfile sample when adding jdk11. Don't forget to add the JDK for Minimum Agent Container.

Dockerfile


FROM jetbrains/teamcity-minimal-agent:latest

LABEL maintainer=""

# JDK preparation start

# Amazon Coretto 11
ARG MD5SUM='08a0cea184824c5477a62ce6a6a0fb0b'
ARG JDK_URL='https://d3pxv6yz143wms.cloudfront.net/11.0.3.7.1/amazon-corretto-11.0.3.7.1-linux-x64.tar.gz'

RUN set -eux; \
    curl -LfsSo /tmp/openjdk.tar.gz ${JDK_URL}; \
    echo "${MD5SUM} */tmp/openjdk.tar.gz" | md5sum -c -; \
    mkdir -p /usr/local/java/openjdk; \
    cd /usr/local/java/openjdk; \
    tar -xf /tmp/openjdk.tar.gz --strip-components=1; \
    rm -rf /tmp/openjdk.tar.gz;

# JDK preparation end
##################################

It is easier to manage on the server if you name the agent using AGENT_NAME.

docker-compose.yml


version: '3'

services:
  ci-agent-java11:
    build: ./ci/ci-agent/
    environment: 
      - SERVER_URL=ci:8111
      - AGENT_NAME=Java11
    ports:
      - 9090:9090
   volumes:
      - ./ci/agent-java11/conf:/data/teamcity_agent/conf

Specify JDK11 in the build step

If the build step is the default, the JDK of the build agent JAVA_HOME is used, so specify the set JDK.

image.png

Reference: Assign agents to pools

If it is difficult to manage with the default pool alone, divide the agents appropriately into pools and assign them to each project.

image.png

Ijo.

Recommended Posts

Add the JDK to the TeamCity build agent container
4 Add println to the interpreter
Add Extended Attributes to the file
How to add the delete function
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
I wanted to add @VisibleForTesting to the method
[Docker] How to build when the source code is bind-mounted on the container
Docker container build fails to install php-radis
How to check the logs in the Docker container
Add empty data to the top of the list
How to add sound in the app (swift)
Change the timezone of the https-portal container to JST
Add classpath: to the path specified in spring.datasource.schema
How to build the simplest blockchain in Ruby
Organized how to interact with the JDK in stages
Communicate from the outside to the container launched by docker-compose
I want to add a delete function to the comment function