Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install DB and apply patches in a single layer #2594

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 8 additions & 3 deletions OracleDatabase/SingleInstance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ You may extend the image with your own Dockerfile and create the users and table
The character set for the database is set during creating of the database. 11gR2 Express Edition supports only UTF-8.
You can set the character set for the Standard Edition 2 and Enterprise Edition during the first run of your container and may keep separate folders containing different tablespaces with different character sets.

**NOTE**: This section is intended for container images 19c or higher which has patching extension support. By default, SLIMMING is **true** to remove some components from the image with the intention of making the image slimmer. These removed components cause problems while patching after building patching extension.
So, to use patching extension one should use additional build argument `-o '--build-arg SLIMMING=false'` while building the container image. Example command for building the container image is as follows:
#### Building container images with patches

./buildContainerImage.sh -e -v 21.3.0 -o '--build-arg SLIMMING=false'
**NOTE**: This section applies to 19c or higher. Earlier versions do not have patching extension support.

You may apply patches when building the Oracle Database container. Multiple one-offs can be applied in a single build but only 1 RU can be applied.

Download the release update and one-offs and place them under the `dockerfiles/<version>/patches/release_update` and `dockerfiles/<version>/patches/one_offs` directories respectively.

Once the patches have been placed in the correct directories, use the `buildContainerImage.sh` script to build the image with patches applied.

#### Building the container images using Podman

Expand Down
36 changes: 30 additions & 6 deletions OracleDatabase/SingleInstance/dockerfiles/19.3.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This is the Dockerfile for Oracle Database 19c
#
#
# REQUIRED FILES TO BUILD THIS IMAGE
# ----------------------------------
# (1) db_home.zip
Expand All @@ -15,8 +15,8 @@
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile
# Run:
# $ docker build -t oracle/database:19.3.0-${EDITION} .
# Run:
# $ docker build -t oracle/database:19.3.0-${EDITION} .
#
# Pull base image
# ---------------
Expand All @@ -37,7 +37,6 @@ LABEL "provider"="Oracle" \
"port.oemexpress"="5500"

# Argument to control removal of components not needed after db software installation
ARG SLIMMING=true
ARG INSTALL_FILE_1="LINUX.X64_193000_db_home.zip"

# Environment variables required for this build (do NOT change)
Expand All @@ -60,7 +59,6 @@ ENV ORACLE_BASE=/opt/oracle \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh" \
RELINK_BINARY_FILE="relinkOracleBinary.sh" \
CONFIG_TCPS_FILE="configTcps.sh" \
SLIMMING=$SLIMMING \
ENABLE_ARCHIVELOG=false \
ARCHIVELOG_DIR_NAME=archive_logs \
# To clone a database referred by PRIMARY_DB_CONN_STR
Expand All @@ -81,6 +79,11 @@ ENV PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib \
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

# Environment variables for patching
ENV HOST_PATCH_DIR="patches" \
PATCH_DIR=/opt/install/patches \
PATCH_DB_BINARIES_FILE="patchDBBinaries.sh"

# Copy files needed during both installation and runtime
# -------------
COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_DIR/
Expand Down Expand Up @@ -113,6 +116,14 @@ RUN chmod ug+x "$INSTALL_DIR"/*.sh && \
sync && \
"$INSTALL_DIR"/"$INSTALL_DB_BINARIES_FILE" $DB_EDITION

# Copy DB patches
COPY --chown=oracle:dba $HOST_PATCH_DIR $PATCH_DB_BINARIES_FILE $PATCH_DIR/

# Apply DB Patches
RUN chmod ug+x "$PATCH_DIR"/*.sh && \
sync && \
"$PATCH_DIR"/"$PATCH_DB_BINARIES_FILE"



#############################################
Expand All @@ -137,8 +148,21 @@ WORKDIR /home/oracle
# hadolint ignore=SC2016
RUN echo 'ORACLE_SID=${ORACLE_SID:-ORCLCDB}; export ORACLE_SID=${ORACLE_SID^^}' > .bashrc

# Environment variables for patching
ENV DATAPATCH_FILE="runDatapatch.sh" \
LSPATCHES_FILE="savePatchSummary.sh" \
SKIP_DATAPATCH=false

# Copy script to run datapatch
COPY --chown=oracle:dba $DATAPATCH_FILE $ORACLE_BASE/scripts/extensions/startup/
RUN chmod ug+x "$ORACLE_BASE"/scripts/extensions/startup/*.sh && sync

# Copy script to run lspatches
COPY --chown=oracle:dba $LSPATCHES_FILE $ORACLE_BASE/scripts/extensions/setup/
RUN chmod ug+x "$ORACLE_BASE"/scripts/extensions/setup/*.sh && sync

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

# Define default command to start Oracle Database.
# Define default command to start Oracle Database.
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Since: December, 2016
# Author: [email protected]
# Description: Sets up the unix environment for DB installation.
#
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
#

# Convert $1 into upper case via "^^" (bash version 4 onwards)
EDITION=${1^^}
Expand Down Expand Up @@ -56,32 +56,5 @@ rm "$INSTALL_FILE_1" && \
"$ORACLE_HOME"/runInstaller -silent -force -waitforcompletion -responsefile "$INSTALL_DIR"/"$INSTALL_RSP" -ignorePrereqFailure && \
cd "$HOME"

if $SLIMMING; then
# Remove not needed components
# APEX
rm -rf "$ORACLE_HOME"/apex && \
# ORDS
rm -rf "$ORACLE_HOME"/ords && \
# SQL Developer
rm -rf "$ORACLE_HOME"/sqldeveloper && \
# UCP connection pool
rm -rf "$ORACLE_HOME"/ucp && \
# All installer files
rm -rf "$ORACLE_HOME"/lib/*.zip && \
# OUI backup
rm -rf "$ORACLE_HOME"/inventory/backup/* && \
# Network tools help
rm -rf "$ORACLE_HOME"/network/tools/help && \
# Database upgrade assistant
rm -rf "$ORACLE_HOME"/assistants/dbua && \
# Database migration assistant
rm -rf "$ORACLE_HOME"/dmu && \
# Remove pilot workflow installer
rm -rf "$ORACLE_HOME"/install/pilot && \
# Support tools
rm -rf "$ORACLE_HOME"/suptools && \
# Temp location
rm -rf /tmp/* && \
# Database files directory
rm -rf "$INSTALL_DIR"/database
fi
# runInstaller will return exit code 6, but we want this script to complete successfully
exit 0;
100 changes: 100 additions & 0 deletions OracleDatabase/SingleInstance/dockerfiles/19.3.0/patchDBBinaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
# LICENSE UPL 1.0
#
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
#
# Since: March, 2020
# Author: [email protected]
# Description: Applies the patches provided by the user on the oracle home.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

RU_DIR="${PATCH_DIR}/release_update"
ONE_OFFS_DIR="${PATCH_DIR}/one_offs"

ru_files=("$RU_DIR"/*.zip)
ru_count=${#ru_files[@]}
if [ "$ru_count" -ge 2 ]; then
echo "Error: Only 1 Release Update can be applied."
exit 1;
elif [ "$ru_count" == 1 ]; then
ru_patch="$(ls "$RU_DIR"/*.zip)"
echo "Unzipping $ru_patch";
unzip -qo "$ru_patch" -d "$PATCH_DIR";
ru_patch=$(echo "${ru_patch##*/}" | cut -d_ -f1 | cut -dp -f2)
else
echo "No Release Update to be installed."
fi

ONE_OFFS_LIST=()

if ls "$ONE_OFFS_DIR"/*.zip 2> /dev/null; then
for patch_zip in "$ONE_OFFS_DIR"/*.zip; do
patch_no=$(echo "${patch_zip##*/}" | cut -d_ -f1 | cut -dp -f2)
if [ "$patch_no" == "6880880" ]; then
echo "Removing directory ${ORACLE_HOME}/OPatch";
rm -rf "${ORACLE_HOME}"/OPatch;
echo "Unzipping OPatch archive $patch_zip to ${ORACLE_HOME}";
unzip -qo "$patch_zip" -d "$ORACLE_HOME";
else
ONE_OFFS_LIST+=("$patch_no");
echo "Unzipping $patch_zip";
unzip -qo "$patch_zip" -d "$PATCH_DIR";
fi
done
else
echo "No one-offs to be installed."
fi

export PATH=${ORACLE_HOME}/perl/bin:$PATH;

if [ -n "$ru_patch" ]; then
echo "Applying Release Update: $ru_patch";
cmd="${ORACLE_HOME}/OPatch/opatchauto apply -binary -oh $ORACLE_HOME ${PATCH_DIR}/${ru_patch} -target_type rac_database";
echo "Running: $cmd";
$cmd || {
echo "RU application failed for patchset: ${ru_patch}";
exit 1;
}
fi

for patch in "${ONE_OFFS_LIST[@]}"; do
echo "Applying patch: $patch";
cmd="${ORACLE_HOME}/OPatch/opatchauto apply -binary -oh $ORACLE_HOME ${PATCH_DIR}/${patch} -target_type rac_database";
echo "Running: $cmd";
$cmd || {
echo "Patch application failed for ${patch}";
exit 1;
}
done

# Remove not needed components
# APEX
rm -rf "$ORACLE_HOME"/apex && \
# ORDS
rm -rf "$ORACLE_HOME"/ords && \
# SQL Developer
rm -rf "$ORACLE_HOME"/sqldeveloper && \
# UCP connection pool
rm -rf "$ORACLE_HOME"/ucp && \
# All installer files
rm -rf "$ORACLE_HOME"/lib/*.zip && \
# OUI backup
rm -rf "$ORACLE_HOME"/inventory/backup/* && \
# Network tools help
rm -rf "$ORACLE_HOME"/network/tools/help && \
# Database upgrade assistant
rm -rf "$ORACLE_HOME"/assistants/dbua && \
# Database migration assistant
rm -rf "$ORACLE_HOME"/dmu && \
# Remove pilot workflow installer
rm -rf "$ORACLE_HOME"/install/pilot && \
# Support tools
rm -rf "$ORACLE_HOME"/suptools && \
# Temp location
rm -rf /tmp/* && \
# Database files directory
rm -rf "$INSTALL_DIR"/database
# Database patch directories
rm -rf "${PATCH_DIR:?}/"* "$ORACLE_HOME"/.patch_storage
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ LSPATCHES_FILE="${DBCONFIG_DIR}/${ORACLE_SID}.lspatches"

# tmp.lspatches will have the patch summary of the oracle home.
temp_lspatches_file="/tmp/tmp.lspatches"
$ORACLE_HOME/OPatch/opatch lspatches > ${temp_lspatches_file};
"$ORACLE_HOME"/OPatch/opatch lspatches > ${temp_lspatches_file};

if diff ${LSPATCHES_FILE} ${temp_lspatches_file} 2> /dev/null; then
if diff "${LSPATCHES_FILE}" ${temp_lspatches_file} 2> /dev/null; then
echo "Datafiles are already patched. Skipping datapatch run."
else
echo "Running datapatch...";
if ! $ORACLE_HOME/OPatch/datapatch -skip_upgrade_check; then
if ! "$ORACLE_HOME"/OPatch/datapatch -skip_upgrade_check; then
echo "Datapatch execution has failed.";
exit 1;
else
echo "DONE: Datapatch execution."
cp ${temp_lspatches_file} ${LSPATCHES_FILE};
cp ${temp_lspatches_file} "${LSPATCHES_FILE}";
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
LSPATCHES_FILE="${ORACLE_SID}.lspatches"
LSPATCHES_FILE_PATH="${ORACLE_BASE}/oradata/dbconfig/${ORACLE_SID}/${LSPATCHES_FILE}"

$ORACLE_HOME/OPatch/opatch lspatches > ${LSPATCHES_FILE_PATH};
"$ORACLE_HOME"/OPatch/opatch lspatches > "${LSPATCHES_FILE_PATH}";
45 changes: 35 additions & 10 deletions OracleDatabase/SingleInstance/dockerfiles/21.3.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This is the Dockerfile for Oracle Database 21c
#
#
# REQUIRED FILES TO BUILD THIS IMAGE
# ----------------------------------
# (1) LINUX.X64_213000_db_home.zip
Expand All @@ -15,7 +15,7 @@
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile
# Run:
# Run:
# $ docker build -t oracle/database:21.3.0-${EDITION} .
#
# Pull base image
Expand All @@ -35,7 +35,6 @@ LABEL "provider"="Oracle" \
"port.oemexpress"="5500"

# Argument to control removal of components not needed after db software installation
ARG SLIMMING=true
ARG INSTALL_FILE_1="LINUX.X64_213000_db_home.zip"

# Environment variables required for this build (do NOT change)
Expand All @@ -59,7 +58,6 @@ ENV ORACLE_BASE=/opt/oracle \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh" \
RELINK_BINARY_FILE="relinkOracleBinary.sh" \
CONFIG_TCPS_FILE="configTcps.sh" \
SLIMMING=$SLIMMING \
ENABLE_ARCHIVELOG=false \
ARCHIVELOG_DIR_NAME=archive_logs \
# To clone a database referred by PRIMARY_DB_CONN_STR
Expand All @@ -80,6 +78,11 @@ ENV PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib \
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

# Environment variables for patching
ENV HOST_PATCH_DIR="patches" \
PATCH_DIR=/opt/install/patches \
PATCH_DB_BINARIES_FILE="patchDBBinaries.sh"

# Copy files needed during both installation and runtime
# -------------
COPY $SETUP_LINUX_FILE $CHECK_SPACE_FILE $INSTALL_DIR/
Expand Down Expand Up @@ -108,9 +111,17 @@ COPY --chown=oracle:dba $INSTALL_FILE_1 $INSTALL_RSP $INSTALL_DB_BINARIES_FILE $

# Install DB software binaries
USER oracle
RUN chmod ug+x $INSTALL_DIR/*.sh && \
RUN chmod ug+x "$INSTALL_DIR"/*.sh && \
sync && \
$INSTALL_DIR/$INSTALL_DB_BINARIES_FILE $DB_EDITION
"$INSTALL_DIR"/"$INSTALL_DB_BINARIES_FILE" $DB_EDITION

# Copy DB patches
COPY --chown=oracle:dba $HOST_PATCH_DIR $PATCH_DB_BINARIES_FILE $PATCH_DIR/

# Apply DB Patches
RUN chmod ug+x "$PATCH_DIR"/*.sh && \
sync && \
"$PATCH_DIR"/"$PATCH_DB_BINARIES_FILE"



Expand All @@ -126,17 +137,31 @@ USER oracle
COPY --chown=oracle:dba --from=builder $ORACLE_BASE $ORACLE_BASE

USER root
RUN $ORACLE_BASE/oraInventory/orainstRoot.sh && \
$ORACLE_HOME/root.sh
RUN "$ORACLE_BASE"/oraInventory/orainstRoot.sh && \
"$ORACLE_HOME"/root.sh

USER oracle
WORKDIR /home/oracle

# Add a bashrc file to capitalize ORACLE_SID in the environment
# hadolint ignore=SC2016
RUN echo 'ORACLE_SID=${ORACLE_SID:-ORCLCDB}; export ORACLE_SID=${ORACLE_SID^^}' > .bashrc

# Environment variables for patching
ENV DATAPATCH_FILE="runDatapatch.sh" \
LSPATCHES_FILE="savePatchSummary.sh" \
SKIP_DATAPATCH=false

# Copy script to run datapatch
COPY --chown=oracle:dba $DATAPATCH_FILE $ORACLE_BASE/scripts/extensions/startup/
RUN chmod ug+x "$ORACLE_BASE"/scripts/extensions/startup/*.sh && sync

# Copy script to run lspatches
COPY --chown=oracle:dba $LSPATCHES_FILE $ORACLE_BASE/scripts/extensions/setup/
RUN chmod ug+x "$ORACLE_BASE"/scripts/extensions/setup/*.sh && sync

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

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
# Define default command to start Oracle Database.
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Loading