rodm / gradle-teamcity-plugin

Gradle plugin for developing TeamCity plugins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add docker task to run Teamcity server/agent in containers

grundic opened this issue · comments

Hi,

What do you think about adding Docker support? This would solve different problems:

  • No need to download/unpack Teamcity
  • Cross platform development support
  • Host system would stay clean.

Here is my attempt, I think it almost worked, but needs more systematic approach :)

package com.github.rodm.teamcity.tasks

import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

class DockerCreateServer extends DefaultTask {

    @Input
    String containerName

    @Input
    File dataDir

    @Input
    String serverOptions

    DockerCreateServer() {
        description = 'Create new Docker container with TeamCity Server'
    }

    @TaskAction
    void start() {
        validDirectory('dataDir', getDataDir())

        project.ant.exec(executable: "/usr/local/bin/docker", failonerror: true, logError: true, spawn: false) {
            arg value: 'create'
            arg value: '--name'
            arg value: getContainerName()
            arg value: '-e'
            arg value: String.format('TEAMCITY_SERVER_MEM_OPTS="%s"', getServerOptions())
            arg value: '-v'
            arg value: String.format('%s:/data/teamcity_server/datadir', getDataDir().path)
            arg value: '-p'
            arg value: '8111:8111'
            arg value: '-p'
            arg value: '5005:5005'
            arg value: 'jetbrains/teamcity-server'
        }
    }
}

Probably some parameters have to be configurable (e.g. container name, ports, docker location).
You can take a look at official Docker support for Teamcity:
https://hub.docker.com/r/jetbrains/teamcity-server/
https://hub.docker.com/r/jetbrains/teamcity-agent/

Thank you.

It's an interesting idea, although I'm not sure if the arguments you give hold, the docker images are larger than the installer and have to be stored somewhere on the host system.

Also rather than implementing support directly into the plugin I would like to possibly use an existing plugin, such as docker-remote-api, and allow environments to specify if a local or a docker server or agent is to be used.

Um.. well, the normal Teacity distributive should also be stored somewhere on the system. The sizes are approximately identical: 1Gb Docker images vs 900Mb tar.gz. But as a bonus we'll get cross-platform support. The argument "No need to download/unpack Teamcity" is that your plugin should not care about downloading TC, Docker will do this work.
For example, developing plugins on Mac is hassle, as there are some problems starting Teamcity on it. Furthermore, with Docker you don't have to care about the Java and garbading our host system (~/.BuildServer etc).

My example was just proof of concept. I don't work with gradle daily, so feel free to choose better approach in implementing this functionality :)

Docker support has been added in version 1.5