5. Customising your instance
Customising your instance is the most complicated part of creating a custom elastic image. You need to install the packages that are prerequisites for Bamboo onto your instance (if you didn't choose the Elastic Bamboo stock images as your base AMI), add your customisations, deploy Bamboo onto your instance and set up an EC2 environment on your instance.
5.1 Installing Bamboo prerequisite packages
If you selected Atlassian's AMI as your base AMI in '2. Selecting an Existing AMI', you can skip this step and go to '5.2 Adding Customisations' as this image has been pre-configured for Bamboo. If you have selected a different AMI, you will need to install the following packages onto your instance using the commands shown below:
Amazon EC2 API tools
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip unzip ec2-api-tools.zip mv ec2-api-tools-* /opt/ec2-api-tools
Note: if your distribution already contains ec2-api-tools package, you can install it instead.
Java JRE
You need to install JRE (or JDK) on your instance to be able to run the agent. The preferred way of doing this is to install a package that came with your distribution. For a list of supported JREs, see supported platforms.
5.2 Adding user customisations to your instance
Adding your own customisations is quite a simple process, once you have made it this far.
To add user customisations to your instance:
- Log into your elastic instance (as previously described in '4. Accessing your Instance').
- Once you have logged into your elastic instance, you can treat it as a standalone machine and install anything you want. For example, if you want to install Tomcat on an Ubuntu instance you would run '
sudo apt-get install tomcat6', configure it, ensure that your startup scripts are in place, etc, just as you would when installing Tomcat on a standalone machine.Please note however, you cannot customise the operating system of a running instance. If you want to create an instance with a customised operating system (e.g. Ubuntu), you will need to select an AMI with that operating system installed (as previously described in '2. Selecting an Existing AMI').
- Everything that you install will be saved in snapshot image created at the end of these instructions (see '6. Creating an Image of your Customised Instance'). Any instances started from this image will have all of your user customisations automatically installed.
5.3 Deploying Bamboo onto your instance
Once you have installed the Bamboo pre-requisites on you instance and added your customisations, you can deploy Bamboo elastic bootstrap files onto your instance.
5.3.1 Creating Bamboo user
First, you need to create a 'bamboo' user on your instance by running the following command:
useradd -m bamboo
5.3.2 Downloading agent installer to the instance
Then, install Bamboo Agent binaries as described below. In this case we're using image version 2.2, you should use the latest version available at https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/bamboo/atlassian-bamboo-elastic-image/.
imageVer=2.2
wget https://maven.atlassian.com/content/repositories/atlassian-public/com/atlassian/bamboo/atlassian-bamboo-elastic-image/${imageVer}/atlassian-bamboo-elastic-image-${imageVer}.zip
sudo mkdir -p /opt/bamboo-elastic-agent
sudo unzip -o atlassian-bamboo-elastic-image-${imageVer}.zip -d /opt/bamboo-elastic-agent
sudo chown -R bamboo /opt/bamboo-elastic-agent
sudo chmod -R u+r+w /opt/bamboo-elastic-agent
5.4 Instance configuration
At this stage, you should have a customised instance with Bamboo deployed onto it. The last step in creating a customised instance is to set up an EC2 environment on your instance. Carry out the following steps to set this up:
Run the following command on your instance to set permissions on the bamboo user directory:
chown -R bamboo:bamboo /home/bamboo/
Configure path variables
Create a file profile.sh in your instance's/mntdirectory. This file contains the default Elastic Bamboo path configuration settings, as seen below:export JAVA_HOME=<path to JRE used to start the agent> export EC2_HOME=<location of your EC2 tools installation> export EC2_PRIVATE_KEY=/root/pk.pem export EC2_CERT=/root/cert.pem export PATH=/opt/bamboo-elastic-agent/bin:$EC2_HOME/bin:$JAVA_HOME/bin:$M2_HOME/bin:$MAVEN_HOME/bin:$ANT_HOME/bin:$PATH
If all of the tools on this page were installed in recommended locations, no changes are required. Otherwise, you can update the file as required.
Once profile.sh is correctly customised for your instance, you need to copy it to the/etc/profile.ddirectory by running the following command on your instance in the/mntdirectory:mv profile.sh /etc/profile.d/bamboo.sh
Configure automatic startup of the Bamboo agent
You will need to configure your instance to start the Bamboo agent automatically when the instance is started. You can do this by sourcing Bamboo rc.local file in /etc/rc.local file:. /opt/bamboo-elastic-agent/etc/rc.local
Make sure you add this line before the "exit 0" line in your /etc/rc.local.
Final settings and cleanup
Finally, create a Bamboo welcome screen and clean up keys on your instance by running the following command:cp /opt/bamboo-elastic-agent/etc/motd /etc/motd echo bamboo-<x.x.x> >> /etc/motd rm -f /root/firstlogin /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.pub /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub /root/.ssh/authorized_keys touch /root/firstrun
where <x.x.x> is the Bamboo version you are running (e.g. 4.1.2).
Now, follow the instructions from section "Creating an image of your Customised Instance" to create an AMI.
- Start the image from Bamboo. The agent should come up and download all necessary data to the EC2 instance.
- Run /opt/bamboo-elastic-agent/bin/prepareInstanceForSaving.sh.
- Now, follow the instructions from section "Creating an image of your Customised Instance" to create an AMI. That's it, the newly created AMI contains everything you need to start Bamboo Agents.
Note: if you started your instance from Bamboo right at the start, instead of steps 5 & 6, you can just run:
su -c /opt/bamboo-elastic-agent/bin/bamboo-elastic-agent - bamboo
20 Comments
Anonymous
Aug 22, 2013Do I have to connect from Bamboo during the creation of a new custom image? If so, this makes it very difficult to automate this task.
What exactly does the custom image need from the running Bamboo instance to properly configure itself. Is the custom image locked-in to a specific Bamboo instance?
I'm trying to automate (via Packer and pals) the creation of a custom elastic image - from a generic (non-stock) template AMI to a Bamboo-ready AMI - and it is very difficult to automate if I have to connect from Bamboo.
Thanks,
Luke
Przemek Bruski
Aug 23, 2013It's not strictly necessary. If you connect to Bamboo, your image will match it better (e.g. your custom plugins will be downloaded) which means it will start faster.
But the agent will sync with Bamboo in any case - it's not tied to a specific Bamboo version.
John Barry
Dec 27, 2013When I create the AMI, do I tie my current elastic block instance to it as the sdh, or do I use the Bamboo interface to do it? (I've tried both with the same results - a server that shuts down as soon as it spins up)
The substitute for Steps 5/6 don't work w/one agent plans.
Then, because I'm starting from an already extant bamboo image, most of these steps seem redundant.
E.g. profile creation (I used a seeded image, guess what? I have this profile.sh)
Finally, it seems to imply I need to create two images even though I'm launching from Bamboo.
Is this the case? What am I missing?
Since I didn't give anything that's actionable: here's my nutshell problem.
I want to snap off a new AMI and use it in lieu of bamboo's. The documentation doesn't get me there at all, under even the most generous of definitions of "documentation".
Przemek Bruski
Dec 26, 2013Do you mean the EBS volume? You don't need to worry about EBS during image creation unless you need some data from it - in such case, just mount it as sdh.
You mean a single remote agent Bamboo licence? You're right, you need to go through 5&6 in such case.
John Barry
Dec 26, 2013I did mean the EBS volume, and don't need anything from it.
So I am a little confused. Am I reading the doc correctly in that I need to do the following:
Przemek Bruski
Dec 26, 2013If you start with a current stock image, and run it from Bamboo, the procedure can be simplified. Just do 1, <your customisations here>, 5, 6, 7.
John Barry
Dec 26, 2013Is that my 5,6, 7 or this doc's?
Follow-up - when I spin up the server (step 4 in my steps above) do I need to wait for the agent to spin up? That shuts down my image whenever I try.
Przemek Bruski
Dec 26, 2013John Barry
Dec 27, 2013Is there a specfic user to run the prepareInstance script as?
Przemek Bruski
Dec 27, 2013I think it needs root.
John Barry
Dec 27, 2013Self inflicted wound - had a file reference that pointed to a missing (since deleted) file in profile-extras.sh which was injected into /opt/bamboo/profile.sh - this then caused that source to fail in testIfStartedFromBamboo.sh and exit with a -1.
Anonymous
Jan 10, 2014The rc.local in the stock ubuntu image is broken. The line that says this:
cp -a /home/ubuntu/.ssh /home/ec2-user/.ssh
Should be this:
cp -a /home/ubuntu/.ssh/* /home/ec2-user/.ssh
It causes the directory to be copied over incorrectly (/home/ec2-user/.ssh/.ssh/). That causes the next line to fail which ends up failing the entire rc.local script early due to it being launched with #!/bin/sh -e.
Przemek Bruski
Jan 10, 2014Try using ami-bd9cb5d4 . We'll get it shipped in one of the Bamboo 5.3.x updates.
Anonymous
Jan 29, 2014Tried like 10 times to make a custom image.
Heres what i get after running prepareinstance script, bundling the final image, and starting it from bamboo:
cp: cannot stat `/home': No such file or directory
The final image seems broken wih no home for the bamboo user and everything else fails.
I was trying to make a custom image based on a Amazon linux s3 image.
Przemek Bruski
Jan 29, 2014On a vanilla Amazon Linux image or a stock Bamboo image based on AL?
Anonymous
Jan 30, 2014Hi Przemek, after a couple more tries I noticed that /home gets excluded from the final ec2-bundle-vol run trying to make my custom image from a vanilla Amazon Linux s3 Image, specifically AMI ID ami-1ba18d72
Excluding:
/tmp/rootDevice15101
/dev/pts
/home
/proc
/
/proc/sys/fs/binfmt_misc
/sys
/dev
/media
/mnt
/proc
/sys
/tmp/customimg-bamboo-agent
/mnt/img-mnt
I think that explains why after that bundled image starts, everything dependent on that home dir of the bamboo user fails.
Thanks,
Przemek Bruski
Jan 30, 2014Can you try using an EBS image as base?
Anonymous
Jan 29, 2014Sorry. On a vanilla Amazon Linux s3 Image, specifically AMI ID ami-1ba18d72.
Nuno Pinge
Jan 30, 2014There's a typo in the cleanup command for the DSA keys in 4. Final settings and cleanup:
"rm -f /root/firstlogin /etc/ssh/ssh_host_DA_key ..."
Can someone fix it? This can be a problem if anyone copies the exact command (I just pasted the exact command)
Przemek Bruski
Jan 30, 2014Fixed, thank you for reporting that.