如何为 teamcity agent 安装额外的软件?
How to install additional software to teamcity agent?
我通过 docker 图片安装了 teamcity 代理
如何通过 brew 向此代理添加一些软件?
Docker化 Teamcity 代理很可能需要扩展基本映像并使用适当的包管理。
例如,我们使用teamcity-minimal-agent
图像,基于UbuntuOS。
下面是扩展 Dockerfile
的示例,其中包含我们软件所需的一些基本工具和额外包的安装说明,以及 docker 到 运行 "docker in docker" 的客户端.
此外,它 运行 同步 OS 用户 ID 和 buildagent
用户 ID,用于 运行 代理。
# Custom Dockerfile
FROM jetbrains/teamcity-minimal-agent:2019.2
ARG user_id
ARG docker_group_id
ENV USER_ID=${user_id}
# Set correct environment variables.
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# Install basic tools
RUN apt-get update && \
apt-get -y --no-install-recommends install \
dirmngr \
gpg-agent \
software-properties-common \
apt-transport-https \
wget \
zip \
git
# Add key and docker repository
ENV DOCKER_VERSION 18.03.1~ce~3-0~ubuntu
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
# Install necessary software
RUN apt-get update
RUN apt-get -y --no-install-recommends install \
docker-ce=${DOCKER_VERSION} \
rsync openssh-client vim python python-dev \
bzip2 nodejs dnsutils sudo
# Install pip and packages
RUN curl -sS 'https://bootstrap.pypa.io/get-pip.py' | python
RUN pip install \
pep8 \
requests
# Access and signature for github repositories
COPY <my-gpg-file>.gpg /var/tmp/<my-gpg-file>.gpg
# Pass OS user's id and export it to use in subcontainers
RUN groupmod -g ${USER_ID} buildagent && \
usermod -g ${USER_ID} -G docker buildagent
# Sync docker group id between OS and container
RUN groupmod -g ${docker_group_id} docker
USER buildagent
RUN gpg --allow-secret-key-import --import /var/tmp/<my-gpg-file>.gpg
RUN git config --global user.email "admin@example.com" && \
git config --global user.name "Teamcity Bot" && \
git config --global user.signingkey <my-gpg-key>
USER root
Docker-compose 使 运行 变得容易得多。
在下面找到一个例子。
它允许在代理 docker 容器中 运行 一个 docker 容器,称为 "docker in docker"。
# Docker-compose to run containers
#
# Build images: DOCKER_GROUP_ID=$(getent group docker | cut -d: -f3) USER_ID=$(id -u) docker-compose build
# Start containers: docker-compose up -d
#
version: '2.2'
services:
teamcity-server:
hostname: "teamcity-server"
container_name: "teamcity-server"
build: "."
volumes:
- "/data/teamcity:/data/teamcity:rw"
environment:
TEAMCITY_SERVER_MEM_OPTS: -Xmx1g -XX:ReservedCodeCacheSize=350m
TEAMCITY_LOGS: /opt/teamcity/logs
TEAMCITY_DIST: /opt/teamcity
TEAMCITY_DATA_PATH: /opt/teamcity/data
ports:
- "443:443"
- "80:80"
restart: "always"
teamcity-agent:
hostname: "teamcity-agent-01"
container_name: "teamcity-agent-01"
build:
context: "./teamcity-agent"
args:
user_id: "${USER_ID}"
docker_group_id: "${DOCKER_GROUP_ID}"
image: "teamcity-agent"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/var/lib/docker:/var/lib/docker"
- "/opt/share/.composer:/home/buildagent/.composer:rw"
- "/opt/agents:/opt/agents:rw"
environment:
- "SERVER_URL=https://<teamcity-url>"
- "AWS_DEFAULT_REGION=ap-southeast-1"
- "AGENT_NAME=teamcity-agent-01"
- "RUN_AS_BUILDAGENT=true"
privileged: true
restart: "always"
cpus: 1
mem_limit: 1g
这些例子也可以大大简化。
我通过 docker 图片安装了 teamcity 代理
如何通过 brew 向此代理添加一些软件?
Docker化 Teamcity 代理很可能需要扩展基本映像并使用适当的包管理。
例如,我们使用teamcity-minimal-agent
图像,基于UbuntuOS。
下面是扩展 Dockerfile
的示例,其中包含我们软件所需的一些基本工具和额外包的安装说明,以及 docker 到 运行 "docker in docker" 的客户端.
此外,它 运行 同步 OS 用户 ID 和 buildagent
用户 ID,用于 运行 代理。
# Custom Dockerfile
FROM jetbrains/teamcity-minimal-agent:2019.2
ARG user_id
ARG docker_group_id
ENV USER_ID=${user_id}
# Set correct environment variables.
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# Install basic tools
RUN apt-get update && \
apt-get -y --no-install-recommends install \
dirmngr \
gpg-agent \
software-properties-common \
apt-transport-https \
wget \
zip \
git
# Add key and docker repository
ENV DOCKER_VERSION 18.03.1~ce~3-0~ubuntu
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
# Install necessary software
RUN apt-get update
RUN apt-get -y --no-install-recommends install \
docker-ce=${DOCKER_VERSION} \
rsync openssh-client vim python python-dev \
bzip2 nodejs dnsutils sudo
# Install pip and packages
RUN curl -sS 'https://bootstrap.pypa.io/get-pip.py' | python
RUN pip install \
pep8 \
requests
# Access and signature for github repositories
COPY <my-gpg-file>.gpg /var/tmp/<my-gpg-file>.gpg
# Pass OS user's id and export it to use in subcontainers
RUN groupmod -g ${USER_ID} buildagent && \
usermod -g ${USER_ID} -G docker buildagent
# Sync docker group id between OS and container
RUN groupmod -g ${docker_group_id} docker
USER buildagent
RUN gpg --allow-secret-key-import --import /var/tmp/<my-gpg-file>.gpg
RUN git config --global user.email "admin@example.com" && \
git config --global user.name "Teamcity Bot" && \
git config --global user.signingkey <my-gpg-key>
USER root
Docker-compose 使 运行 变得容易得多。 在下面找到一个例子。 它允许在代理 docker 容器中 运行 一个 docker 容器,称为 "docker in docker"。
# Docker-compose to run containers
#
# Build images: DOCKER_GROUP_ID=$(getent group docker | cut -d: -f3) USER_ID=$(id -u) docker-compose build
# Start containers: docker-compose up -d
#
version: '2.2'
services:
teamcity-server:
hostname: "teamcity-server"
container_name: "teamcity-server"
build: "."
volumes:
- "/data/teamcity:/data/teamcity:rw"
environment:
TEAMCITY_SERVER_MEM_OPTS: -Xmx1g -XX:ReservedCodeCacheSize=350m
TEAMCITY_LOGS: /opt/teamcity/logs
TEAMCITY_DIST: /opt/teamcity
TEAMCITY_DATA_PATH: /opt/teamcity/data
ports:
- "443:443"
- "80:80"
restart: "always"
teamcity-agent:
hostname: "teamcity-agent-01"
container_name: "teamcity-agent-01"
build:
context: "./teamcity-agent"
args:
user_id: "${USER_ID}"
docker_group_id: "${DOCKER_GROUP_ID}"
image: "teamcity-agent"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/var/lib/docker:/var/lib/docker"
- "/opt/share/.composer:/home/buildagent/.composer:rw"
- "/opt/agents:/opt/agents:rw"
environment:
- "SERVER_URL=https://<teamcity-url>"
- "AWS_DEFAULT_REGION=ap-southeast-1"
- "AGENT_NAME=teamcity-agent-01"
- "RUN_AS_BUILDAGENT=true"
privileged: true
restart: "always"
cpus: 1
mem_limit: 1g
这些例子也可以大大简化。