Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Teamcity] Teamcity Server can create the agent on AWS.

Posted on November 8, 2022November 9, 2022 By nim No Comments on [Teamcity] Teamcity Server can create the agent on AWS.

Bài này mình sẽ tìm hiểu các create agent của teamcity trên các aws, vmware hoặc k8s.

Contents

Toggle
  • 1) Configure TeamCity server to connect to AWS.
    • 1.1) Setup Teamcity Server.
    • 1.2) Configure agent windows for Teamcity
      • 1.2.1) Create VM windows on AWS
        • 1.2.1.1) Create Key-pairs
        • 1.2.1.2) Create EC2 windows by terraform.
      • 1.2.2) Access to VM windows by remote desktop
      • 1.2.3) Install Teamcity Agent on windows
      • 1.2.4) Accept connection of teamcity agent.
      • 1.2.5) Create image (AMI) based on the agent windows be installed temcity agent
      • 1.2.6) Teamcity server will create agent windows based on AMI.
    • 1.3) Configure agent ubuntu for Teamcity
      • 1.3.1) install teamcity agent on linux
      • 1.3.2) Create an image (AMI) for the Linux agent to be installed TeamCity agent.
    • 1.4) Amazon EC2 Spot Fleet support
      • 1.4.1) Get JSON config of EC2 Spot
      • 1.4.2) Get ARN role
      • 1.4.3) Get information to be related to AMI
      • 1.4.4) Create agent teamcity with spot fleet style.
          • JSON config Linux
          • JSON config windows
  • Upgrade teamcity agent

1) Configure TeamCity server to connect to AWS.

1.1) Setup Teamcity Server.

Bạn vào adminsitrator xong tiếp tục vào Root Project
Teamcity có thể connect đến:
– EC2
– VMware
K8s

Bạn copy cái domain của teamcity xuống.
rồi bạn điền access key và secret key vào.

Ấn chạy mà ko thấy có dấu hiệu gì bất thường là ok.

1.2) Configure agent windows for Teamcity

1.2.1) Create VM windows on AWS

Bạn có thể tham khảo video bên dưới để create vm windows trên AWS.

https://github.com/ravsau/aws-labs/blob/master/terraform-aws/lesson2-windows-and-linux-login.MD

1.2.1.1) Create Key-pairs
Bạn sẽ download được file xxx.pem
để tý chúng ta còn login vào vm windows thông qua remote desktop.
1.2.1.2) Create EC2 windows by terraform.

Bạn vào dường link bên dưới để tham khảo terraform.

https://github.com/mrnim94/terraform-aws/tree/master/ec2-windows

Thông qua terraform mình sẽ tạo 1 vm window.

1.2.2) Access to VM windows by remote desktop

Bạn sử dụng file remote và password để remote vào con agent ec2 windows.

1.2.3) Install Teamcity Agent on windows

sau khi access được vào bên trong teamcity agent thì bạn truy cập vào web teamcity server
vào agent và tải agent window về.

Xong bước này bạn chỉ cần điền url của teamcity server và đặt tên cho agent là ok
ownPort thì để nguyên nhé, không change để nguyên (9090)

Sau khi bạn save thì nó thông báo sẽ tạo 1 file config agent trên máy tính, nên bạn cần sửa gì thì chui vào đó sửa.
Chạy quyền system luôn cho máu.

1.2.4) Accept connection of teamcity agent.

xong khi run xong hết thì bạn sẽ trở lại Teamcity server

Bạn chờ một lúc, sẽ thấy agent windows đăng ký đến teamcity.

sau khi authen thành công bạn sẽ thấy file config sẽ có 1 token.

1.2.5) Create image (AMI) based on the agent windows be installed temcity agent

Bước tiếp theo bạn cần xóa token đó đi. vì bước tiếp theo chúng ta tạo image(AMI) base on trên con VM này.

Bạn thấy giờ chung ta đã có một AMI.

1.2.6) Teamcity server will create agent windows based on AMI.

Giớ chúng ta trở lại Teamcity và create agent trên EC2 thông qua AMI.

Giờ bạn đặt trên cho instance, chọn source là AMI mà chúng ta vừa create
chọn subnet, key-pair, Sec Group,…
Ra ngoài phần agent bạn sẽ thấy ở tab cloud có 1 agent.

Đợi 1 lúc thì agent là đã lên cả trên EC2 và teamcity

hình ảnh Agent Window trên AWS.

Dưới đây là hình ảnh trên teamcity

Agent trên EC2 đã được stop.
Mình sẽ terminate Ec2 trên AWS

Bạn sẽ chờ hẳn khi vm windows đã được xóa trên aws

xong bạn vào trong project root để xóa agent.

Có vẻ đã xóa được vậy thì save thôi

1.3) Configure agent ubuntu for Teamcity

1.3.1) install teamcity agent on linux

Tham khảo link này:
https://unixcop.com/install-and-configure-teamcity-agent-on-linux/

Bạn ssh vào server linux

wget https://teamcity.nimtechnology.com/update/buildAgentFull.zip
apt install unzip
unzip buildAgentFull.zip
apt install java-1.8.0-openjdk
sudo apt-get update
apt-get install openjdk-8-jdk
java -version

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin/java
echo $JAVA_HOME
cp conf/buildAgent.dist.properties  conf/buildAgent.properties
vi buildAgent.properties
chmod +x bin/agent.sh
./bin/agent.sh start

Làm sao để auto restart teamcity agent nếu linux bị restart.

Refence Links:
https://www.jetbrains.com/help/teamcity/start-teamcity-agent.html#Automatic+Agent+Start+Under+Linux

đầu tiên bạn cần kiểm tra lại bash agent.sh của bạn đang ở đây.

root@ip-10-0-102-156:~# ls bin/agent.sh
bin/agent.sh
root@ip-10-0-102-156:~# pwd
/root
vi /etc/systemd/system/teamcityagent.service

[Unit]
Description=TeamCity Build Agent
After=network.target

[Service]
Type=oneshot

#User=teamcityagent
#Group=teamcityagent
ExecStart=/home/teamcityagent/agent/bin/agent.sh start
ExecStop=-/home/teamcityagent/agent/bin/agent.sh stop

# Support agent upgrade as the main process starts a child and exits then
RemainAfterExit=yes
# Support agent upgrade as the main process gets SIGTERM during upgrade and that maps to exit code 143
SuccessExitStatus=0 143

[Install]
WantedBy=default.target

sau đó bạn chạy các lệnh sau:

systemctl daemon-reload
systemctl start teamcityagent
systemctl enable teamcityagent

giờ nếu bạn có reboot thì agent cùng tự connect với teamcity server.

1.3.2) Create an image (AMI) for the Linux agent to be installed TeamCity agent.

bạn ssh vào agent và xoa tocken trong config.

trợ lại UI của AWS tạo image(AMI)

Giờ bạn thấy image đã được tạo thành công

Giờ bạn trở lại UI của teamcity server.

Bạn chọn và đặt tên cho agent phù hợp
Bạn thất agent đang lên
và trên AWS cũng có 1 vm được tạo bới teamcity
sau khi agent ready thì nó sẽ tự động được authen với teamcity server

1.4) Amazon EC2 Spot Fleet support

Ngoài ra teamcity cũng sẽ hỗ trợ chúng chạy các instance Amazon EC2 Spot Fleet
Việc của chúng ta là tìm được JSON config của EC2 Spot mà chúng ta muốn.

https://www.jetbrains.com/help/teamcity/setting-up-teamcity-for-amazon-ec2.html#Amazon+EC2+Spot+Fleet+support

1.4.1) Get JSON config of EC2 Spot

Giờ chúng ta vào phần tạo spot Requests
Giờ bạn cứ thoải mái chọn
khi bạn chọn xong thì bạn ngó giá và download JSON Config

1.4.2) Get ARN role

Bạn để ý ở ảnh trên thì nó đã tạo 1 role: aws-ec2-spot-fleet-tagging-role

1.4.3) Get information to be related to AMI

1.4.4) Create agent teamcity with spot fleet style.

Bạn cần check kĩ các phần mà mình đánh dấu nếu sai sẽ không create được instance trên EC2
JSON config Linux
{
  "IamFleetRole": "arn:aws:iam::250887682577:role/aws-ec2-spot-fleet-tagging-role",
  "AllocationStrategy": "lowestPrice",
  "TargetCapacity": 1,
  "SpotPrice": "0.766",
  "ValidFrom": "2022-08-01T19:39:45Z",
  "ValidUntil": "2023-08-01T19:39:45Z",
  "TerminateInstancesWithExpiration": true,
  "LaunchSpecifications": [
    {
      "ImageId": "ami-0fe9e7950f0b6b707",
      "InstanceType": "t2.micro",
      "KeyName": "work-space-ubuntu",
      "SpotPrice": "0.766",
      "BlockDeviceMappings": [
        {
          "DeviceName": "/dev/sda1",
          "Ebs": {
            "DeleteOnTermination": true,
            "VolumeType": "gp2",
            "VolumeSize": 10,
            "SnapshotId": "snap-00ee5835a90ff3dbb"
          }
        }
      ],
      "NetworkInterfaces": [
        {
          "DeviceIndex": 0,
          "SubnetId": "subnet-03ef25ed5ad9beabc",
          "DeleteOnTermination": true,
          "Groups": [
            "sg-00bddd938f496637d"
          ],
          "AssociatePublicIpAddress": true
        }
      ],
      "TagSpecifications": [
        {
          "ResourceType": "instance",
          "Tags": [
            {
              "Key": "name",
              "Value": "Cloud Linux Agent"
            }
          ]
        }
      ]
    }
  ],
  "Type": "request"
}
JSON config windows
{
  "IamFleetRole": "arn:aws:iam::250887682577:role/aws-ec2-spot-fleet-tagging-role",
  "AllocationStrategy": "lowestPrice",
  "TargetCapacity": 1,
  "SpotPrice": "0.6",
  "ValidFrom": "2020-11-20T23:24:08Z",
  "ValidUntil": "2022-11-20T23:24:08Z",
  "TerminateInstancesWithExpiration": true,
  "LaunchSpecifications": [
    {
      "ImageId": "ami-0e7820e354aedf56c",
      "InstanceType": "c4.2xlarge",
      "KeyName": "TeamCity-key",
      "BlockDeviceMappings": [
        {
          "DeviceName": "/dev/sda1",
          "Ebs": {
            "DeleteOnTermination": true,
            "SnapshotId": "snap-07eb94ff6c274a92e",
            "VolumeSize": 196,
            "VolumeType": "gp2",
            "Encrypted": false
          }
        }
      ],
      "NetworkInterfaces": [
        {
          "DeviceIndex": 0,
          "SubnetId": "subnet-0f095b2a41dfedb56",
          "DeleteOnTermination": true,
          "Groups": [
            "sg-06bb8c51e59a07a5f",
            "sg-01be05bcee8c4e7e3"
          ],
          "AssociatePublicIpAddress": true
        }
      ],
      "IamInstanceProfile": {
        "Arn": "arn:aws:iam::250887682577:instance-profile/TeamCityAccessRole"
      },
      "TagSpecifications": [
        {
          "ResourceType": "instance",
          "Tags": [
            {
              "Key": "name",
              "Value": "c4.xl New Windows Agent"
            }
          ]
        }
      ],
      "EbsOptimized": true
    }
  ],
  "Type": "request"
}

trên teamcity đã hiện instance

Bạn tiến hành start agent spot fleet.

Nếu config spot fleet đúng thì bạn sẽ thấy trên aws có 1 instance mới.

Upgrade teamcity agent

https://www.jetbrains.com/help/teamcity/upgrading-teamcity-server-and-agents.html#Automatic+Build+Agents+Update

TeamCity

Post navigation

Previous Post: [Teamcity] What is “reverse.dep.*” on TeamCity
Next Post: [Gitops] How to design files and folders to be reasonable for any infrastructure

More Related Articles

[TeamCity] Kotlin DSL – Lesson 5 – Build Chain Refactoring TeamCity
[TeamCity] Installing and configuring TeamCity 2017 TeamCity
[TeamCity] Kotlin DSL – Lesson 2 – DSL Basics TeamCity
[Teamcity] Kotlin codes on Git(repository) are conflicted with the TeamCity UI. TeamCity
[TeamCity] Kotlin DSL – Lesson 3 – DSL Deep Dive TeamCity
[TeamCity] Kotlin DSL – Lesson 4 – Build Chains TeamCity

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.