Managing ServerTemplates and RightScripts as code
RightScale’s built in version control system for ServerTemplates™ and RightScripts™ works great if you are only person maintaining them, but if you are working on them with a team or if you have experience with other version control systems like Git or Subversion, it definitely leaves much to be desired. We’ve been dealing with this here at RightScale too, and that is why we are introducing Right ST, the ServerTemplate and RightScript management tool. It is a command line utility that you can use to import and export your ServerTemplates and RightScripts between your own version control system or even just your local workstation. We have designed it to be a flexible command line tool that you can use on the command line, in automated scripts, or even as part of a continuous integration system like Travis CI, AppVeyor, or Jenkins. Like several of our other recent projects, Right ST is written in the Go programming language and it uses our rsc RightScale API client Go library. Just like rsc, it is an open source project released under the MIT License and you can download precompiled binaries for Linux, Windows, and Mac OS X.
Right ST takes advantage of a fairly new addition to the RightScale API – RightScript Metadata Comments – in order to allow you to fully specify the attributes of your RightScripts within the script file itself. These attributes include the name, description, and full RightScript input definitions. It even supports listing local files to synchronize as attachments to the RightScript. Right ST has commands to show, upload, and download RightScripts as well as a command to validate the RightScript Metadata Comments in a script without uploading it.
In addition to working with RightScripts, Right ST can also manage ServerTemplates defined by a YAML format including MultiCloudImages, RightScripts, Alerts, and Inputs. Commands to show, upload, and download ServerTemplates are included. For a full description of the format, see ServerTemplate YAML format.
Bootstrapping your Repositories
However, if you are anything like us, you might have a whole bunch of RightScripts that do not have any RightScript Metadata Comments since they were written before there was even such a thing (this might even be the first you have heard of them). But there is no reason to worry, Right ST has ways help with that too!
RightScripts downloaded via the
rightscript download command will have complete RightScript Metadata Comments
inserted, including full input definitions. Thanks to recent API additions, all attachments will also be downloaded.
ServerTemplates can also be downloaded via the
st download command, which will download or specify all subcomponents
such as RightScripts, MultiCloudImages, and Alerts.
Once downloaded all assets can be checked into Git or any other version control system. Code can be modified and easily re-uploaded to separate accounts such as production, staging, or different development accounts for validation or deployment.
There is even a command to help with scripts not in the RightScale system at all:
rightscript scaffold. The scaffold
command builds a stub RightScript Metadata Comments section from the name and contents of your script and automatically
inserts it into the correct place in the RightScript. Inputs are automatically detected in the same way the RightScale
platform does with a few enhancements to detect default values as well. I will give an example of how it works:
Let’s say you have a script that sets up NTP on your Linux server called
You can run
right_st rightscript scaffold ntp_setup.sh and it will edit your script so it looks like:
As you can see, Right ST kept the shebang at the beginning of the file and inserted the metadata comment after it. Also,
it used the file name to come up with a name for the RightScript and detected the
NTP_SERVERS input from the
$NTP_SERVERS variable usage in the script. Clearly there needs to be some tweaking to get the metadata the way it
should be, but you did not have to write it all out by hand, which could get pretty tedious with more inputs and
scripts. But, if you have another hint in your script,
scaffold can do even better:
Let’s say your script had a default for testing outside of RightLink:
right_st rightscript scaffold ntp_setup.sh will give you:
That little hint allowed Right ST to figure out that the
NTP_SERVERS input should have a default value and based on
the commas in that value it also determined that the input is an array type instead of just a string.
We made Right ST to improve the experience of managing RightScripts and ServerTemplates with an external version control system such as Git or Subversion and we hope you find it as helpful for this as we already do. If you do run into issues with Right ST, you can report them with GitHub issues and since it is open source we also accept pull requests. In the future we hope to make another post about using Right ST as part of a continuous integration workflow so stay tuned!