阅读 230

Teamcity docker部署

Teamcity docker部署

系统配置

  1. 宿主机器:Ubuntu + docker+ docker-compose
  2. 持续构建工具:teamcity-server+teamcity-agent
  3. 数据库:postgresql

安装部署

teamcity-server支持使用

安装postgresql(optional)
database:
    container_name: "database-name"
    image: postgres:latest
    restart: always
    privileged: true
    ports:
      - <port>:5432
    networks:
      - <same with teamcity-server>
    environment:
      POSTGRES_USER: teamcity
      POSTGRES_PASSWORD: teamcity
      POSTGRES_DB: teamcity
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - <path to data>:/var/lib/postgresql/data/pgdata
复制代码
安装teamcity-server
server:
    image: jetbrains/teamcity-server
    container_name: teamcity-server
    restart: always
    depends_on:
      - db
    networks:
		<networks>
    dns: #配置容器dns,防止服务访问外部网路域名解析失败
      - 8.8.8.8
      - 1.1.1.1
      - 114.114.114.114
    volumes:
      - "<path to data>:/data/teamcity_server/datadir"
      - "<path to logs>:/opt/teamcity/logs"
    ports:
      - <port>:8111
复制代码
安装teamcity-agent

官方提供的teamcity-agent镜像是基于Ubuntu构建,只有对Java的支持,实际使用时需要基于官方镜像重新构建镜像,以node环境为例

构建支持nodejs的代理镜像
  1. dockerfile

    FROM jetbrains/teamcity-agent
    USER root
    
    LABEL maintainer="lvcq"
    
    #node安装
    COPY ./node-agent.sh ./
    RUN chmod a+x ./node-agent.sh && ./node-agent.sh
    
    USER buildagent
    复制代码
  2. node-agent.sh

    #! /bin/bash
    # 官方agent是基于Ubuntu构建
     mv /etc/apt/sources.list /etc/apt/sources.list.bak
    LSB_RELEASE=$(lsb_release -cs)
    NODE_NAME='node-v14.15.1-linux-x64'
    echo $LSB_RELEASE
    # 更换Ubuntu软件源为清华源
    cat >/etc/apt/sources.list<<EOF
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE} main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE} main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-updates main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-backports main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-security main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${LSB_RELEASE}-security main restricted universe multiverse
    EOF
    # 设置dns服务器,防止安装依赖过程中偶尔出现域名解析失败问题
    echo "set nameserver"
    cat >> /etc/resolv.conf << EOF
    nameserver 8.8.8.8
    nameserver 1.1.1.1
    nameserver 114.114.114.114
    EOF
    
    # installNodeWithBinaries
    installNodeWithApt
    
    # 安装node方式一
    installNodeWithBinaries(){
    	apt-get update 
    	apt-get install wget 
    	wget https://nodejs.org/dist/v14.15.1/${NODE_NAME}.tar.xz
    	tar xvf ${NODE_NAME}.tar.xz
    	mv ${NODE_NAME} /home/buildagent/node
    	chown -R buildagent:buildagent /home/buildagent/node
    	echo $(ls -l /home/buildagent/node)
    	cat >> /home/buildagent/.bashrc << EOF
    	# node path
    	export PATH=/home/buildagent/node/bin:\$PATH
    EOF
    }
    
    #安装node方式二
    installNodeWithApt(){
    	apt-get update 
    	apt-get install -y build-essential
    	curl -sL https://deb.nodesource.com/setup_15.x | bash - 
    	apt-get install -y nodejs 
    	apt-get install -y man 
    	apt-get clean all
    }
    
    复制代码

    部署完成后设置

    1. 通过teamcity-server的http://ip:port 访问系统,配置数据库

    2. 添加项目,配置部署步骤

    3. 激活(Authorize)agent,为agent设置项目配置

文章分类
开发工具
文章标签