Skip to content

Commit

Permalink
Merge pull request NixOS#4 from briangebala/teamcity
Browse files Browse the repository at this point in the history
TeamCity package and services.
  • Loading branch information
briangebala committed Jul 14, 2015
2 parents c187f5e + 671eb2d commit f34a198
Show file tree
Hide file tree
Showing 7 changed files with 465 additions and 0 deletions.
125 changes: 125 additions & 0 deletions nixos/modules/ai2/teamcity-agent/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.teamcity-agent;
stateDir = "/opt/teamcity/agent";
in
{
options = {
services.teamcity-agent = {
enable = mkOption {
default = false;
description = "Whether to enable the TeamCity agent.";
type = types.bool;
};

heapSize = mkOption {
default = "384m";
description = "Max heap size for the TeamCity Java process.";
type = types.str;
};

gitPublicKey = mkOption {
description = "Contents of the public SSH key file for checking out from GitHub.";
type = types.str;
};

gitPrivateKey = mkOption {
description = "Contents of the private SSH key file for checking out from GitHub.";
type = types.str;
};

sonatypeUser = mkOption {
description = "Sonatype user needed to build s2-online";
type = types.str;
};

sonatypePassword = mkOption {
description = "Sonatype password needed to build s2-online";
type = types.str;
};
};
};

config = mkIf cfg.enable {
systemd.services.teamcity-agent = {
description = "TeamCity agent";

requires = [ "teamcity.service" ];

after = [ "network-interfaces.target" ];
wantedBy = [ "multi-user.target" ];

path = [ pkgs.bash pkgs.procps pkgs.jre pkgs.git pkgs.pkgconfig pkgs.openssh ];

preStart =
let
sbtCreds = builtins.toFile "allenai.sbt" ''
credentials += Credentials("Sonatype Nexus Repository Manager",
"utility.allenai.org",
"${cfg.sonatypeUser}",
"${cfg.sonatypePassword}")
'';
sshConfig = builtins.toFile "config" ''Host github.com
IdentityFile ${stateDir}/.ssh/git-dev
'';
in
''
if [ ! -d ${stateDir}/.ssh ] ; then
mkdir -p ${stateDir}/.ssh
cp ${sshConfig} ${stateDir}/.ssh/config;
echo "${cfg.gitPrivateKey}" > ${stateDir}/.ssh/git-dev
echo "${cfg.gitPublicKey}" > ${stateDir}/.ssh/git-dev.pub
mkdir -p ${stateDir}/sbt
cp ${sbtCreds} ${stateDir}/sbt/allenai.sbt;
mkdir -p ${stateDir}/bin
ln -s /bin/sh ${stateDir}/bin/sh
fi
cp ${pkgs.teamcity}/buildAgent/bin/*.sh ${stateDir}/bin
mkdir -p ${stateDir}/conf
cp ${pkgs.teamcity}/buildAgent/conf/buildAgent.properties ${stateDir}/conf
mkdir -p ${stateDir}/lib
cp ${pkgs.teamcity}/buildAgent/lib/*.jar ${stateDir}/lib
mkdir -p ${stateDir}/logs
chown -R teamcity-agent:teamcity-agent ${stateDir}
chmod -R ug+rw ${stateDir}
chmod -R a+rX /opt/teamcity
chmod -R 600 ${stateDir}/.ssh
'';

serviceConfig = {
User = "teamcity-agent";
WorkingDirectory = stateDir;
PermissionsStartOnly = true;
ExecStart = ''
${pkgs.jre}/bin/java \
-ea \
-cp ${stateDir}/lib/launcher.jar \
jetbrains.buildServer.agent.Launcher \
-ea \
-Xmx${cfg.heapSize} \
-Dteamcity_logs=${stateDir}/logs/ \
-Dlog4j.configuration=file:${pkgs.teamcity}/buildAgent/conf/teamcity-agent-log4j.xml \
jetbrains.buildServer.agent.AgentMain \
-file ${stateDir}/conf/buildAgent.properties
'';
};
};

environment.systemPackages = [ pkgs.teamcity ];

users.extraUsers.teamcity-agent = {
group = "teamcity-agent";
home = stateDir;
createHome = true;
};

users.extraGroups.teamcity-agent = {};
};
}
106 changes: 106 additions & 0 deletions nixos/modules/ai2/teamcity/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.teamcity;
stateDir = "/opt/teamcity/server";
in

{
options = {
services.teamcity = {
enable = mkOption {
default = false;
description = "Whether to enable TeamCity.";
type = types.bool;
};

heapSize = mkOption {
default = "512m";
description = "Max heap size for the TeamCity Java process.";
type = types.str;
};

gitPublicKey = mkOption {
description = "Contents of the public SSH key file for checking out from GitHub.";
type = types.str;
};

gitPrivateKey = mkOption {
description = "Contents of the private SSH key file for checking out from GitHub.";
type = types.str;
};
};
};

config = mkIf cfg.enable {

systemd.services.teamcity = {
description = "TeamCity";

after = [ "network-interfaces.target" ];
wantedBy = [ "multi-user.target" ];

preStart =
let
sshConfig = builtins.toFile "config" ''Host github.com
IdentityFile ${stateDir}/.ssh/git-dev
'';
in
''
mkdir -p ${stateDir}/.ssh
cp ${sshConfig} ${stateDir}/.ssh/config;
echo "${cfg.gitPrivateKey}" > ${stateDir}/.ssh/git-dev
echo "${cfg.gitPublicKey}" > ${stateDir}/.ssh/git-dev.pub
mkdir -p ${stateDir}/work
cp -r ${pkgs.teamcity}/webapps ${stateDir}
chown -R teamcity:teamcity ${stateDir}
chmod -R u+rw ${stateDir}
chmod -R a+rX /opt
'';

serviceConfig = {
User = "teamcity";
WorkingDirectory = stateDir;
PermissionsStartOnly = true;
ExecStart = ''
${pkgs.jre}/bin/java \
-Djava.util.logging.config.file=${pkgs.teamcity}/conf/logging.properties \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-server \
-Xmx${cfg.heapSize} \
-XX:MaxPermSize=270m \
-Dlog4j.configuration=file:${pkgs.teamcity}/conf/teamcity-server-log4j.xml \
-Dteamcity_logs=${stateDir} \
-Djsse.enableSNIExtension=false \
-Djava.awt.headless=true \
-Djava.endorsed.dirs=${pkgs.teamcity}/endorsed \
-classpath ${pkgs.teamcity}/bin/bootstrap.jar:${pkgs.teamcity}/bin/tomcat-juli.jar \
-Dcatalina.home=${pkgs.teamcity} \
-Djava.io.tmpdir=${stateDir} \
org.apache.catalina.startup.Bootstrap start
'';
};
};

environment.systemPackages = [ pkgs.teamcity ];

users.extraUsers.teamcity = {
group = "teamcity";
home = stateDir;
createHome = true;
};

users.extraGroups.teamcity = {};

# users.extraUsers = lib.singleton {
# name = "teamcity";
# description = "teamcity";
# home = stateDir;
# createHome = true;
# extraGroups = [ "users" ];
# };
};
}
63 changes: 63 additions & 0 deletions pkgs/ai2/teamcity/buildAgent.dist.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## TeamCity build agent configuration file

######################################
# Required Agent Properties #
######################################

## The address of the TeamCity server. The same as is used to open TeamCity web interface in the browser.
## The address may contain "http://" or "https://" prefix. If omitted, the http protocol is used.
## Example 1: serverUrl=buildserver.mydomain.com
## Example 2: serverUrl=https://buildserver.mydomain.com:8111
serverUrl=http://localhost:8111/

## The unique name of the agent used to identify this agent on the TeamCity server
## Use blank name to let server generate it.
## By default, this name would be created from the build agent's host name
name=

## Container directory to create default checkout directories for the build configurations.
workDir=/opt/teamcity/agent/work

## Container directory for the temporary directories.
## Please note that the directory may be cleaned between the builds.
tempDir=/opt/teamcity/agent/temp

## Container directory for agent system files
systemDir=/opt/teamcity/agent/system


######################################
# Optional Agent Properties #
######################################

## The IP address which will be used by TeamCity server to connect to the build agent.
## If not specified, it is detected by build agent automatically,
## but if the machine has several network interfaces, automatic detection may fail.
#ownAddress=<own IP address or server-accessible domain name>

## Optional
## A port that TeamCity server will use to connect to the agent.
## Please make sure that incoming connections for this port
## are allowed on the agent computer (e.g. not blocked by a firewall)
ownPort=9090

## A token which is used to identify this agent on the TeamCity server.
## It is automatically generated and saved on the first agent connection to the server.
authorizationToken=


######################################
# Default Build Properties #
######################################
## All properties starting with "system.name" will be passed to the build script as "name"
## All properties starting with "env.name" will be set as environment variable "name" for the build process
## Note that value should be properly escaped. (use "\\" to represent single backslash ("\"))
## More on file structure: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)

# Build Script Properties

#system.exampleProperty=example Value

# Environment Variables

#env.exampleEnvVar=example Env Value
65 changes: 65 additions & 0 deletions pkgs/ai2/teamcity/buildAgent.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## TeamCity build agent configuration file

######################################
# Required Agent Properties #
######################################

## The address of the TeamCity server. The same as is used to open TeamCity web interface in the browser.
## The address may contain "http://" or "https://" prefix. If omitted, the http protocol is used.
## Example 1: serverUrl=buildserver.mydomain.com
## Example 2: serverUrl=https://buildserver.mydomain.com:8111
serverUrl=http://localhost:8111/

## The unique name of the agent used to identify this agent on the TeamCity server
## Use blank name to let server generate it.
## By default, this name would be created from the build agent's host name
name=Default Agent

## Container directory to create default checkout directories for the build configurations.
workDir=/opt/teamcity/agent/work

## Container directory for the temporary directories.
## Please note that the directory may be cleaned between the builds.
tempDir=/opt/teamcity/agent/temp

## Container directory for agent system files
systemDir=/opt/teamcity/agent/system


######################################
# Optional Agent Properties #
######################################

## The IP address which will be used by TeamCity server to connect to the build agent.
## If not specified, it is detected by build agent automatically,
## but if the machine has several network interfaces, automatic detection may fail.
#ownAddress=<own IP address or server-accessible domain name>

## Optional
## A port that TeamCity server will use to connect to the agent.
## Please make sure that incoming connections for this port
## are allowed on the agent computer (e.g. not blocked by a firewall)
ownPort=9090

## A token which is used to identify this agent on the TeamCity server.
## It is automatically generated and saved on the first agent connection to the server.
authorizationToken=474ba1a15932aafebb296f88372ebd99


######################################
# Default Build Properties #
######################################
## All properties starting with "system.name" will be passed to the build script as "name"
## All properties starting with "env.name" will be set as environment variable "name" for the build process
## Note that value should be properly escaped. (use "\\" to represent single backslash ("\"))
## More on file structure: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)

# Build Script Properties

#system.exampleProperty=example Value

# Environment Variables

#env.exampleEnvVar=example Env Value

#teamcity.git.use.native.ssh=true
Loading

0 comments on commit f34a198

Please sign in to comment.