Skip to content

Commit

Permalink
Introduction of health checks + tests bug fix (oracle#621)
Browse files Browse the repository at this point in the history
* Add return code description
* Introduce healthcheck
* Remove cleanup call
* Make runImageBuildTests prereq for runContainerTests
* Change tests order to have newest release first
* Add XE test
  • Loading branch information
gvenzl authored and Djelibeybi committed Oct 30, 2017
1 parent 66b9b5e commit 2c75e6a
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 73 deletions.
8 changes: 6 additions & 2 deletions OracleDatabase/dockerfiles/11.2.0.2/Dockerfile.xe
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ ENV ORACLE_BASE=/u01/app/oracle \
INSTALL_DIR="$HOME/install" \
CONFIG_RSP="xe.rsp" \
RUN_FILE="runOracle.sh" \
PWD_FILE="setPassword.sh"
PWD_FILE="setPassword.sh" \
CHECK_DB_FILE="checkDBStatus.sh"

# Use second ENV so that variable get substituted
ENV PATH=$ORACLE_HOME/bin:$PATH

# Copy binaries
# -------------
COPY $INSTALL_FILE_1 $CONFIG_RSP $RUN_FILE $PWD_FILE $INSTALL_DIR/
COPY $INSTALL_FILE_1 $CONFIG_RSP $RUN_FILE $PWD_FILE $CHECK_DB_FILE $INSTALL_DIR/

# Install Oracle Express Edition
# ------------------------------
Expand All @@ -67,12 +68,15 @@ RUN yum -y install unzip libaio bc initscripts net-tools openssl && \
mv $INSTALL_DIR/$CONFIG_RSP $ORACLE_BASE/ && \
mv $INSTALL_DIR/$RUN_FILE $ORACLE_BASE/ && \
mv $INSTALL_DIR/$PWD_FILE $ORACLE_BASE/ && \
mv $INSTALL_DIR/$CHECK_DB_FILE $ORACLE_BASE/ && \
ln -s $ORACLE_BASE/$PWD_FILE / && \
cd $HOME && \
rm -rf $INSTALL_DIR && \
chmod ug+x $ORACLE_BASE/*.sh

VOLUME ["$ORACLE_BASE/oradata"]
EXPOSE 1521 8080
HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

CMD exec $ORACLE_BASE/$RUN_FILE
39 changes: 39 additions & 0 deletions OracleDatabase/dockerfiles/11.2.0.2/checkDBStatus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# LICENSE UPL 1.0
#
# Copyright (c) 1982-2017 Oracle and/or its affiliates. All rights reserved.
#
# Since: May, 2017
# Author: [email protected]
# Description: Checks the status of Oracle Database.
# Return codes: 0 = Database is open and ready to use
# 1 = Database is not open
# 2 = Sql Plus execution failed
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORAENV_ASK=NO
source oraenv

# Check Oracle DB status and store it in status
status=`sqlplus -s / as sysdba << EOF
set heading off;
set pagesize 0;
select status from v\\$instance;
exit;
EOF`
# Store return code from SQL*Plus
ret=$?
# SQL Plus execution was successful and database is open
if [ $ret -eq 0 ] && [ "$status" = "OPEN" ]; then
exit 0;
# Database is not open
elif [ "$status" != "OPEN" ]; then
exit 1;
# SQL Plus execution failed
else
exit 2;
fi;
2 changes: 2 additions & 0 deletions OracleDatabase/dockerfiles/12.1.0.2/Dockerfile.ee
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ WORKDIR /home/oracle

VOLUME ["$ORACLE_BASE/oradata"]
EXPOSE 1521 5500
HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
4 changes: 3 additions & 1 deletion OracleDatabase/dockerfiles/12.1.0.2/Dockerfile.se2
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ WORKDIR /home/oracle

VOLUME ["$ORACLE_BASE/oradata"]
EXPOSE 1521 5500

HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
22 changes: 7 additions & 15 deletions OracleDatabase/dockerfiles/12.1.0.2/checkDBStatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@
# Since: May, 2017
# Author: [email protected]
# Description: Checks the status of Oracle Database.
# The ORACLE_HOME, ORACLE_SID and the PATH has to be set.
#
# Return codes: 0 = Database is open and ready to use
# 1 = Database is not open
# 2 = Sql Plus execution failed
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

# Check that ORACLE_HOME is set
if [ "$ORACLE_HOME" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_HOME is not set. Please set ORACLE_HOME and PATH before invoking this script."
exit 3;
fi;

# Check that ORACLE_SID is set
if [ "$ORACLE_SID" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_SID is not set. Please set ORACLE_SID before invoking this script."
exit 3;
fi;
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
ORAENV_ASK=NO
source oraenv

# Check Oracle DB status and store it in status
status=`sqlplus -s / as sysdba << EOF
Expand Down
4 changes: 3 additions & 1 deletion OracleDatabase/dockerfiles/12.2.0.1/Dockerfile.ee
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ WORKDIR /home/oracle

VOLUME ["$ORACLE_BASE/oradata"]
EXPOSE 1521 5500

HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
2 changes: 2 additions & 0 deletions OracleDatabase/dockerfiles/12.2.0.1/Dockerfile.se2
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ WORKDIR /home/oracle

VOLUME ["$ORACLE_BASE/oradata"]
EXPOSE 1521 5500
HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
22 changes: 7 additions & 15 deletions OracleDatabase/dockerfiles/12.2.0.1/checkDBStatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@
# Since: May, 2017
# Author: [email protected]
# Description: Checks the status of Oracle Database.
# The ORACLE_HOME, ORACLE_SID and the PATH has to be set.
#
# Return codes: 0 = Database is open and ready to use
# 1 = Database is not open
# 2 = Sql Plus execution failed
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

# Check that ORACLE_HOME is set
if [ "$ORACLE_HOME" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_HOME is not set. Please set ORACLE_HOME and PATH before invoking this script."
exit 3;
fi;

# Check that ORACLE_SID is set
if [ "$ORACLE_SID" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_SID is not set. Please set ORACLE_SID before invoking this script."
exit 3;
fi;
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
ORAENV_ASK=NO
source oraenv

# Check Oracle DB status and store it in status
status=`sqlplus -s / as sysdba << EOF
Expand Down
2 changes: 1 addition & 1 deletion OracleDatabase/tests/runAllTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#

# Run image build tests
./runImageBuildTests.sh
./runImageBuildTests.sh && \
./runContainerTests.sh
35 changes: 19 additions & 16 deletions OracleDatabase/tests/runContainerTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function runContainerTest {
echo ""

# Run and start container
docker run -d -e ORACLE_SID="$ORACLE_SID" --name "$CON_NAME" "$IMAGE"
docker run -d --shm-size=1g -e ORACLE_SID="$ORACLE_SID" --name "$CON_NAME" "$IMAGE"

# Check whether Oracle is OK
checkOracle "$TEST_NAME" "$CON_NAME" "$ORACLE_SID"
Expand Down Expand Up @@ -80,29 +80,32 @@ function checkOracle {
done;
}

###################### TEST ###########################
###################### TEST 11.2.0.2 XE default ###########################

# Run 12.1.0.2 SE2 default container
runContainerTest "12.1.0.2 SE2 default database" "12.1.0.2-SE2-default" "oracle/database:12.1.0.2-se2"
# Run 11.2.0.2 XE default container
runContainerTest "11.2.0.2 XE default database" "11.2.0.2-XE-default" "oracle/database:11.2.0.2-xe"

###################### TEST ###########################
###################### TEST 12.2.0.1 EE default ###########################

# Run 12.1.0.2 EE default container
runContainerTest "12.1.0.2 EE default database" "12.1.0.2-EE-default" "oracle/database:12.1.0.2-ee"
# Run 12.2.0.1 EE default container
runContainerTest "12.2.0.1 EE default database" "12.2.0.1-EE-default" "oracle/database:12.2.0.1-ee"

###################### TEST 12.2.0.1 EE custom DB ###########################

# Run 12.2.0.1 EE custom container
runContainerTest "12.2.0.1-EE-custom database" "12.2.0.1-EE-custom" "oracle/database:12.2.0.1-ee" "TEST"

###################### TEST ###########################
###################### TEST 12.2.0.1 SE2 default ###########################

# Run 12.2.0.1 SE2 default container
runContainerTest "12.2.0.1 SE2 default database" "12.2.0.1-SE2-default" "oracle/database:12.2.0.1-se2"

###################### TEST ###########################
###################### TEST 12.1.0.2 EE default ###########################

# Run 12.2.0.1 EE default container
runContainerTest "12.2.0.1 EE default database" "12.2.0.1-EE-default" "oracle/database:12.2.0.1-ee"
# Run 12.1.0.2 EE default container
runContainerTest "12.1.0.2 EE default database" "12.1.0.2-EE-default" "oracle/database:12.1.0.2-ee"

###################### TEST ###########################
###################### TEST 12.1.0.2 SE2 default ###########################

# Run 12.2.0.1 EE custom container
runContainerTest "12.2.0.1-EE-custom database" "12.2.0.1-EE-custom" "oracle/database:12.2.0.1-ee" "TEST"

# Run 12.2.0.1 EE custom characterset
# Run 12.1.0.2 SE2 default container
runContainerTest "12.1.0.2 SE2 default database" "12.1.0.2-SE2-default" "oracle/database:12.1.0.2-se2"
45 changes: 23 additions & 22 deletions OracleDatabase/tests/runImageBuildTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function checkError {

if [ "$RETURN_CODE" != "0" ]; then
echo "Test $TEST_NAME: FAILED!";
cleanup;
exit 1;
else
echo "Test $TEST_NAME: OK";
Expand All @@ -36,7 +35,7 @@ function checkError {

cd "../dockerfiles"

###################### TEST ###########################
###################### TEST 11.2.0.2 XE ###########################

# Copy binary file
cp $BIN_DIR/oracle-xe-11.2.0-1.0.x86_64.rpm.zip ./11.2.0.2/
Expand All @@ -48,19 +47,24 @@ checkError "Build 11.2.0.2 XE image" $?
# Delete binary file
rm ./11.2.0.2/oracle-xe-11.2.0-1.0.x86_64.rpm.zip

###################### TEST ###########################
###################### TEST 12.1.0.1 EE ###########################

# Copy binary file
cp $BIN_DIR/linuxamd64_12102_database_se2_*.zip ./12.1.0.2/
cp $BIN_DIR/linuxx64_12201_database.zip ./12.2.0.1/

# Build 12.1.0.2 SE2 images
./buildDockerImage.sh -s -v 12.1.0.2
checkError "Build 12.1.0.2 SE2 image" $?
# Build 12.2.0.1 EE images
./buildDockerImage.sh -e -v 12.2.0.1
checkError "Build 12.2.0.1 EE image" $?

# Delete binary file
rm ./12.1.0.2/*.zip
###################### TEST 12.2.0.1 SE2 ###########################

# Build 12.2.0.1 SE2 images
./buildDockerImage.sh -s -v 12.2.0.1
checkError "Build 12.2.0.1 SE2 image" $?

rm ./12.2.0.1/*.zip

###################### TEST ###########################
###################### TEST 12.1.0.2 EE ###########################

# Copy binary file
cp $BIN_DIR/linuxamd64_12102_database_1of2.zip ./12.1.0.2/
Expand All @@ -73,21 +77,18 @@ checkError "Build 12.1.0.2 EE image" $?
# Delete binary file
rm ./12.1.0.2/*.zip

###################### TEST ###########################
###################### TEST 12.1.0.2 SE2 ###########################

# Copy binary file
cp $BIN_DIR/linuxx64_12201_database.zip ./12.2.0.1/

# Build 12.2.0.1 SE2 images
./buildDockerImage.sh -s -v 12.2.0.1
checkError "Build 12.2.0.1 SE2 image" $?
cp $BIN_DIR/linuxamd64_12102_database_se2_*.zip ./12.1.0.2/

###################### TEST ###########################
# Build 12.1.0.2 SE2 images
./buildDockerImage.sh -s -v 12.1.0.2
checkError "Build 12.1.0.2 SE2 image" $?

# Build 12.2.0.1 EE images
./buildDockerImage.sh -e -v 12.2.0.1
checkError "Build 12.2.0.1 EE image" $?
# Delete binary file
rm ./12.1.0.2/*.zip

rm ./12.2.0.1/*.zip
######################### END OF TESTS ############################

cd "$WORKDIR";
cd "$WORKDIR";

0 comments on commit 2c75e6a

Please sign in to comment.