diff --git a/configuration/hudson_instance_setup/setup-hudson-server.sh b/configuration/hudson_instance_setup/setup-hudson-server.sh index 7ae0166ba12..bbd2ac68260 100755 --- a/configuration/hudson_instance_setup/setup-hudson-server.sh +++ b/configuration/hudson_instance_setup/setup-hudson-server.sh @@ -22,10 +22,14 @@ else echo "Running on an AWS EC2 instance as user ${USER} / $(whoami), starting setup..." # Install secrets scp root@sapsailing.com:dev-secrets /tmp + scp root@sapsailing.com:hudson-aws-credentials /tmp sudo mv /tmp/dev-secrets /root/secrets - sudo chown root /root/secrets - sudo chgrp root /root/secrets - sudo chmod 600 /root/secrets + mkdir /root/.aws + sudo mv /tmp/hudson-aws-credentials /root/.aws/credentials + sudo chown root:root /root/secrets /root/.aws/credentials + sudo chmod 600 /root/secrets /root/.aws/credentials + # Make eu-west-1 the default region for any aws CLI interaction: + sudo su - -c "aws configure set default.region eu-west-1" # Create "hudson" user and clear its directory again which is to become a mount point sudo adduser hudson sudo su - hudson -c "rm -rf /home/hudson/* /home/hudson/.* 2>/dev/null" @@ -41,6 +45,10 @@ else sudo ln -s /home/sailing/code/configuration/hudson_instance_setup/hudson.service /etc/systemd/system # Link Hudson system-wide config file: sudo ln -s /home/sailing/code/configuration/hudson_instance_setup/sysconfig-hudson /etc/sysconfig/hudson + # Link additional script files needed for Hudson build server control: + sudo ln -s /home/sailing/code/configuration/launchhudsonslave /usr/local/bin + sudo ln -s /home/sailing/code/configuration/launchhudsonslave-java11 /usr/local/bin + sudo ln -s /home/sailing/code/configuration/aws-automation/getLatestImageOfType.sh /usr/local/bin # Enable the service: sudo systemctl daemon-reload sudo systemctl enable hudson.service @@ -48,6 +56,13 @@ else sudo su - -c "cat <>/etc/exports /home/hudson/android-sdk-linux 172.31.0.0/16(rw,nohide,no_root_squash) EOF +" + # Allow "hudson" user to launch EC2 instances: + sudo su - -c "cat <>/etc/sudoers.d/hudsoncanlaunchec2instances +hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave +hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave-java11 +hudson ALL = (root) NOPASSWD: /usr/local/bin/getLatestImageOfType.sh +EOF " # Install DEV server sudo su - sailing -c "mkdir /home/sailing/servers/DEV diff --git a/configuration/launchhudsonslave b/configuration/launchhudsonslave index 2e2e963d87e..35e08063bbe 100755 --- a/configuration/launchhudsonslave +++ b/configuration/launchhudsonslave @@ -3,7 +3,7 @@ # hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave # hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave-java11 # hudson ALL = (root) NOPASSWD: /usr/local/bin/getLatestImageOfType.sh -AWS=/usr/bin/aws +AWS=/bin/aws REGION=eu-west-1 HUDSON_SLAVE_AMI_ID=$( /usr/local/bin/getLatestImageOfType.sh hudson-slave ) echo Launching instance from AMI ${HUDSON_SLAVE_AMI_ID} ... diff --git a/wiki/info/landscape/creating-ec2-image-for-hudson-from-scratch.md b/wiki/info/landscape/creating-ec2-image-for-hudson-from-scratch.md index e1c9f79b9a5..552fd998582 100644 --- a/wiki/info/landscape/creating-ec2-image-for-hudson-from-scratch.md +++ b/wiki/info/landscape/creating-ec2-image-for-hudson-from-scratch.md @@ -6,7 +6,7 @@ Like when setting up a regular sailing application server instance, start with a ``` This will first run the regular sailing server set-up which allows the instance to run the ``dev.sapsailing.com`` Sailing Analytics instance later. Then, the script will continue to obtain the Hudson WAR file from ``https://static.sapsailing.com/hudson.war.patched-with-mail-1.6.2`` and deploy it to ``/usr/lib/hudson``, obtain and install the default system-wide Hudson configuration, get adjusted dev server secrets from ``ssh://root@sapsailing.com/root/dev-secrets`` as well as ``mail.properties``, and install a ``hudson.service`` unit under ``/etc/systemd/system``. A ``hudson`` user is created, and its ``/home/hudson`` home directory is emptied so it can act as a mount point. A latest version of the SAP Sailing Analytics is installed to ``/home/sailing/servers/DEV``. -The ``/home/hudson/android-sdk-linux`` folder that is later expected to be mounted into the ``/home/hudson`` mount point is exported through NFS by appending a corresponding entry to ``/etc/exports``. +The ``/home/hudson/android-sdk-linux`` folder that is later expected to be mounted into the ``/home/hudson`` mount point is exported through NFS by appending a corresponding entry to ``/etc/exports``. The script will also allow the ``hudson`` user to run the ``/usr/local/bin/launchhudsonslave`` script with ``sudo``. In order to elastically scale our build / CI infrastructure, we use AWS to provide Hudson build slaves on demand. The Hudson Master (https://hudson.sapsailing.com) has a script obtained from our git at ``./configuration/launchhudsonslave`` which takes an Amazon Machine Image (AMI), launches it in our default region (eu-west-1) and connects to it. The AWS credentials are stored in the ``root`` account on ``hudson.sapsailing.com``, and the ``hudson`` user is granted access to the script by means of an ``/etc/sudoers.d`` entry. When the script has finished, proceed as follows: