Skip to content

Commit a45d662

Browse files
committed
Merge pull request #50 from adriaanm/master
Bootstrap jenkins from scratch -- the oy vey! edition (oh, and move to our own artifactory)
2 parents 16a51ef + 5716b17 commit a45d662

35 files changed

+570
-270
lines changed

.chef/Vagrantfile

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,43 @@
55
# vagrant up
66
# centos: vagrant box add chef/centos-7.0
77
Vagrant.configure("2") do |config|
8-
config.vm.box = "utopic-daily"
9-
config.vm.provision :chef_solo do |chef|
10-
chef.cookbooks_path = ["~/git/cookbooks"]
11-
chef.node_name = "jenkins-master"
12-
chef.add_recipe("scala-jenkins-infra::master-init")
13-
chef.add_recipe("scala-jenkins-infra::_master-config-proxy")
8+
config.vm.define "default" do |master|
9+
master.vm.box = "utopic-daily"
10+
master.vm.provision :chef_zero do |chef|
11+
chef.cookbooks_path = "~/git/cookbooks"
12+
# after a long struggle tring to get chef-zero/solo to work with chef-vault, dumped the databags in plain text from admin account using:
13+
# for item in $(knife data bag show master); do knife vault show --format json master $item > .chef/data_bags/master/$item.json; done
14+
chef.data_bags_path = "data_bags"
15+
chef.node_name = "jenkins-master"
16+
# TODO: chef.encrypted_data_bag_secret_key_path
17+
chef.add_recipe("scala-jenkins-infra::master-init")
18+
chef.add_recipe("scala-jenkins-infra::master-config")
19+
chef.add_recipe("scala-jenkins-infra::master-jenkins") # do not run on first provision -- must run up to master-config and allow jenkins to restart
20+
end
21+
master.vm.network "public_network"
22+
master.vm.provider "virtualbox" do |v|
23+
v.memory = 4096
24+
v.cpus = 2
25+
end
1426
end
15-
config.vm.network "public_network"
16-
config.vm.provider "virtualbox" do |v|
17-
v.memory = 4096
18-
v.cpus = 2
27+
28+
29+
config.vm.define "worker" do |worker|
30+
worker.vm.box = "utopic-daily"
31+
worker.vm.provision :chef_zero do |chef|
32+
chef.cookbooks_path = "~/git/cookbooks"
33+
# after a long struggle tring to get chef-zero/solo to work with chef-vault, dumped the databags in plain text from admin account using:
34+
# for item in $(knife data bag show master); do knife vault show --format json master $item > .chef/data_bags/master/$item.json; done
35+
chef.data_bags_path = "data_bags"
36+
chef.node_name = "jenkins-worker-vagrant"
37+
# TODO: chef.encrypted_data_bag_secret_key_path
38+
chef.add_recipe("scala-jenkins-infra::worker-init")
39+
chef.add_recipe("scala-jenkins-infra::worker-config")
40+
end
41+
worker.vm.network "public_network"
42+
# worker.vm.provider "virtualbox" do |v|
43+
# v.memory = 4096
44+
# v.cpus = 2
45+
# end
1946
end
2047
end

.chef/knife.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
1313
cookbook_path ["#{current_dir}/cookbooks"]
1414

15+
#ssl_verify_mode :verify_peer
16+
1517
knife[:aws_credential_file] = "#{ENV['HOME']}/.aws/credentials"
16-
knife[:aws_ssh_key_id] = "typesafe-scala-aws-#{ENV.fetch('AWS_USER', ENV['USER'])}" # the pem file name without the .pem extension and it has to be located in: ~/.ssh/
18+
knife[:aws_ssh_key_id] = "#{ENV.fetch('AWS_USER', ENV['USER'])}" # name to use for the key on amazon
1719
knife[:vault_mode] = 'client'

README.md

Lines changed: 124 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -178,42 +178,64 @@ hub clone scala/scala-jenkins-infra
178178
cd scala-jenkins-infra
179179
ln -sh ~/git/cookbooks $PWD/.chef/
180180
181-
knife site install cron
182-
knife site install logrotate
183-
knife site install chef_handler
184-
knife site install windows
185-
knife site install chef-client
186-
knife site install aws
187-
knife site install delayed_evaluator
188-
knife site install ebs
189-
knife site install java
190-
knife site install apt
191-
knife site install packagecloud
192-
knife site install runit
193-
knife site install yum
194-
knife site install jenkins
195-
knife site install 7-zip
196-
knife site install ark
197-
knife site install artifactory
198-
knife site install build-essential
199-
knife site install dmg
200-
knife site install yum-epel
201-
knife site install git
202-
knife site install user
203-
knife site install partial_search
204-
knife site install ssh_known_hosts
205-
knife site install git_user
206-
knife site install chef-sbt
207-
knife site install sbt-extras
208-
```
181+
knife cookbook site install cron
182+
knife cookbook site install logrotate
183+
knife cookbook site install chef_handler
184+
knife cookbook site install windows
185+
knife cookbook site install chef-client
186+
knife cookbook site install aws
187+
knife cookbook site install delayed_evaluator
188+
knife cookbook site install ebs
189+
knife cookbook site install apt
190+
knife cookbook site install packagecloud
191+
knife cookbook site install runit
192+
knife cookbook site install yum
193+
knife cookbook site install 7-zip
194+
knife cookbook site install ark
195+
knife cookbook site install artifactory
196+
knife cookbook site install build-essential
197+
knife cookbook site install dmg
198+
knife cookbook site install yum-epel
199+
knife cookbook site install git
200+
knife cookbook site install user
201+
knife cookbook site install partial_search
202+
knife cookbook site install ssh_known_hosts
203+
knife cookbook site install git_user
204+
205+
knife cookbook site install chef-vault
206+
```
207+
208+
### Current cookbooks
209+
- 7-zip == 1.0.2
210+
- apt == 2.7.0
211+
- ark == 0.9.0
212+
- artifactory == 0.1.1
213+
- aws == 2.7.0
214+
- build-essential == 2.2.3
215+
- chef-client == 4.3.0
216+
- chef_handler == 1.1.6
217+
- cron == 1.6.1
218+
- delayed_evaluator == 0.2.0
219+
- dmg == 2.2.2
220+
- ebs == 0.3.6
221+
- git == 4.2.2
222+
- git_user == 0.3.1
223+
- logrotate == 1.9.1
224+
- packagecloud == 0.0.17
225+
- partial_search == 1.0.8
226+
- runit == 1.6.0
227+
- sbt == 0.1.0
228+
- sbt-extras == 0.4.0
229+
- ssh_known_hosts == 2.0.0
230+
- user == 0.4.2
231+
- windows == 1.36.6
232+
- yum == 3.6.0
233+
- yum-epel == 0.6.0
209234

210235
### Switch to unreleased versions from github
211236
```
212-
//fixed: knife cookbook github install opscode-cookbooks/windows # fix nosuchmethoderror (#150)
213-
//knife cookbook github install adriaanm/jenkins/fix305 # ssl fail on windows -- fix pending: https://github.com/opscode-cookbooks/jenkins/pull/313
214-
knife cookbook github install b-dean/jenkins/http_ca_fixes # pending fix for above ^^^
215-
216-
knife cookbook github install adriaanm/java/windows-jdk1.6 # jdk 1.6 installer barfs on re-install -- wipe its INSTALLDIR
237+
knife cookbook github install adriaanm/jenkins/fix305 # custom fixes + https://github.com/opscode-cookbooks/jenkins/pull/313 (b-dean/jenkins/http_ca_fixes)
238+
knife cookbook github install adriaanm/java/windows-jdk1.6 # jdk 1.6 installer barfs on re-install -- wipe its INSTALLDIR
217239
knife cookbook github install adriaanm/chef-sbt
218240
knife cookbook github install gildegoma/chef-sbt-extras
219241
knife cookbook github install adriaanm/artifactory
@@ -338,19 +360,19 @@ Note that the IPs are stable by allocating elastic IPs and associating them to n
338360
## ~/.ssh/config
339361
```
340362
Host jenkins-worker-ubuntu-publish
341-
IdentityFile $PWD/.chef/config/chef.pem
363+
IdentityFile ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
342364
User ubuntu
343365
344366
Host jenkins-worker-behemoth-1
345-
IdentityFile $PWD/.chef/config/chef.pem
367+
IdentityFile ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
346368
User ec2-user
347369
348370
Host jenkins-worker-behemoth-2
349-
IdentityFile $PWD/.chef/config/chef.pem
371+
IdentityFile ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
350372
User ec2-user
351373
352374
Host jenkins-master
353-
IdentityFile $PWD/.chef/config/chef.pem
375+
IdentityFile ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
354376
User ec2-user
355377
356378
Host scabot
@@ -359,29 +381,30 @@ Host scabot
359381
User scabot
360382
361383
Host jenkins-worker-windows-publish
362-
IdentityFile $PWD/.chef/config/chef.pem
384+
IdentityFile ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
363385
User jenkins
364386
```
365387

366388

367389
# Launch instance on EC2
368390
## Create (ssh) key pair
369391

392+
TODO: I don't think the name matters as long as it's used consistently, ultimately your access key and secret credentials are used by aws-cli to generate the keys etc
393+
370394
If your username on AWS does not match the local username on your machine, define
371395
```
372396
export AWS_USER="[username]"
373397
```
374398

399+
Create a keypair and store locally to authenticate with instances over ssh/winrm:
375400
```
376401
echo $(aws ec2 create-key-pair --key-name $AWS_USER | jq .KeyMaterial) | perl -pe 's/"//g' > ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
377402
chmod 0600 ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
378403
```
379404

380-
In `knife.rb`, make sure `knife[:aws_ssh_key_id]` points to the pem file.
381-
382-
383405
## Selected AMIs
384406

407+
jenkins-master: ami-3b14f27f (Amazon Linux AMI 2015.03 on HVM Instance Store 64-bit for US West N. California)
385408
amazon linux: ami-4b6f650e (Amazon Linux AMI 2014.09.1 x86_64 HVM EBS)
386409
windows: ami-cfa5b68a (Windows_Server-2012-R2_RTM-English-64Bit-Base-2014.12.10)
387410
ubuntu: ami-81afbcc4 (Ubuntu utopic 14.10 from https://cloud-images.ubuntu.com/locator/ec2/ for us-west-1/amd64/hvm:ebs-ssd/20141204)
@@ -396,11 +419,17 @@ NOTE:
396419

397420

398421
```
399-
knife ec2 server create -N jenkins-master \
400-
--region us-west-1 --flavor t2.small -I ami-4b6f650e \
401-
-G Master --ssh-user ec2-user \
402-
--iam-profile JenkinsMaster \
403-
--identity-file $PWD/.chef/config/chef.pem \
422+
--subnet subnet-4bb3b80d --associate-eip 54.67.111.226 \
423+
--server-connect-attribute public_ip_address \
424+
425+
knife ec2 server create -N jenkins-master \
426+
--flavor m3.large \
427+
--region us-west-1 \
428+
-I ami-3b14f27f \
429+
-G Master --ssh-user ec2-user \
430+
--iam-profile JenkinsMaster \
431+
--security-group-ids sg-7afd2d1f \
432+
--identity-file ~/.ssh/typesafe-scala-aws-$AWS_USER.pem \
404433
--run-list "scala-jenkins-infra::master-init"
405434
406435
knife ec2 server create -N jenkins-worker-windows-publish \
@@ -412,7 +441,7 @@ knife ec2 server create -N jenkins-worker-windows-publish \
412441
--security-group-ids sg-1dec3d78 \
413442
--subnet subnet-4bb3b80d --associate-eip 54.183.156.89 \
414443
--server-connect-attribute public_ip_address \
415-
--identity-file $PWD/.chef/config/chef.pem \
444+
--identity-file ~/.ssh/typesafe-scala-aws-$AWS_USER.pem \
416445
--run-list "scala-jenkins-infra::worker-init"
417446
418447
@@ -426,7 +455,7 @@ knife ec2 server create -N jenkins-worker-ubuntu-publish \
426455
--security-group-ids sg-ecb06389 \
427456
--subnet subnet-4bb3b80d --associate-eip 54.67.33.167 \
428457
--server-connect-attribute public_ip_address \
429-
--identity-file $PWD/.chef/config/chef.pem \
458+
--identity-file ~/.ssh/typesafe-scala-aws-$AWS_USER.pem \
430459
--run-list "scala-jenkins-infra::worker-init"
431460
432461
echo NOTE: Make sure to first remove the ips in $behemothIp from your ~/.ssh/known_hosts. Also remove the corresponding worker from the chef server (can be only one with the same name).
@@ -441,7 +470,7 @@ do knife ec2 server create -N jenkins-worker-behemoth-$behemoth \
441470
--security-group-ids sg-ecb06389 \
442471
--subnet subnet-4bb3b80d --associate-eip ${behemothIp[$behemoth]} \
443472
--server-connect-attribute public_ip_address \
444-
--identity-file $PWD/.chef/config/chef.pem \
473+
--identity-file ~/.ssh/typesafe-scala-aws-$AWS_USER.pem \
445474
--run-list "scala-jenkins-infra::worker-init"
446475
done
447476
@@ -472,30 +501,67 @@ knife vault update worker-publish gnupg --search 'name:jenkins-worker-ub
472501

473502
### Add run-list items that need the vault
474503
```
475-
knife node run_list set jenkins-master "scala-jenkins-infra::master-init,scala-jenkins-infra::master-config"
504+
knife node run_list set jenkins-master "recipe[chef-vault],scala-jenkins-infra::master-init,scala-jenkins-infra::master-config,scala-jenkins-infra::master-jenkins"
476505
477506
for w in jenkins-worker-windows-publish jenkins-worker-ubuntu-publish jenkins-worker-behemoth-1 jenkins-worker-behemoth-2
478-
do knife node run_list set $w "scala-jenkins-infra::worker-init,scala-jenkins-infra::worker-config"
507+
do knife node run_list set $w "recipe[chef-vault],scala-jenkins-infra::worker-init,scala-jenkins-infra::worker-config"
479508
done
480509
```
481510

482511
### Re-run chef manually
483512

484513
- windows:
485514
```
486-
PASS=$(aws ec2 get-password-data --instance-id i-f67c0a35 --priv-launch-key $PWD/.chef/config/chef.pem | jq .PasswordData | xargs echo)
515+
PASS=$(aws ec2 get-password-data --instance-id i-f67c0a35 --priv-launch-key ~/.ssh/typesafe-scala-aws-$AWS_USER.pem | jq .PasswordData | xargs echo)
487516
knife winrm jenkins-worker-windows-publish chef-client -m -P $PASS
488517
```
489518

490-
- ubuntu: `ssh jenkins-worker-ubuntu-publish sudo chef-client`
491-
- amazon linux: `ssh jenkins-worker-behemoth-1`, and then `sudo chef-client`
519+
- linux
520+
```
521+
ssh jenkins-worker-ubuntu-publish
522+
sudo su --login # --login needed on ubuntu to set SSL_CERT_FILE (it's done in /etc/profile.d)
523+
chef-client
524+
```
492525

493526
### Attach eips
494527

495528
```
496529
aws ec2 associate-address --allocation-id eipalloc-df0b13bd --instance-id i-94adaa5e # jenkins-master
497530
```
498531

532+
# MANUAL STEPS
533+
## Scabot access to jenkins
534+
The jenkins token for scabot has to be configured manually:
535+
- get the API token from https://scala-ci.typesafe.com/user/scala-jenkins/configure
536+
- use it create `scabot-jenkins.json` as follows
537+
```
538+
{
539+
"id": "scabot",
540+
"jenkins": {
541+
"token": "<TOKEN>"
542+
}
543+
}
544+
```
545+
- do `knife vault update master scabot -J scabot-jenkins.json`
546+
547+
# Artifactory
548+
- Set admin password.
549+
- create repos (TODO: automate)
550+
- Create scala-ci user that can push to scala-release-temp and scala-pr-validation-snapshots,
551+
- coordinate scala-ci credentials with jenkins via
552+
```
553+
knife vault update worker-publish private-repo -J private-repo.json
554+
```
555+
556+
where `private-repo.json`:
557+
```
558+
{
559+
"id": "private-repo",
560+
"user": "scala-ci",
561+
"pass": "???"
562+
}
563+
```
564+
499565

500566
# Misc
501567

@@ -532,9 +598,11 @@ Incorporate the cert into an ssl chain for nginx:
532598

533599
For [forward secrecy](http://axiacore.com/blog/enable-perfect-forward-secrecy-nginx/):
534600
```
535-
openssl dhparam -out files/default/dhparam.pem 2048
601+
openssl dhparam -out files/default/dhparam.pem 1024
536602
```
537603

604+
Using 1024 bits (instead of 2048) for DH to be Java 6 compatible... Bye-bye A+ on https://www.ssllabs.com/ssltest/analyze.html?d=scala-ci.typesafe.com
605+
538606
Confirm values in the csr using:
539607

540608
```
@@ -551,7 +619,7 @@ If it appears stuck at "Waiting for remote response before bootstrap.", the user
551619
(check C:\Program Files\Amazon\Ec2ConfigService\Logs) we need to enable unencrypted authentication:
552620

553621
```
554-
aws ec2 get-password-data --instance-id $INST --priv-launch-key $PWD/.chef/config/chef.pem
622+
aws ec2 get-password-data --instance-id $INST --priv-launch-key ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
555623
556624
cord $IP, log in using password above and open a command line:
557625

0 commit comments

Comments
 (0)