Skip to content

Artifactory OSS in Pivotal TC Server? Yes!

Posted in Uncategorized

I’m very enthusiastic about automation and standardized processes. The more boilerplate something can be, the happier I am. So when it came time to set up my own infrastructure, I had some choices to make, and Nuclear Family LLC is limited in terms of cash flow while we’re developing our product.

Being very familiar with automating Pivotal TC Server from working at a prior employer, I settled on Jenkins for my CI tool. We had used Nexus Repository, so I took a look at that. It was as painful as I thought it would be for my particular liking, and it was stand-alone (they nixed the WAR files in a previous release). I then remembered that Artifactory OSS was tomcat based and had WAR based servlets…

But it wasn’t that simple. Our platform is built using Ubuntu server, and nothing I tried could get Artifactory working; not the Debian package; not the stand-alone. I wanted to deploy in Pivotal TC Server anyhow, so I examined the install and discovered that, yes, I could!

Included is the script I wrote to enable me to just pop it into TC Server. This is not my finished automation, but it should give the power user who is familiar with Tomcat and/or Pivotal TC Server a good idea of what’s going on. The script assumes you have already created the TC Server instance and unpacked the Artifactory installation into its new home.

#!/bin/bash
#The following code is released into the public domain
echo ARTIFACTORY_HOME: ${1}
ARTIFACTORY_HOME=${1}
echo TC_SERVER_INSTANCE: ${2}
TC_SERVER_INSTANCE=${2}

#Change the Java home value if needed
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre

#Get Pivotal TC Server user
#Assumes instance owner is the user that will run the instance
INSTANCE_OWNER=$(stat -c '%U' $TC_SERVER_INSTANCE)
echo INSTANCE_OWNER: $INSTANCE_OWNER

#Copy WAR files from artifactory home
cp $ARTIFACTORY_HOME/webapps/*.war $TC_SERVER_INSTANCE/webapps/
#Copy derby JAR
cp $ARTIFACTORY_HOME/tomcat/lib/derby-*.jar $TC_SERVER_INSTANCE/lib/
#Copy config files, excluding Catalina directory
cp $ARTIFACTORY_HOME/tomcat/conf/*.p* $TC_SERVER_INSTANCE/conf/
cp $ARTIFACTORY_HOME/tomcat/conf/*.x* $TC_SERVER_INSTANCE/conf/
#Copy and edit Catalina config files for access and artifactory
#This makes the config files point to the correct WAR file location in catalina.base
cp -r $ARTIFACTORY_HOME/tomcat/conf/Catalina $TC_SERVER_INSTANCE/conf/Catalina
ACCESS=$TC_SERVER_INSTANCE/conf/Catalina/localhost/access.xml
ARTIFACTORY=$TC_SERVER_INSTANCE/conf/Catalina/localhost/artifactory.xml
REPLACE=\\\$\{artifactory.home\}\\/
sed -e s/${REPLACE}//g $ACCESS > $ACCESS.tmp && mv $ACCESS.tmp $ACCESS
sed -e s/${REPLACE}//g $ARTIFACTORY > $ARTIFACTORY.tmp && mv $ARTIFACTORY.tmp $ARTIFACTORY

#Write setenv.sh
(echo \# Edit this file to set custom options$'\n'\
\# Tomcat accepts two parameters JAVA_OPTS and CATALINA_OPTS$'\n'\
\# JAVA_OPTS are used during START/STOP/RUN$'\n'\
\# CATALINA_OPTS are used during START/RUN$'\n'\
$'\n'\
ARTIFACTORY_HOME=\"$ARTIFACTORY_HOME\"$'\n'\
ARTIFACTORY_USER=$INSTANCE_OWNER$'\n'\
\#START_LOCAL_REPLICATOR=true$'\n'\
START_TMO=60$'\n'\
JAVA_HOME=\"$JAVA_HOME\"$'\n'\
AGENT_PATHS=\"\"$'\n'\
JAVA_AGENTS=\"\"$'\n'\
JAVA_LIBRARY_PATH=\"\"$'\n'\
JVM_OPTS=\"-server -Xms512m -Xmx2g -Xss256k -XX:+UseG1GC -XX:OnOutOfMemoryError=\\\"kill -9 %p\\\"\\$'\n'\
          -Djruby.bytecode.version=1.8 -Djruby.compile.invokedynamic=false -Dfile.encoding=UTF8\\$'\n'\
          -Dartdist=zip -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true\\$'\n'\
          -Djava.security.egd=file:/dev/./urandom\"$'\n'\
JAVA_OPTS=\"\$JVM_OPTS \$AGENT_PATHS \$JAVA_AGENTS \$JAVA_LIBRARY_PATH\"$'\n'\
export ARTIFACTORY_HOME$'\n'\
export ARTIFACTORY_USER$'\n'\
\#export START_LOCAL_REPLICATOR$'\n'\
export START_TMO$'\n'\
export JAVA_HOME$'\n') > $TC_SERVER_INSTANCE/bin/setenv.sh

#Set setenv.sh executable flag
chmod +x $TC_SERVER_INSTANCE/bin/setenv.sh

#Validate that artifactory home and instance are owned by the Pivotal TC Server user
chown -R $INSTANCE_OWNER $ARTIFACTORY_HOME
chown -R $INSTANCE_OWNER $TC_SERVER_INSTANCE

I was very happy with how this turned out for me. If you have any questions about this or suggestions, please let me know!

Be First to Comment

Got something to say?