Skip to content

Gem Bundle used by OpenStudio

Petersen, Anya edited this page Jan 11, 2019 · 16 revisions

OpenStudio Server Release 2.6.2 introduces separation between the gem bundles used by OpenStudio Server and OpenStudio. By default, OpenStudio will run using the bundle that ships with OpenStudio, as described in the OpenStudio Ruby/Gemfile.lock file.

If you need to load a gem that is not included with OpenStudio out of the box, and OpenStudio Server is running in a Docker environment, you can modify the OpenStudio bundle using a using a data point initialization script.

Prerequisites

This is a specific application of a data point initialization script. All prerequisites apply.

Example

Below is sample code that modifies single gem in the OpenStudio Gemfile and re-installs the bundle. The arguments should be passed in via the arguments input in PAT.

#!/usr/bin/env sh

echo $0

# ARGUMENTS:
# First argument is the name of the gem (openstudio-standards)
# Second argument is the name of the github repo (NREL/openstudio-standards)
# Third is the name of the branch (master)

# First check if there is a file that
# indicates the gem has already been updated.
# We only need to update the bundle once / worker,
# not every time a data point is initialized.
GEMFILEUPDATE="/var/oscli/analysis_$SCRIPT_ANALYSIS_ID.lock"
if [ -e $GEMFILEUPDATE ]
then
    echo "***The gem bundle has already been updated"
    exit
fi

# Gemfile for OpenStudio
GEMFILE='/var/oscli/Gemfile'
GEMFILEDIR='/var/oscli'

# Update gem definition in OpenStudio Gemfile
# Replace:
# gem 'openstudio-standards', '= 0.1.15'
OLDGEM="gem '$1'"
echo "***Replacing gem:"
echo "$OLDGEM"

# With this:
# gem 'openstudio-standards', github: 'NREL/openstudio-standards', branch: 'PNNL'
NEWGEM="gem '$1', github: '$2', branch: '$3'"
echo "***With gem:"
echo "$NEWGEM"

# Modify the reference Gemfile in place
cp /usr/local/openstudio-2.6.1/Ruby/Gemfile /var/oscli/
sed -i -e "s|$OLDGEM.*|$NEWGEM|g" $GEMFILE
echo "gem 'aws-sdk-s3', '~> 1'" >> $GEMFILE

# Show the modified Gemfile contents in the log
cd $GEMFILEDIR
echo "***Here is the modified Gemfile:"
cat $GEMFILE

# Set the required env vars
export HOME=/root
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export RUBYLIB=/usr/local/openstudio-2.6.1/Ruby:/usr/Ruby

# Update the specified gem in the bundle
echo "***Updating the specified gem:"
rm Gemfile.lock
rm -rf custom_gems
rm -rf .bundle
bundle _1.14.4_ install --path gems

# Note that the bundle has been updated
echo >> $GEMFILEUPDATE