JetBrains / teamcity-docker-agent

TeamCity agent docker image sources
https://hub.docker.com/r/jetbrains/teamcity-agent/
Apache License 2.0
77 stars 64 forks source link

Questions related to updating to Ubuntu 18.04 #25

Closed rubenwardy closed 6 years ago

rubenwardy commented 6 years ago

Hi! I'd like to run a teamcity agent based on Ubuntu 18.04. I cloned each of teamcity-minimal-agent and this repo, move ubuntu/Dockerfile to the root of each repo and delete all other dirs, then updated the dockerfile to use biomic and such.

Building this repo's image failed, as systemd was not installed in the image. Systemd should not be used in docker anyway, as the whole point is you run the app as the init process - it's a container not a VM.

Additionally, this appears to be for using docker inside a docker container??? From what I can tell, this is never actually used in my CI and I'm not even sure how it's supposed to be used.

So, questions:

  1. Why does this image use docker inside it, what feature allows me to make builds use it, and can it be removed?
  2. When will the default image from docker hub use 18.04?
  3. How can I install systemd to make this image work, and is there an example teamcity-base?

teamcity-base/Dockerfile:

FROM ubuntu:18.04

ENV DEBIAN_FRONTEND noninteractive
ENV JAVA_HOME       /usr/lib/jvm/java-8-oracle
ENV LANG            en_US.UTF-8
ENV LC_ALL          en_US.UTF-8

RUN apt-get update && \
  apt-get install -y wget gnupg && \
  apt-get install -y --no-install-recommends locales && \
  locale-gen en_US.UTF-8 && \
  apt-get dist-upgrade -y && \
  apt-get --purge remove openjdk* && \
  echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections && \
  echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu bionic main" > /etc/apt/sources.list.d/webupd8team-java-trusty.list && \
  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \
  apt-get update && \
  apt-get install -y --no-install-recommends oracle-java8-installer oracle-java8-set-default && \
  apt-get clean all

teamcity-minimal-agent/Dockerfile:

FROM teamcity-base

MAINTAINER Kateryna Shlyakhovetska <shkate@jetbrains.com>

VOLUME /data/teamcity_agent/conf
ENV CONFIG_FILE /data/teamcity_agent/conf/buildAgent.properties
LABEL dockerImage.teamcity.version="latest" \
      dockerImage.teamcity.buildNumber="latest"

COPY run-agent.sh /run-agent.sh
COPY run-services.sh /run-services.sh
COPY dist/buildagent /opt/buildagent

RUN useradd -m buildagent && \
    chmod +x /run-agent.sh /run-services.sh && sync

CMD ["/run-services.sh"]

EXPOSE 9090

teamcity-agent/Dockerfile:

FROM teamcity-minimal-agent

MAINTAINER Vladislav Rassokhin <vladislav.rassokhin@jetbrains.com>

LABEL dockerImage.teamcity.version="latest" \
      dockerImage.teamcity.buildNumber="latest"

ENV NUGET_XMLDOC_MODE=skip \
    DOTNET_CLI_TELEMETRY_OPTOUT=true \
    DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true \
    GIT_SSH_VARIANT=ssh

RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && add-apt-repository -y ppa:git-core/ppa && apt-get update && \
    apt-get install -y git mercurial openjdk-8-jdk apt-transport-https ca-certificates curl && \
    \
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
#    apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 && \
    echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable" > /etc/apt/sources.list.d/docker.list && \
    \
    apt-cache policy docker-ce && \
    apt-get update && \
    apt-get install -y docker-ce && \
#    systemctl disable docker && \
    curl -SL https://github.com/docker/compose/releases/download/1.20.1/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose && \
    \
    apt-get install -y --no-install-recommends \
            libc6 \
            libcurl3 \
            libgcc1 \
            libgssapi-krb5-2 \
            libicu55 \
            liblttng-ust0 \
            libssl1.0.0 \
            libstdc++6 \
            libunwind8 \
            libuuid1 \
            zlib1g \
        && rm -rf /var/lib/apt/lists/* && \
    \
    curl -SL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.4/dotnet-sdk-2.1.4-linux-x64.tar.gz --output dotnet.tar.gz \
        && mkdir -p /usr/share/dotnet \
        && tar -zxf dotnet.tar.gz -C /usr/share/dotnet \
        && rm dotnet.tar.gz \
        && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet && \
    \
    mkdir warmup \
        && cd warmup \
        && dotnet new \
        && cd .. \
        && rm -rf warmup \
        && rm -rf /tmp/NuGetScratch && \
    \
    apt-get clean all && \
    \
    usermod -aG docker buildagent

COPY run-docker.sh /services/run-docker.sh
kir commented 6 years ago

Hi,

I'll try answering your first question - TeamCity has a number of features when docker is used in your builds. There are "docker build" and "docker compose" build runners + you can specify command line runner to run your script inside docker container from the specified docker image.

Some documentation on these features are here: https://confluence.jetbrains.com/display/TCD18/Integrating+TeamCity+with+Docker

Hope this makes sense,

rubenwardy commented 6 years ago

Thanks, will look though.

Forgot to mention a third question, how do I install systemd in my teamcity-base? Would be good to have an example teamcity-base/Dockerfile

VladRassokhin commented 6 years ago

I'll try to answer other questions.

  1. There're no plans to use Ubuntu 18.04 in nearest future (this year), I'd wait for 18.04.1 or even 18.04.2 to be released.
  2. I'm unaware how to install systemd on modern Ubuntu as I'd expect it to be there (probably it's removed in docker image). Since it's only needed to start docker server you may try to use alternatives like tini and adapt run-docker.sh to use it for starting docker server in background. Another approach is drop 'run-docker.sh' and pass docker.sock into running agent to be able to use docker-related features in TeamCity.
rubenwardy commented 6 years ago

Closing as I've solved this issue for myself. I removed systemd and docker from the container.

teamcity-agent/Dockerfile:

FROM teamcity-minimal-agent

MAINTAINER Vladislav Rassokhin <vladislav.rassokhin@jetbrains.com>

LABEL dockerImage.teamcity.version="latest" \
      dockerImage.teamcity.buildNumber="latest"

ENV NUGET_XMLDOC_MODE=skip \
    DOTNET_CLI_TELEMETRY_OPTOUT=true \
    DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true \
    GIT_SSH_VARIANT=ssh

RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository -y ppa:openjdk-r/ppa && add-apt-repository -y ppa:git-core/ppa && apt-get update && \
    apt-get install -y git mercurial openjdk-8-jdk apt-transport-https ca-certificates curl && \
    \
    wget http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu55_55.1-7ubuntu0.4_amd64.deb && \
    apt install ./libicu55_55.1-7ubuntu0.4_amd64.deb && \
    apt-get install -y --no-install-recommends \
            libc6 \
            libgcc1 \
            libgssapi-krb5-2 \
            liblttng-ust0 \
            libssl1.0.0 \
            libstdc++6 \
            libunwind8 \
            libuuid1 \
            zlib1g \
        && rm -rf /var/lib/apt/lists/* && \
    \
    curl -SL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.4/dotnet-sdk-2.1.4-linux-x64.tar.gz --output dotnet.tar.gz \
        && mkdir -p /usr/share/dotnet \
        && tar -zxf dotnet.tar.gz -C /usr/share/dotnet \
        && rm dotnet.tar.gz \
        && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet && \
    \
    mkdir warmup \
        && cd warmup \
        && dotnet new \
        && cd .. \
        && rm -rf warmup \
        && rm -rf /tmp/NuGetScratch && \
    \
    apt-get clean all

run-docker.sh:

#!/bin/bash

if [ "$DOCKER_IN_DOCKER" = "start" ] ; then
 echo "Ignoring docker start request"
fi

Hope this helps someone