Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow stop/start and add options for tomcat. log things better
mchyzer committed Sep 2, 2020
1 parent b8c5e46 commit 93ca3ab
Showing 20 changed files with 225 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
@@ -6,7 +6,7 @@ RUN yum update -y \
RUN yum install -y wget tar unzip dos2unix patch

ARG GROUPER_CONTAINER_VERSION
ENV GROUPER_VERSION=2.5.33 \
ENV GROUPER_VERSION=2.5.34 \
GROUPER_CONTAINER_VERSION=$GROUPER_CONTAINER_VERSION

# Install Corretto Java JDK
@@ -32,7 +32,7 @@ RUN echo 'Installing Grouper'; \
cd /opt/grouper/$GROUPER_VERSION/ \
&& $JAVA_HOME/bin/java -cp :grouperInstaller.jar edu.internet2.middleware.grouperInstaller.GrouperInstaller
FROM centos:centos7 as cleanup
ENV GROUPER_VERSION=2.5.33 \
ENV GROUPER_VERSION=2.5.34 \
TOMEE_VERSION=7.0.0
RUN mkdir -p /opt/grouper/grouperWebapp/
RUN mkdir -p /opt/tomee/
4 changes: 2 additions & 2 deletions container_files/tier-support/test/grouperContainerUnitTest.sh
@@ -5,13 +5,13 @@ if [ "$#" -ne 4 ]; then
exit 1
fi

expectedSuccesses=538
expectedSuccesses=554

export containerName=$1
export imageName=$2
export containerVersion=$3
export grouperVersion=$4
export globalSleepSecondsAfterRun=5
export globalSleepSecondsAfterRun=10
export globalExitOnError=false

export successCount=0
@@ -163,6 +163,18 @@ assertNotListeningOnPort() {
assertEquals "not listening on port $1" "0" "$var"
}

containerCommandResultEquals() {

if [ "$#" -ne 2 ]; then
echo "You must enter exactly 2 arguments: the command to run and the expected result"
exit 1
fi
local command="docker exec $containerName $1"
local var="$(runCommand "$command")"
assertEquals "$1" "$2" "$var"

}

runCommand() {
if [ "$#" -ne 1 ]; then
echo "Pass the command to run"
@@ -121,5 +121,32 @@ testContainerQuickstart() {
curl -L -k -u GrouperSystem:thisPassIsCopyrightedDontUse https://localhost/grouper-ws-scim/v2/Groups/ -o index.html
assertLocalFileContains index.html 'etc:workflowEditors'

docker stop $containerName
docker start $containerName

sleep $globalSleepSecondsAfterRun

# one for hsqldb
assertNumberOfTomcatProcesses 2
assertNumberOfApacheProcesses 5
assertNumberOfShibProcesses 0

assertListeningOnPort 443
assertListeningOnPort 80
assertListeningOnPort 8009
assertListeningOnPort 9001

curl -L -k -u GrouperSystem:thisPassIsCopyrightedDontUse https://localhost -o index.html
assertLocalFileContains index.html document.location.href

curl -L -k -u GrouperSystem:thisPassIsCopyrightedDontUse https://localhost/grouper/grouperUi/app/UiV2Main.index?operation=UiV2Main.indexMain -o index.html
assertLocalFileContains index.html 'end index.jsp'

containerCommandResultEquals "ps -ef | grep root | grep cat | grep -v grep | wc -l" 6
containerCommandResultEquals "ps -ef | grep root | grep awk | grep supervisord | wc -l" 1
containerCommandResultEquals "ps -ef | grep root | grep awk | grep grouper | wc -l" 1
containerCommandResultEquals "ps -ef | grep root | grep awk | grep httpd | wc -l" 1
containerCommandResultEquals "ps -ef | grep root | grep awk | grep tomee | wc -l" 1

}
export -f testContainerQuickstart
@@ -19,6 +19,10 @@ testContainerUi() {
docker run --detach --name $containerName --publish 443:443 $imageName ui
sleep $globalSleepSecondsAfterRun


assertFileContains /opt/tomee/conf/server.xml 'address="0.0.0.0"'
assertFileContains /opt/tomee/conf/server.xml 'allowedRequestAttributesPattern=".*"'

assertFileExists /opt/grouper/grouperWebapp/WEB-INF/libWs/axis2-kernel-1.6.4.jar
assertFileNotExists /opt/grouper/grouperWebapp/WEB-INF/lib/axis2-kernel-1.6.4.jar
assertFileExists /opt/grouper/grouperWebapp/WEB-INF/libScim/stax-api-1.0-2.jar
26 changes: 26 additions & 0 deletions container_files/tier-support/test/rebuildTestContainer.sh
@@ -0,0 +1,26 @@
#/bin/bash

if [ "$#" -ne 2 ]; then
echo "You must enter exactly 2 command line arguments: grouper base container version, grouper_container_git_base_dir"
echo "rebuildTestContainer.sh 2.5.33 /mnt/c/mchyzer/git/grouper_container"
exit 1
fi

export grouperBaseContainerVersion=$1
export grouperContainerGitPath=$2
export subimageName=my-grouper-$1

export reldir=`dirname $0`

# /mnt/c/mchyzer/git/grouper_container
mkdir -p $reldir/slashRoot/usr/local/bin
rsync -avzpl $grouperContainerGitPath/container_files/usr-local-bin/* $reldir/slashRoot/usr/local/bin

rsync -avzpl $grouperContainerGitPath/container_files/tier-support/test/grouper*.sh $reldir

mkdir -p $reldir/slashRoot/opt/tomee/conf
rsync -avzpl $grouperContainerGitPath/container_files/tomee/conf/* $reldir/slashRoot/opt/tomee/conf/

docker build -f $reldir/testContainer.Dockerfile -t $subimageName --build-arg GROUPER_VERSION=$grouperBaseContainerVersion $reldir

echo "Run tests with: ./grouperContainerUnitTest.sh grouper-test $subimageName:latest $grouperBaseContainerVersion $grouperBaseContainerVersion"
11 changes: 11 additions & 0 deletions container_files/tier-support/test/testContainer.Dockerfile
@@ -0,0 +1,11 @@
# this matches the version you decided on from release notes
ARG GROUPER_VERSION=2.5.XX

# --build-arg GROUPER_VERSION=${VARIABLE_NAME}
FROM i2incommon/grouper:${GROUPER_VERSION}

# this will overlay all the files from /opt/grouperContainer/slashRoot on to /
COPY slashRoot /

RUN chown -R tomcat:tomcat /opt/grouper \
&& chown -R tomcat:tomcat /opt/tomee
2 changes: 1 addition & 1 deletion container_files/tomee/conf/server.xml.turnOnAjp.patch
@@ -10,7 +10,7 @@
- port="8009"
- redirectPort="8443" />
- -->
+ <Connector secretRequired="false" secure="true" scheme="https" URIEncoding="UTF-8" tomcatAuthentication="false" port="8009" protocol="AJP/1.3" redirectPort="8443" />
+ <Connector secretRequired="false" secure="true" scheme="https" URIEncoding="UTF-8" tomcatAuthentication="false" port="8009" protocol="AJP/1.3" redirectPort="8443" address="0.0.0.0" allowedRequestAttributesPattern=".*" />
+

<!-- An Engine represents the entry point (within Catalina) that processes
8 changes: 5 additions & 3 deletions container_files/usr-local-bin/changeGid.sh
@@ -1,16 +1,18 @@
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "grouperContainer; ERROR: (changeGid.sh) This script must be run as root"
exit 1
fi
if [ "$#" -ne 2 ]; then
echo "You must enter exactly 2 command line arguments: groupname, and gid to change to"
echo "grouperContainer; ERROR: (changeGid.sh) You must enter exactly 2 command line arguments: groupname, and gid to change to"
exit 1
fi
groupname=$1
newGid=$2
getentOutput="$(getent group "$groupname")"
oldGid="$( echo "$getentOutput" |cut -d\: -f3 )"
groupmod -g "$newGid" "$groupname"
find / -xdev -type d -group "$oldGid" -exec chgrp -h "$groupname" {} \;
echo "grouperContainer; INFO: (changeGid.sh) groupmod -g $newGid $groupname , result: $?"
find / -xdev -type d -group "$oldGid" -exec chgrp -h "$groupname" {} \;
echo "grouperContainer; INFO: (changeGid.sh) find / -xdev -type d -group $oldGid -exec chgrp -h $groupname {} \; , result: $?"
6 changes: 4 additions & 2 deletions container_files/usr-local-bin/changeUid.sh
@@ -1,15 +1,17 @@
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "grouperContainer; ERROR: (changeUid.sh) This script must be run as root"
exit 1
fi
if [ "$#" -ne 2 ]; then
echo "You must enter exactly 2 command line arguments: username, and uid to change to"
echo "grouperContainer; ERROR: (changeUid.sh) You must enter exactly 2 command line arguments: username, and uid to change to"
exit 1
fi
username=$1
newUid=$2
oldUid="$(id -u "$username")"
usermod -u "$newUid" "$username"
echo "grouperContainer; INFO: (changeUid.sh) usermod -u $newUid $username , result: $?"
find / -xdev -type d -user "$oldUid" -exec chown -h "$username" {} \;
echo "grouperContainer; INFO: (changeUid.sh) find / -xdev -type d -user $oldUid -exec chown -h $username {} \; , result: $?"
4 changes: 2 additions & 2 deletions container_files/usr-local-bin/entrypoint.sh
@@ -5,7 +5,7 @@ prep_conf

if [ "$#" -eq 0 ];
then
echo no component set to run
echo "grouperContainer; INFO: (entrypoint.sh) No component set to run"
prep_finish
setupFiles
runCommand
@@ -31,7 +31,7 @@ else
GROUPER_ENTRYPOINT_COMMAND=gsh
fi

echo executing "$GROUPER_ENTRYPOINT_COMMAND $@"
echo "grouperContainer; INFO: (entrypoint.sh) Executing $GROUPER_ENTRYPOINT_COMMAND $@"
exec "$GROUPER_ENTRYPOINT_COMMAND" "$@"
fi

2 changes: 2 additions & 0 deletions container_files/usr-local-bin/library.sh
@@ -1,5 +1,6 @@
#!/bin/sh

echo "grouperContainer; INFO: (library.sh) Start loading library.sh"
. /usr/local/bin/libraryPrep.sh
. /usr/local/bin/libraryPrepOnly.sh
. /usr/local/bin/libraryRunCommand.sh
@@ -15,4 +16,5 @@

# implementations of custom hooks
. /usr/local/bin/grouperScriptHooks.sh
echo "grouperContainer; INFO: (library.sh) End loading library.sh"

14 changes: 9 additions & 5 deletions container_files/usr-local-bin/libraryPrep.sh
@@ -87,19 +87,22 @@ prep_ws() {
}

prep_conf() {

echo "grouperContainer; INFO: (libraryPrep.sh-prep_conf) Start setting up initial pipes"
setupPipe_logging
setupPipe_supervisordLog
setupPipe_grouperLog
echo "grouperContainer; INFO: (libraryPrep.sh-prep_conf) End setting up initial pipes"

# if we are stopping and starting, we just read the env vars and we done
if [ -f /opt/grouper/grouperEnv.sh ]
then
echo "Loading env vars from /opt/grouper/grouperEnv.sh"
echo "grouperContainer; INFO: (libraryPrep.sh-prep_conf) Loading env vars from /opt/grouper/grouperEnv.sh"
. /opt/grouper/grouperEnv.sh
return
fi

prep_initDeprecatedEnvVars
setupPipe_logging
setupPipe_supervisordLog
setupPipe_grouperLog
grouperScriptHooks_prepConfPost

}
@@ -191,7 +194,7 @@ prep_finish() {

if [ "$GROUPER_SETUP_FILES_COMPLETE" = "true" ]
then
echo "GROUPER_SETUP_FILES_COMPLETE=true, skipping startup prep"
echo "grouperContainer; INFO: (libraryPrep.sh-prep_finish) GROUPER_SETUP_FILES_COMPLETE=true, skipping startup prep"
prep_unsetAllAndFromFiles

return
@@ -212,6 +215,7 @@ prep_finish() {
grouperScriptHooks_finishPrepPost

prep_unsetAllAndFromFiles
echo "grouperContainer; INFO: (libraryPrep.sh-prep_finish) End prep"
}

prep_unsetAllAndFromFiles() {
11 changes: 11 additions & 0 deletions container_files/usr-local-bin/libraryRunCommand.sh
@@ -2,18 +2,29 @@

runCommand() {

echo "grouperContainer; INFO: (libraryRunCommand.sh-runCommand) Start setting up remaining pipes"
setupPipe_hsqldbLog
setupPipe_httpdLog
setupPipe_shibdLog
setupPipe_tomcatLog
setupPipe_tomcatAccessLog
echo "grouperContainer; INFO: (libraryRunCommand.sh-runCommand) End setting up remainder pipes"

runCommand_unsetAll

if [ "$GROUPER_RUN_TOMCAT_NOT_SUPERVISOR" = "true" ]
then
echo "grouperContainer; INFO: (libraryRunCommand.sh-runCommand) Starting tomcat not supervisor"
/opt/tomee/bin/catalina.sh run
else
echo "grouperContainer; INFO: (libraryRunCommand.sh-runCommand) Starting supervisor"
exec /usr/bin/supervisord -c /opt/tier-support/supervisord.conf
fi

}

runCommand_unsetAll() {
setupPipe_unsetAll
unset -f runCommand
unset -f runCommand_unsetAll
}
16 changes: 11 additions & 5 deletions container_files/usr-local-bin/librarySetupFiles.sh
@@ -28,26 +28,32 @@ setupFiles_rsyncSlashRoot() {
setupFiles_localLogging() {
if [ "$GROUPER_LOG_TO_HOST" = "true" ]
then
cp -v /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.grouperContainerHost.properties /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.properties
cp /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.grouperContainerHost.properties /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.properties
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_localLogging) cp /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.grouperContainerHost.properties /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.properties, result: $?"
fi

}

setupFiles_loggingPrefix() {
sed -i "s|__GROUPER_LOG_PREFIX__|$GROUPER_LOG_PREFIX|g" /opt/grouper/grouperWebapp/WEB-INF/classes/log4j.properties
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_loggingPrefix) Changing log prefix to $GROUPER_LOG_PREFIX in log4j.properties, result: $?"
}

setupFiles_chownDirs() {
# do this last
if [ "$GROUPER_CHOWN_DIRS" = "true" ]
then
chown -R tomcat:tomcat /opt/grouper/grouperWebapp
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_chownDirs) chown -R tomcat:tomcat /opt/grouper/grouperWebapp, result: $?"
chown -R tomcat:tomcat /opt/tomee
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_chownDirs) chown -R tomcat:tomcat /opt/tomee, result: $?"
fi
}

setupFiles_storeEnvVars() {

echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_storeEnvVars) Start store env vars in /opt/grouper/grouperEnv.sh"

echo "#!/bin/sh" > /opt/grouper/grouperEnv.sh
echo "" >> /opt/grouper/grouperEnv.sh

@@ -58,7 +64,7 @@ setupFiles_storeEnvVars() {

if [ ! -f /home/tomcat/.bashrc ]
then
echo "Why doesnt /home/tomcat/.bashrc exist????"
echo "grouperContainer; ERROR: (librarySetupFiles.sh-setupFiles_storeEnvVars) Why doesnt /home/tomcat/.bashrc exist????"
exit 1
fi
if ! grep -q grouperEnv /home/tomcat/.bashrc
@@ -73,7 +79,7 @@ setupFiles_storeEnvVars() {
# we need these global
if [ ! -f /etc/bashrc ]
then
echo "Why doesnt /etc/bashrc exist????"
echo "grouperContainer; ERROR: (librarySetupFiles.sh-setupFiles_storeEnvVars) Why doesnt /etc/bashrc exist????"
exit 1
fi
if ! grep -q GROUPER_GSH_CHECK_USER /etc/bashrc
@@ -86,13 +92,14 @@ setupFiles_storeEnvVars() {
echo "" >> /etc/bashrc
fi
fi
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles_storeEnvVars) End store env vars in /opt/grouper/grouperEnv.sh"
}

setupFiles() {

if [ "$GROUPER_SETUP_FILES_COMPLETE" = "true" ]
then
echo "GROUPER_SETUP_FILES_COMPLETE=true, skipping setting up files"
echo "grouperContainer; INFO: (librarySetupFiles.sh-setupFiles) GROUPER_SETUP_FILES_COMPLETE=true, skipping setting up files"
setupFiles_unsetAllAndFromFiles
return
fi
@@ -141,7 +148,6 @@ setupFiles_unsetAllAndFromFiles() {
setupFilesForComponent_unsetAll
setupFilesForProcess_unsetAll
setupFilesTomcat_unsetAll
setupPipe_unsetAll
grouperScriptHooks_unsetAll

}

0 comments on commit 93ca3ab

Please sign in to comment.