CI/CD setup for website via TeamCity

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Configuring CI/CD for Your Website with TeamCity

TeamCity is a CI/CD server from JetBrains. It supports complex pipelines, parallel steps, its own Kotlin DSL, and tight integration with IntelliJ IDEA. Popular in corporate environments and .NET projects.

Installing TeamCity

# Docker Compose
services:
  teamcity-server:
    image: jetbrains/teamcity-server:2024.03
    ports:
      - "8111:8111"
    volumes:
      - ./teamcity-data:/data/teamcity_server/datadir
      - ./teamcity-logs:/opt/teamcity/logs

  teamcity-agent:
    image: jetbrains/teamcity-agent:2024.03
    environment:
      SERVER_URL: "http://teamcity-server:8111"
      AGENT_NAME: "linux-agent-1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Kotlin DSL — Configuration as Code

// .teamcity/settings.kts
import jetbrains.buildServer.configs.kotlin.*
import jetbrains.buildServer.configs.kotlin.buildSteps.*
import jetbrains.buildServer.configs.kotlin.triggers.*

version = "2024.03"

project {
    buildType(Build)
    buildType(Test)
    buildType(Deploy)

    buildTypesOrder = arrayListOf(Build, Test, Deploy)
}

object Build : BuildType({
    name = "Build"
    vcs { root(DslContext.settingsRoot) }

    steps {
        nodeJS {
            shellScript = "npm ci && npm run build"
        }
    }

    artifactRules = "dist/** => dist.zip"
})

object Test : BuildType({
    name = "Test"
    dependencies {
        snapshot(Build) {}
    }

    steps {
        script {
            scriptContent = """
                npm ci
                npm test -- --coverage --ci
            """.trimIndent()
        }
    }

    failureConditions {
        testFailure = true
        errorMessage = true
    }
})

object Deploy : BuildType({
    name = "Deploy to Production"
    type = Type.DEPLOYMENT

    dependencies {
        snapshot(Test) {}
        artifacts(Build) {
            artifactRules = "dist.zip => ."
        }
    }

    params {
        param("deploy.env", "production")
    }

    steps {
        script {
            scriptContent = """
                unzip dist.zip -d /var/www/app/
                sudo systemctl reload nginx
            """.trimIndent()
        }
    }

    triggers {
        vcs {
            branchFilter = "+:refs/heads/main"
        }
    }
})

Deploy via SSH

// SSH Upload Step
sshExec {
    commands = """
        cd /var/www/app
        git pull origin main
        composer install --no-dev --optimize-autoloader
        php artisan migrate --force
        php artisan config:cache
        php artisan route:cache
        php artisan view:cache
        sudo systemctl reload php8.3-fpm
    """.trimIndent()
    targetUrl = "deploy-server.example.com"
    authMethod = uploadedKey {
        username = "deploy"
        key = "deploy_key"
    }
}

Docker Build in TeamCity

steps {
    dockerCommand {
        commandType = build {
            source = file { path = "Dockerfile" }
            namesAndTags = "registry.example.com/myapp:%build.counter%"
            commandArgs = "--no-cache"
        }
    }

    dockerCommand {
        commandType = push {
            namesAndTags = "registry.example.com/myapp:%build.counter%"
        }
    }
}

Parameters and Templates

// Template for multiple environments
template("DeployTemplate") {
    params {
        param("env.name", "")
        param("env.url", "")
        param("ssh.host", "")
    }

    steps {
        script {
            scriptContent = "deploy.sh %env.name% %env.url%"
        }
    }
}

object DeployStaging : BuildType({
    templates(DeployTemplate)
    params {
        param("env.name", "staging")
        param("env.url", "https://staging.example.com")
        param("ssh.host", "staging.server.com")
    }
})

Notifications

TeamCity supports notifications to Slack, email, Telegram:

// Email on build
emailNotifier {
    sendTo = "[email protected]"
    events {
        buildFailed()
        firstSuccessAfterFailure()
    }
}

Implementation Timeline

Basic pipeline Build → Test → Deploy: 2–3 days. Full setup with multiple environments, templates, and notifications: 5–7 days.