Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
*.tar.gz
*.war
.DS_Store
image_version.yml
metacat-bin-*.tar.gz
metacat*.properties
test.properties
100 changes: 74 additions & 26 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if [ -z $1 ] ;
echo "Usage: $0 <version> (<uid> <gid>)"
exit
fi
SOLR_VERSION=8.9
BUILD_ARGS="${BUILD_ARGS} --build-arg SOLR_VERSION=$SOLR_VERSION"

BUILD_ARGS=""
if [ ! -z $2 ] ;
Expand All @@ -29,42 +31,88 @@ then
fi


VERSION=$1

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

#Read the split words into an array based on space delimiter
VERSION=$1
IFS='.' read -a version_array <<< "${VERSION}"

# Get Metacat
METACAT=metacat-bin-${VERSION}
ARCHIVE=${METACAT}.tar.gz
if [ ${#version_array[*]} -lt 3 ];
then
echo "ERROR: Version ${VERSION} must be three numbers it is ${#version_array[*]}"
exit
fi
version_major=${version_array[0]}
version_minor=${version_array[1]}
echo "INFO: Metacat major:$version_major minor:$version_minor"

BUILD_ARGS="${BUILD_ARGS} --build-arg METACAT_VERSION=${VERSION}"

if [ ! -f $DIR/${ARCHIVE} ];
# Check the version number
# Continue if form Metacat 2.13 and greater
if [ $version_major -eq 2 ] && [ $version_minor -ge 13 ] || [ $version_major -ge 3 ];
then

wget http://knb.ecoinformatics.org/software/dist/${ARCHIVE} -O $DIR/${ARCHIVE}
fi
# Get Metacat
METACAT=metacat-bin-${VERSION}
ARCHIVE=${METACAT}.tar.gz

# create the docker tag
DOCKER_TAG="${VERSION}-p$(cd $DIR; git rev-list HEAD --count)"
BUILD_ARGS="${BUILD_ARGS} --build-arg METACAT_VERSION=${VERSION}"

# CREATE image_version.yml
echo "****************************"
echo "BUILDING image_version"
echo "****************************"
IMAGE_VERSION_CONTENT="$(cd $DIR && git log -n 1 --pretty="commit_count: $(git rev-list HEAD --count)%ncommit_hash: %h%nsubject: %s%ncommitter: %cN <%ce>%ncommiter_date: %ci%nauthor: %aN <%ae>%nauthor_date: %ai%nref_names: %D" )"
echo "$IMAGE_VERSION_CONTENT" > $DIR/image_version.yml
cat $DIR/image_version.yml
# Get the metacat distribution
if [ ! -f "$DIR/${ARCHIVE}" ];
then
wget http://knb.ecoinformatics.org/software/dist/${ARCHIVE} -O $DIR/${ARCHIVE}

fi

# create the docker tag
DOCKER_TAG="${VERSION}-p$(cd $DIR; git rev-list HEAD --count)"

# CREATE image_version.yml
echo "****************************"
echo "BUILDING image_version"
echo "****************************"
IMAGE_VERSION_CONTENT="$(cd $DIR && git log -n 1 --pretty="commit_count: $(git rev-list HEAD --count)%ncommit_hash: %h%nsubject: %s%ncommitter: %cN <%ce>%ncommiter_date: %ci%nauthor: %aN <%ae>%nauthor_date: %ai%nref_names: %D" )"
echo "$IMAGE_VERSION_CONTENT" > $DIR/image_version.yml
cat $DIR/image_version.yml


# Determine if there is an image registry
IMAGE_NAME="metacat:${DOCKER_TAG}"
if [ "${REGISTRY_SPIN}" != "" ];
then
# There is a spin registry
IMAGE_NAME="${REGISTRY_SPIN}/${IMAGE_NAME}"
fi

echo "docker build ${DOCKER_BUILD_OPTIONS} -f $DIR/metacat/Dockerfile -t ${IMAGE_NAME} $BUILD_ARGS $DIR/"
docker build ${DOCKER_BUILD_OPTIONS} -f $DIR/metacat/Dockerfile -t ${IMAGE_NAME} $BUILD_ARGS $DIR/


rm -rf $DIR/metacat-index.war $DIR/solr/WEB-INF

# Get the solr config from the index war file for solr image
tar -xvf $DIR/${ARCHIVE} --directory $DIR metacat-index.war
unzip "$DIR/metacat-index.war" "WEB-INF/classes/solr-home/conf/*" -d "$DIR/solr"

# create the docker tag
DOCKER_TAG="${VERSION}-${SOLR_VERSION}-p$(cd $DIR; git rev-list HEAD --count)"

# Determine if there is an image registry
IMAGE_NAME="metacat-solr:${DOCKER_TAG}"
if [ "${REGISTRY_SPIN}" != "" ];
then
# There is a spin registry
IMAGE_NAME="${REGISTRY_SPIN}/${IMAGE_NAME}"
fi

echo "docker build ${DOCKER_BUILD_OPTIONS} -f $DIR/solr/Dockerfile -t ${IMAGE_NAME} $BUILD_ARGS $DIR/"
docker pull solr:${SOLR_VERSION}
docker build ${DOCKER_BUILD_OPTIONS} -f $DIR/solr/Dockerfile -t ${IMAGE_NAME} $BUILD_ARGS $DIR/
else

echo "ERROR: Metacat Version $VERSION not supported anymore. Please use Metacat>=2.13.0"

# Determine if there is an image registry
IMAGE_NAME="metacat:${DOCKER_TAG}"
if [ "${REGISTRY_SPIN}" != "" ];
then
# There is a spin registry
IMAGE_NAME="${REGISTRY_SPIN}/${IMAGE_NAME}"
fi

echo "docker build --no-cache -t ${IMAGE_NAME} $BUILD_ARGS $DIR"
docker pull tomcat:7.0-jre8
docker build ${DOCKER_BUILD_OPTIONS} -t ${IMAGE_NAME} $BUILD_ARGS $DIR
22 changes: 13 additions & 9 deletions Dockerfile → metacat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ ARG METACAT_UID=108
ARG METACAT_GID=121

ENV METACAT_APP_CONTEXT=metacat
ENV DB_HOST=db
ENV DB_PORT=5432
ENV DB_SOLR_HOST=db-solr
ENV DB_SOLR_PORT=8983
ARG METACAT_VERSION=2.8.7
ADD /metacat-bin-${METACAT_VERSION}.tar.gz /tmp/
ADD catalina.properties /tmp/
ADD server.xml.patch /tmp/
ADD metacat-bin-${METACAT_VERSION}.tar.gz /tmp/
ADD metacat/catalina.properties /tmp/
ADD metacat/server.xml.patch /tmp/
ADD metacat/skins /tmp/skins
ADD image_version.yml image_version.yml


Expand All @@ -28,15 +33,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& cp /tmp/metacat.war /tmp/metacat-index.war /usr/local/tomcat/webapps \
&& cat /tmp/catalina.properties >> /usr/local/tomcat/conf/catalina.properties

ADD metacat.conf /etc/logrotate.d/
ADD metacat/metacat.conf /etc/logrotate.d/

COPY apply_config.py /usr/local/bin/
COPY metacat/apply_config.py /usr/local/bin/
RUN ln -s usr/local/bin/apply_config.py / # backwards compat

COPY apply_context.py /usr/local/bin/
COPY metacat/apply_context.py /usr/local/bin/
RUN ln -s usr/local/bin/apply_context.py / # backwards compat

COPY docker-entrypoint.sh /usr/local/bin/
COPY metacat/docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

Expand All @@ -47,8 +52,7 @@ RUN patch conf/server.xml /tmp/server.xml.patch
RUN groupadd -g ${METACAT_GID} metacat && \
useradd -u ${METACAT_UID} -g ${METACAT_GID} -c 'Metacat User' --no-create-home metacat && \
mkdir -p /var/metacat && \
mkdir -p /var/metacat-fast && \
chown -R metacat:metacat /var/metacat /var/metacat-fast logs temp work && \
chown -R metacat:metacat /var/metacat logs temp work && \
chown -R metacat:metacat /usr/local/tomcat/conf && \
chown metacat:metacat /usr/local/tomcat/webapps && \
chmod g+s /usr/local/tomcat/webapps && \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 13 additions & 29 deletions docker-entrypoint.sh → metacat/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ if [ "$1" = 'bin/catalina.sh' ]; then
sleep 0.1
done

echo
echo '**************************************'
echo "Waiting for Solr to start "
echo '**************************************'
echo
while ! nc -z "${DB_SOLR_HOST:-db-solr}" "${DB_SOLR_PORT:-8983}"; do
sleep 0.1
done

echo
echo '**************************************'
echo "Logrotating catalina.out"
Expand Down Expand Up @@ -61,7 +70,7 @@ if [ "$1" = 'bin/catalina.sh' ]; then

DEFAULT_PROPERTIES_FILE=${METACAT_DIR}/WEB-INF/metacat.properties
APP_PROPERTIES_FILE=${APP_PROPERTIES_FILE:-/config/app.properties}
METACATUI_CUSTOM_SKINS_PATH=/config/skins
METACATUI_CUSTOM_SKINS_PATH=/tmp/skins
METACAT_VERSION_CONFIGURED=`grep application.metacatVersion $DEFAULT_PROPERTIES_FILE | sed 's/[^:]*=//'`


Expand Down Expand Up @@ -142,13 +151,13 @@ if [ "$1" = 'bin/catalina.sh' ]; then

# Make sure all default directories are available and owned by metacat
[ `stat -c '%U:%G' /var/metacat` = 'metacat:metacat' ] || chown metacat:metacat /var/metacat
[ `stat -c '%U:%G' /var/metacat-fast` = 'metacat:metacat' ] || chown metacat:metacat /var/metacat-fast

mkdir -p /var/metacat/data \
/var/metacat/inline-data \
/var/metacat/documents \
/var/metacat/temporary \
/var/metacat/logs
/var/metacat/logs \
/var/metacat/solr-temp

# Look for Tomcat Configuration to copy
if [ -d /config/conf ];
Expand All @@ -160,32 +169,7 @@ if [ "$1" = 'bin/catalina.sh' ]; then
done
fi


# Initialize the solr home directory
SOLR_CONF_LOCATION=/var/metacat-fast/solr-home
if [ ! -d ${SOLR_CONF_LOCATION} ];
then

# Setup env for Here Document
SOLR_CONF_DEFAULT_LOCATION=/usr/local/tomcat/webapps/metacat-index/WEB-INF/classes/solr-home
USER_PWFILE="/var/metacat/users/password.xml"
SOLR_CONF_FILES=`bash -c "cd ${SOLR_CONF_DEFAULT_LOCATION} && find ."`

echo "INFO SOLR_CONF_LOCATION ${SOLR_CONF_LOCATION}"
bash -c "mkdir -p $SOLR_CONF_LOCATION"

for SOLR_FILE in ${SOLR_CONF_FILES[@]}
do
NEW_DIR=$(dirname $SOLR_CONF_LOCATION/$SOLR_FILE)

mkdir -p $NEW_DIR
if [ -f $SOLR_CONF_DEFAULT_LOCATION/$SOLR_FILE ] && [ ! -f $SOLR_CONF_LOCATION/$SOLR_FILE ];
then
echo "cp ${SOLR_CONF_DEFAULT_LOCATION}/$SOLR_FILE $SOLR_CONF_LOCATION/$SOLR_FILE"
cp ${SOLR_CONF_DEFAULT_LOCATION}/$SOLR_FILE $SOLR_CONF_LOCATION/$SOLR_FILE
fi
done
fi
USER_PWFILE="/var/metacat/users/password.xml"

# If there is an admin/password set and it does not exist in the passwords file
# set it
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading