Skip to content

Commit faee280

Browse files
committed
Cleanup environment construction
1 parent ec92ee6 commit faee280

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

attributes/master.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@
3232

3333
default['s3']['downloads']['host'] = "downloads.typesafe.com.s3.amazonaws.com"
3434

35+
# see below (note that default['master']['env'] can only indirect through node -- workerJavaOpts is not in scope)
36+
workerJavaOpts = "-Dfile.encoding=UTF-8 -server -XX:+AggressiveOpts -XX:+UseParNewGC -Xmx2G -Xss1M -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=128M -Dpartest.threads=4"
37+
default['jenkinsEnv']['JAVA_OPTS'] = workerJavaOpts
38+
default['jenkinsEnv']['ANT_OPTS'] = workerJavaOpts
39+
default['jenkinsEnv']['MAVEN_OPTS'] = workerJavaOpts # doesn't technically need the -Dpartest one, but oh well
40+
41+
# NOTE: This is a string that represents a closure that closes over the worker node for which it computes the environment.
42+
# (by convention -- see `environment((eval node["master"]["env"])...` in _master-config-workers
43+
# Since we can't marshall closures, while attributes need to be sent from master to workers, we must encode them as something that can be shipped...
3544
default['master']['env'] = <<-'EOH'.gsub(/^ {2}/, '')
3645
lambda{| node | Chef::Node::ImmutableMash.new({
37-
"JAVA_OPTS" => "-Dfile.encoding=UTF-8 -server -XX:+AggressiveOpts -XX:+UseParNewGC -Xmx2G -Xss1M -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=128M -Dpartest.threads=4",
38-
"ANT_OPTS" => "-Dfile.encoding=UTF-8 -server -XX:+AggressiveOpts -XX:+UseParNewGC -Xmx2G -Xss1M -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=128M -Dpartest.threads=4",
39-
"MAVEN_OPTS" => "-Dfile.encoding=UTF-8 -server -XX:+AggressiveOpts -XX:+UseParNewGC -Xmx2G -Xss1M -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=128M",
40-
"prRepoUrl" => "http://private-repo.typesafe.com/typesafe/scala-pr-validation-snapshots/"
46+
"JAVA_HOME" => node['java']['java_home'], # we get the jre if we don't do this
47+
"JAVA_OPTS" => node['jenkinsEnv']['JAVA_OPTS'],
48+
"ANT_OPTS" => node['jenkinsEnv']['ANT_OPTS'],
49+
"MAVEN_OPTS" => node['jenkinsEnv']['MAVEN_OPTS'],
50+
"prRepoUrl" => node['repos']['private']['pr-snap']
4151
})}
4252
EOH
4353

attributes/worker.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@
6363
default["jenkinsHomes"][jenkinsHome]["in_demand_delay"] = 1 # if builds are in queue for even one minute, launch this worker
6464
default["jenkinsHomes"][jenkinsHome]["idle_delay"] = 15 # take worker off-line after 15 min of idling (we're charged by the hour, so no rush)
6565

66-
# can't marshall closures, but they sometimes need to be shipped, so encode as string, closing over `node`
6766
default["_jenkinsHome"] = jenkinsHome
6867
default["_jenkinsTmp"] = jenkinsTmp
68+
69+
# Worker-specific env, the rest is defined in master's attribs.
70+
# This needs to be a closure to get laziness so that we can refer to other attributes, but can't marshall closures,
71+
# and they sometimes need to be shipped, so encode as string, closing over `node`...
6972
default["jenkinsHomes"][jenkinsHome]["env"] = <<-'EOH'.gsub(/^ {4}/, '')
7073
lambda{| node | Chef::Node::ImmutableMash.new({
7174
"PATH" => "/bin:/usr/bin:/cygdrive/c/java/jdk-1.6/bin:/cygdrive/c/Program Files (x86)/Git/Cmd", # TODO express in terms of attributes
7275
"sbtLauncher" => "#{node['sbt']['launcher_path']}\\sbt-launch.jar", # from chef-sbt cookbook
7376
"WIX" => node['wix']['home'],
74-
"JAVA_HOME" => node['java']['java_home'],
7577
"TMP" => "#{node['_jenkinsTmp']}",
7678
"_JAVA_OPTIONS" => "-Duser.home=#{node['_jenkinsHome']}", # no other way to do this... sbt boot will fail pretty weirdly if it can't write to $HOME/.sbt and $TMP/...
7779
"SHELLOPTS" => "igncr" # ignore line-ending issues in shell scripts
@@ -110,13 +112,15 @@
110112
default["jenkinsHomes"]["/home/jenkins"]["usage_mode"] = publisher ? "exclusive" : "normal"
111113
default["jenkinsHomes"]["/home/jenkins"]["labels"] = ["linux", publisher ? "publish": "public"]
112114

113-
# can't marshall closures, and this one needs to be shipped from worker to master (note: sshCharaArgs only use on publisher, but doesn't contain any private date, so not bothering)
115+
# Worker-specific env, the rest is defined in master's attribs.
116+
# (note: sshCharaArgs only used on publisher, but doesn't contain any private date, so not bothering to split it out)
117+
# This needs to be a closure to get laziness so that we can refer to other attributes, but can't marshall closures,
118+
# and they sometimes need to be shipped, so encode as string, closing over `node`...
114119
default["jenkinsHomes"]["/home/jenkins"]["env"] = <<-'EOH'.gsub(/^ {4}/, '')
115120
lambda{| node | Chef::Node::ImmutableMash.new({
116121
"sshCharaArgs" => '("[email protected]" "-i" "/home/jenkins/.ssh/for_chara")',
117122
"sbtLauncher" => File.join(node['sbt']['launcher_path'], "sbt-launch.jar"), # from chef-sbt cookbook
118-
"sbtCmd" => File.join(node['sbt-extras']['setup_dir'], node['sbt-extras']['script_name']), # sbt-extras
119-
"JAVA_HOME" => node['java']['java_home'] # we get the jre if we don't do this
123+
"sbtCmd" => File.join(node['sbt-extras']['setup_dir'], node['sbt-extras']['script_name']) # sbt-extras
120124
})}
121125
EOH
122126

recipes/_master-config-workers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# TODO: make retrying more robust
4040
max_num_retries 10 # how often to retry when the SSH connection is refused during initial connect
41-
retry_wait_time 60 # seconds between retries
41+
retry_wait_time 60 # seconds between retries
4242

4343
remote_fs jenkinsHome.dup
4444
jvm_options workerConfig["jvm_options"]
@@ -54,7 +54,7 @@
5454
in_demand_delay workerConfig["in_demand_delay"]
5555
idle_delay workerConfig["idle_delay"]
5656

57-
environment((eval node["master"]["env"]).call(node).merge((eval workerConfig["env"]).call(worker)))
57+
environment((eval node["master"]["env"]).call(worker).merge((eval workerConfig["env"]).call(worker)))
5858

5959
action [:create] # we don't need to :connect, :online since the ec2 start/stop plugin will do that. Also, if connect fails, it may be that chef-client hasn't yet run on the client to initialize jenkins home with .ssh/authorized_keys
6060
end

0 commit comments

Comments
 (0)