Skip to content

Commit 992fcbf

Browse files
committed
Speed up interpolation
chef_vault_item is pretty expensive --> hoist out of loop simplify templates while we're at it
1 parent e011bb7 commit 992fcbf

10 files changed

+28
-25
lines changed

recipes/_worker-config-debian.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
end
5555
end
5656

57+
privateRepo = chef_vault_item("worker-publish", "private-repo")
58+
s3Downloads = chef_vault_item("worker-publish", "s3-downloads")
59+
sonatype = chef_vault_item("worker-publish", "sonatype")
60+
5761
{ "#{jenkinsHome}/.credentials-private-repo" => "credentials-private-repo.erb",
5862
"#{jenkinsHome}/.credentials-sonatype" => "credentials-sonatype.erb",
5963
"#{jenkinsHome}/.credentials" => "credentials-private-repo.erb",
@@ -70,12 +74,9 @@
7074
sensitive true
7175

7276
variables({
73-
:sonatypePass => chef_vault_item("worker-publish", "sonatype")['pass'],
74-
:sonatypeUser => chef_vault_item("worker-publish", "sonatype")['user'],
75-
:privateRepoPass => chef_vault_item("worker-publish", "private-repo")['pass'],
76-
:privateRepoUser => chef_vault_item("worker-publish", "private-repo")['user'],
77-
:s3DownloadsPass => chef_vault_item("worker-publish", "s3-downloads")['pass'],
78-
:s3DownloadsUser => chef_vault_item("worker-publish", "s3-downloads")['user']
77+
:privateRepo => privateRepo,
78+
:s3Downloads => s3Downloads,
79+
:sonatype => sonatype
7980
})
8081
helpers(ScalaJenkinsInfra::JobBlurbs)
8182
end

recipes/_worker-config-rhel.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
end
1919
end
2020

21+
privateRepo = chef_vault_item("worker", "private-repo-public-jobs")
22+
2123
{ "#{jenkinsHome}/.m2/settings.xml" => "m2-settings-public-jobs.xml.erb",
2224
"#{jenkinsHome}/.credentials" => "credentials-private-repo.erb"
2325
}.each do |target, templ|
@@ -27,8 +29,7 @@
2729
sensitive true
2830

2931
variables({
30-
:privateRepoPass => chef_vault_item("worker", "private-repo-public-jobs")['pass'],
31-
:privateRepoUser => chef_vault_item("worker", "private-repo-public-jobs")['user']
32+
:privateRepo => privateRepo
3233
})
3334
helpers(ScalaJenkinsInfra::JobBlurbs)
3435
end

recipes/_worker-config-windows.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
node["jenkinsHomes"].each do |jenkinsHome, workerConfig|
1212
if workerConfig["publish"]
13+
s3Downloads = chef_vault_item("worker-publish", "s3-downloads")
14+
1315
# TODO: once s3-plugin supports it, use instance profile instead of credentials
1416
{
1517
"#{jenkinsHome}/.s3credentials" => "s3credentials.erb"
@@ -20,8 +22,7 @@
2022
user workerConfig["jenkinsUser"]
2123

2224
variables({
23-
:s3DownloadsPass => chef_vault_item("worker-publish", "s3-downloads")['pass'],
24-
:s3DownloadsUser => chef_vault_item("worker-publish", "s3-downloads")['user']
25+
:s3Downloads => s3Downloads
2526
})
2627
end
2728
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
realm=<%=node['repos']['private']['realm']%>
22
host=<%=node['repos']['private']['host']%>
3-
user=<%= @privateRepoUser %>
4-
password=<%= @privateRepoPass %>
3+
user=<%= @privateRepo['user'] %>
4+
password=<%= @privateRepo['pass'] %>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
realm=Sonatype Nexus Repository Manager
22
host=oss.sonatype.org
3-
user=<%= @sonatypeUser %>
4-
password=<%= @sonatypePass %>
3+
user=<%= @sonatype['user'] %>
4+
password=<%= @sonatype['pass'] %>

templates/default/m2-settings-public-jobs.xml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<servers>
1212
<server>
1313
<id>pr-scala</id>
14-
<username><%= @privateRepoUser %></username>
15-
<password><%= xmlSafe(@privateRepoPass) %></password>
14+
<username><%= @privateRepo['user'] %></username>
15+
<password><%= xmlSafe(@privateRepo['pass']) %></password>
1616
</server>
1717
</servers>
1818

templates/default/m2-settings.xml.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
<servers>
1212
<server>
1313
<id>sonatype-nexus</id>
14-
<username><%= @sonatypeUser %></username>
15-
<password><%= @sonatypePass %></password>
14+
<username><%= @sonatype['user'] %></username>
15+
<password><%= @sonatype['pass'] %></password>
1616
</server>
1717
<server>
1818
<id>private-repo</id>
19-
<username><%= @privateRepoUser %></username>
20-
<password><%= xmlSafe(@privateRepoPass) %></password>
19+
<username><%= @privateRepo['user'] %></username>
20+
<password><%= xmlSafe(@privateRepo['pass']) %></password>
2121
</server>
2222
<!-- <server>
2323
<id>mirror</id>

templates/default/s3credentials.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
realm=Amazon S3
22
host=<%=node['s3']['downloads']['host']%>
3-
user=<%=@s3DownloadsUser%>
4-
password=<%=@s3DownloadsPass%>
3+
user=<%=@s3Downloads['user']%>
4+
password=<%=@s3Downloads['pass']%>

templates/default/s3curl.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%awsSecretAccessKeys = (
22
typesafe => {
3-
id => '<%= @s3DownloadsUser %>',
4-
key => '<%= @s3DownloadsPass %>',
3+
id => '<%= @s3Downloads['user'] %>',
4+
key => '<%= @s3Downloads['pass'] %>',
55
}
66
)

templates/default/sonatype-curl.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
user = <%= @sonatypeUser %>:<%= @sonatypePass %>
1+
user = <%= @sonatype['user'] %>:<%= @sonatype['pass'] %>

0 commit comments

Comments
 (0)