-
Notifications
You must be signed in to change notification settings - Fork 2
Implement agent installation #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91dc0e6
3e1f8ae
9e23424
f791d64
6cb9d16
ef51c14
778faee
f8a97a3
e90db65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
default['osrf_jenkins_agent']['jenkins_url'] = "https://build.osrfoundation.org" | ||
default['osrf_buildfarm']['agent']['jenkins_url'] = "https://build.osrfoundation.org" | ||
default['osrf_buildfarm']['agent']['agent_username'] = 'jenkins' | ||
default['osrf_buildfarm']['agent']['java_args'] = '' | ||
default['osrf_buildfarm']['agent']['username'] = 'admin' | ||
default['osrf_buildfarm']['agent']['nodename'] = 'agent' | ||
default['osrf_buildfarm']['agent']['description'] = 'build agent' | ||
default['osrf_buildfarm']['agent']['executors'] = 1 | ||
# TODO tags | ||
default['osrf_buildfarm']['agent']['labels'] = %w(docker) | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,6 +4,10 @@ | |||
# | ||||
# Copyright:: 2020, Open Source Robotics Foundation. | ||||
# | ||||
|
||||
agent_username = node['osrf_buildfarm']['agent']['agent_username'] | ||||
agent_homedir = "/home/#{agent_username}" | ||||
|
||||
apt_update "default" do | ||||
action :periodic | ||||
frequency 3600 | ||||
|
@@ -18,6 +22,7 @@ | |||
libssl-dev | ||||
mercurial | ||||
ntp | ||||
openjdk-8-jdk-headless | ||||
qemu-user-static | ||||
sudo | ||||
x11-xserver-utils | ||||
|
@@ -53,9 +58,9 @@ | |||
block do | ||||
lightdm_conf = Chef::Util::FileEdit.new("/etc/lightdm/lightdm.conf") | ||||
lightdm_conf.search_file_replace_line %r{^display-setup-script=.*}, | ||||
"display-setup-script=/etc/lightdm/xhost.conf" | ||||
"display-setup-script=/etc/lightdm/xhost.sh" | ||||
lightdm_conf.insert_line_if_no_match %r{^display-setup-script=.*}, | ||||
"display-setup-script=/etc/lightdm/xhost.conf" | ||||
"display-setup-script=/etc/lightdm/xhost.sh" | ||||
lightdm_conf.write_file if lightdm_conf.unwritten_changes? | ||||
end | ||||
end | ||||
|
@@ -92,28 +97,74 @@ | |||
action [:start, :enable] | ||||
end | ||||
|
||||
user "jenkins" do | ||||
user agent_username do | ||||
shell "/bin/bash" | ||||
manage_home true | ||||
end | ||||
sudo "jenkins" do | ||||
user "jenkins" | ||||
sudo agent_username do | ||||
user agent_username | ||||
nopasswd true | ||||
end | ||||
|
||||
# Add agent user to the docker group to allow them to build and run docker | ||||
# containers. | ||||
group 'docker' do | ||||
append true | ||||
members 'jenkins' | ||||
members agent_username | ||||
action :manage # Group should be created by docker package. | ||||
end | ||||
|
||||
directory "/home/jenkins/jenkins-agent" | ||||
agent_jar_url = node["osrf_jenkins_agent"]["agent_jar_url"] | ||||
if agent_jar_url.nil? || agent_jar_url.empty? | ||||
agent_jar_url = "#{node["osrf_jenkins_agent"]["jenkins_url"]}/jnlpJars/agent.jar" | ||||
|
||||
# TODO: how to read attributes from chef-osrf plugins into this cookbook | ||||
# swarm_client_version = node['jenkins-plugins']['swarm'] | ||||
swarm_client_version = "3.24" | ||||
swarm_client_url = "https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/#{swarm_client_version}/swarm-client-#{swarm_client_version}.jar" | ||||
swarm_client_jarfile_path = "/home/#{agent_username}/swarm-client-#{swarm_client_version}.jar" | ||||
|
||||
# Download swarm client program from url and install it to the jenkins-agent user's home directory. | ||||
remote_file swarm_client_jarfile_path do | ||||
source swarm_client_url | ||||
owner agent_username | ||||
group agent_username | ||||
mode '0444' | ||||
end | ||||
|
||||
jenkins_username = node['osrf_buildfarm']['agent']['username'] | ||||
agent_jenkins_user = search('osrf_buildfarm_jenkins_users', "username:#{jenkins_username}").first | ||||
template '/etc/default/jenkins-agent' do | ||||
source 'jenkins-agent.env.erb' | ||||
variables Hash[ | ||||
java_args: node['osrf_buildfarm']['agent']['java_args'], | ||||
jarfile: swarm_client_jarfile_path, | ||||
jenkins_url: node['osrf_buildfarm']['jenkins_url'], | ||||
username: jenkins_username, | ||||
password: agent_jenkins_user['password'], | ||||
name: node['osrf_buildfarm']['agent']['nodename'], | ||||
description: node['osrf_buildfarm']['agent']['description'], | ||||
executors: node['osrf_buildfarm']['agent']['executors'], | ||||
user_home: agent_homedir, | ||||
labels: node['osrf_buildfarm']['agent']['labels'], | ||||
] | ||||
notifies :restart, 'service[jenkins-agent]' | ||||
end | ||||
remote_file "/home/jenkins/jenkins-agent/agent.jar" do | ||||
source agent_jar_url | ||||
|
||||
template '/etc/systemd/system/jenkins-agent.service' do | ||||
source 'jenkins-agent.service.erb' | ||||
variables Hash[ | ||||
service_name: 'jenkins-agent', | ||||
username: agent_username, | ||||
] | ||||
notifies :run, 'execute[systemctl-daemon-reload]', :immediately | ||||
notifies :restart, 'service[jenkins-agent]' | ||||
end | ||||
|
||||
execute 'systemctl-daemon-reload' do | ||||
command 'systemctl daemon-reload' | ||||
action :nothing | ||||
end | ||||
|
||||
service 'jenkins-agent' do | ||||
action [:start, :enable] | ||||
# can not connect to server while testing | ||||
not_if { node.chef_environment == "test" } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Earlier versions of the swarm client would start and not exit on a connection failure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you here. What you see wrong in the code about avoiding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The not_if here won't try to start the jenkins-agent service in test environments. But I think it should start it in all cases eve if you can't connect to the server.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can try, I think that it is going to make CI to fail since the agent connection will return an error code from provisioning making the provision to stop there. Let's see if that is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Failing now after applying the change.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to revert the change to make CI happy. Ticketed in #7 in the case we find time to debug and solve it. |
||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
JAVA_ARGS=<%= @java_args %> | ||
|
||
SWARM_CLIENT_JAR='<%= @jarfile %>' | ||
|
||
JENKINS_URL='<%= @jenkins_url %>' | ||
|
||
USERNAME='<%= @username %>' | ||
PASSWORD='<%= @password %>' | ||
|
||
NAME='<%= @name %>' | ||
DESCRIPTION='<%= @description %>' | ||
MODE=exclusive | ||
EXECUTORS=<%= @executors %> | ||
FSROOT='<%= @user_home %>' | ||
LABELS='<%= @labels.join ' '%>' | ||
|
||
JENKINS_ARGS='' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=OSRF build farm jenkins agent | ||
After=network.target | ||
|
||
[Service] | ||
EnvironmentFile=/etc/default/<%= @service_name %> | ||
Type=simple | ||
ExecStart=/bin/sh -c "/usr/bin/java $JAVA_ARGS -jar $SWARM_CLIENT_JAR \ | ||
-master $JENKINS_URL -username $USERNAME -password \"$PASSWORD\" \ | ||
-name $NAME -description \"$DESCRIPTION\" -mode $MODE -executors $EXECUTORS \ | ||
-fsroot $FSROOT -labels \"$LABELS\" $JENKINS_ARGS" | ||
|
||
User=<%= @username %> | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Uh oh!
There was an error while loading. Please reload this page.