diff --git a/OracleDatabase/SingleInstance/extensions/README.md b/OracleDatabase/SingleInstance/extensions/README.md new file mode 100644 index 0000000000..3062c594f4 --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/README.md @@ -0,0 +1,24 @@ +# Build Extensions + +After creating the base image using buildDockerImage.sh, use buildExtensions.sh to build an extended image that will include all features present under the extensions folder. + +Once you have created the base image, go into the **extensions** folder and run the **buildExtensions.sh** script: + + [oracle@localhost dockerfiles]$ ./buildExtensions.sh -h + + Usage: buildExtensions.sh -a -x [extensions] -b [base image] -t [image name] [-o] [Docker build option] + Builds one of more Docker Image Extensions. + + Parameters: + -a: Build all extensions + -x: Space separated extensions to build. Defaults to all + Choose from : patching + -b: Base image to use + -t: name:tag for the extended image + -o: passes on Docker build option + +LICENSE UPL 1.0 + +Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + +The resulting image can be used in the same fashion as the base image. \ No newline at end of file diff --git a/OracleDatabase/SingleInstance/extensions/buildExtensions.sh b/OracleDatabase/SingleInstance/extensions/buildExtensions.sh new file mode 100644 index 0000000000..3432f82a3e --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/buildExtensions.sh @@ -0,0 +1,148 @@ +#!/bin/bash -e +# +# Since: Mar, 2020 +# Author: mohammed.qureshi@oracle.com +# Description: Build script for building Docker Image Extensions +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# + +SCRIPT_DIR=$(dirname $0) +SCRIPT_NAME=$(basename $0) + +usage() { + cat << EOF + +Usage: $SCRIPT_NAME -a -x [extensions] -b [base image] -t [image name] [-o] [Docker build option] +Builds one of more Docker Image Extensions. + +Parameters: + -a: Build all extensions + -x: Space separated extensions to build. Defaults to all + Choose from : $(for i in $(cd "$SCRIPT_DIR" && ls -d */); do echo -n "${i%%/} "; done) + -b: Base image to use + -t: name:tag for the extended image + -o: passes on Docker build option + +LICENSE UPL 1.0 + +Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + +EOF + +} + +############## +#### MAIN #### +############## + +# Parameters +DOCKEROPS="" +DOCKERFILE="Dockerfile" +BASE_IMAGE="oracle/database:19.3.0-ee" +IMAGE_NAME="oracle/database:ext" + +if [ "$#" -eq 0 ]; then + usage; + exit 1; +fi + +while getopts "ax:b:t:o:h" optname; do + case "$optname" in + a) + EXTENSIONS=$(for i in $(cd "$SCRIPT_DIR" && ls -d */); do echo -n "${i%%/} "; done) + ;; + x) + EXTENSIONS="$OPTARG" + ;; + b) + BASE_IMAGE="$OPTARG" + ;; + t) + IMAGE_NAME="$OPTARG" + ;; + o) + DOCKEROPS="$OPTARG" + ;; + h|?) + usage; + exit 1; + ;; + *) + # Should not occur + echo "Unknown error while processing options inside buildDockerImage.sh" + ;; + esac +done + +echo "==========================" +echo "DOCKER info:" +docker info +echo "==========================" + +# Proxy settings +PROXY_SETTINGS="" +if [ "${http_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg http_proxy=${http_proxy}" +fi + +if [ "${https_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg https_proxy=${https_proxy}" +fi + +if [ "${ftp_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg ftp_proxy=${ftp_proxy}" +fi + +if [ "${no_proxy}" != "" ]; then + PROXY_SETTINGS="$PROXY_SETTINGS --build-arg no_proxy=${no_proxy}" +fi + +if [ "$PROXY_SETTINGS" != "" ]; then + echo "Proxy settings were found and will be used during the build." +fi + +# ################## # +# BUILDING THE IMAGE # +# ################## # + +BUILD_START=$(date '+%s') + +cd "$SCRIPT_DIR" +for x in $EXTENSIONS; do + echo "Building extension $x..." + # Go into version folder + cd "$x" || { + echo "Could not find extension directory '$x'"; + exit 1; + } + docker build --force-rm=true --build-arg BASE_IMAGE="$BASE_IMAGE" \ + $DOCKEROPS $PROXY_SETTINGS -t $IMAGE_NAME -f $DOCKERFILE . || { + echo "" + echo "ERROR: Oracle Database Docker Image was NOT successfully created." + echo "ERROR: Check the output and correct any reported problems with the docker build operation." + exit 1 + } + BASE_IMAGE="$IMAGE_NAME" + cd .. +done + +# Remove dangling images (intermitten images with tag ) +docker image prune -f > /dev/null + +BUILD_END=$(date '+%s') +BUILD_ELAPSED=`expr $BUILD_END - $BUILD_START` + +echo "" +echo "" + +cat< $IMAGE_NAME + + Build completed in $BUILD_ELAPSED seconds. + +EOF diff --git a/OracleDatabase/SingleInstance/extensions/patching/Dockerfile b/OracleDatabase/SingleInstance/extensions/patching/Dockerfile new file mode 100644 index 0000000000..894c0528a2 --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/Dockerfile @@ -0,0 +1,67 @@ +# LICENSE UPL 1.0 +# +# Copyright (c) 1982-2020 Oracle and/or its affiliates. All rights reserved. +# +# ORACLE DOCKERFILES PROJECT +# -------------------------- +# This is the Dockerfile for Oracle Database with patching support +# +# REQUIREMETNS FOR THIS IMAGE +# ---------------------------------- +# +# +# HOW TO BUILD THIS IMAGE +# ----------------------- +# +# Run: +# $ docker build -t . --build-arg BASE_IMAGE=oracle/database:18.3.0-ee +# +# Pull base image +# --------------- +ARG BASE_IMAGE=oracle/database:19.3.0-ee +FROM ${BASE_IMAGE} as patching + +# Environment variables required for this build (do NOT change) +# ------------------------------------------------------------- +ENV HOST_PATCH_DIR="patches" \ + PATCH_DIR=/opt/install/patches \ + PATCH_DB_BINARIES_FILE="patchDBBinaries.sh" + +# Copy DB patches +COPY --chown=oracle:dba $HOST_PATCH_DIR $PATCH_DB_BINARIES_FILE $PATCH_DIR/ + +# Apply DB Patch +RUN chmod ug+x $PATCH_DIR/*.sh && \ + sync && \ + $PATCH_DIR/$PATCH_DB_BINARIES_FILE && \ + rm -rf $PATCH_DIR/* $ORACLE_HOME/.patch_storage + + +## New stage for minimal layer size +FROM ${BASE_IMAGE} +ENV DATAPATCH_FILE="runDatapatch.sh" \ + LSPATCHES_FILE="savePatchSummary.sh" + +# Extn name +ARG EXTENSION_NAME="patching" + +# Copying patched oracle_base from previous layer +COPY --chown=oracle:dba --from=patching $ORACLE_BASE $ORACLE_BASE + +# Copy script to run datapatch +COPY --chown=oracle:dba $DATAPATCH_FILE $ORACLE_BASE/scripts/startup +RUN chmod ug+x $ORACLE_BASE/scripts/startup/*.sh && sync + +# Copy script to run lspatches +COPY --chown=oracle:dba $LSPATCHES_FILE $ORACLE_BASE/scripts/setup +RUN chmod ug+x $ORACLE_BASE/scripts/setup/*.sh && sync + +# backup origin runOracle +RUN mv "$ORACLE_BASE/$RUN_FILE" "$ORACLE_BASE/$RUN_FILE.$EXTENSION_NAME" + +# Copy updated runOracle.sh +COPY --chown=oracle:dba $RUN_FILE $ORACLE_BASE/ +RUN chmod ug+x $ORACLE_BASE/*.sh && sync + +# Append a call to main runOracle +RUN echo -e "\n. $ORACLE_BASE/$RUN_FILE.$EXTENSION_NAME" >> "$ORACLE_BASE/$RUN_FILE" diff --git a/OracleDatabase/SingleInstance/extensions/patching/README.md b/OracleDatabase/SingleInstance/extensions/patching/README.md new file mode 100644 index 0000000000..7a2c88ce3e --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/README.md @@ -0,0 +1,7 @@ +# PATCH APPLICATION + +Applies patches on oracle home. 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 extensions/patching/patches directory inside subfolders release_update and one_offs respectively. + +Once the patches have been placed in the correct directories, use the buildExtensions.sh script to build the extended image with patch support. diff --git a/OracleDatabase/SingleInstance/extensions/patching/patchDBBinaries.sh b/OracleDatabase/SingleInstance/extensions/patching/patchDBBinaries.sh new file mode 100644 index 0000000000..9482bd51cf --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/patchDBBinaries.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# +# Since: March, 2020 +# Author: rishabh.y.gupta@oracle.com +# 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_count=$(ls $RU_DIR/*.zip 2> /dev/null | wc -l) +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 [ ! -z $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; +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; +done diff --git a/OracleDatabase/SingleInstance/extensions/patching/patches/one_offs/.keep b/OracleDatabase/SingleInstance/extensions/patching/patches/one_offs/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/OracleDatabase/SingleInstance/extensions/patching/patches/release_update/.keep b/OracleDatabase/SingleInstance/extensions/patching/patches/release_update/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/OracleDatabase/SingleInstance/extensions/patching/runDatapatch.sh b/OracleDatabase/SingleInstance/extensions/patching/runDatapatch.sh new file mode 100644 index 0000000000..fcbc08719b --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/runDatapatch.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# +# Since: March, 2020 +# Author: rishabh.y.gupta@oracle.com +# Description: Runs datapatch in a container while using existing datafiles if container is at different RU level +# than the container which created the datafiles +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# + +# LSPATCHES_FILE will have the patch summary of the datafiles. +DBCONFIG_DIR="${ORACLE_BASE}/oradata/dbconfig/${ORACLE_SID}" +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}; + +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 + echo "Datapatch execution has failed."; + exit 1; + else + echo "DONE: Datapatch execution." + cp ${temp_lspatches_file} ${LSPATCHES_FILE}; + fi +fi diff --git a/OracleDatabase/SingleInstance/extensions/patching/runOracle.sh b/OracleDatabase/SingleInstance/extensions/patching/runOracle.sh new file mode 100644 index 0000000000..39abf82427 --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/runOracle.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# +# Since: March, 2020 +# Author: rishabh.y.gupta@oracle.com +# Description: runOracle.sh for the patching extension +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# diff --git a/OracleDatabase/SingleInstance/extensions/patching/savePatchSummary.sh b/OracleDatabase/SingleInstance/extensions/patching/savePatchSummary.sh new file mode 100644 index 0000000000..8eff8a9a62 --- /dev/null +++ b/OracleDatabase/SingleInstance/extensions/patching/savePatchSummary.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# LICENSE UPL 1.0 +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# +# Since: March, 2020 +# Author: rishabh.y.gupta@oracle.com +# Description: Runs lspatches to save summary of installed patches just after new db is created. +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# + +LSPATCHES_FILE="${ORACLE_SID}.lspatches" +LSPATCHES_FILE_PATH="${ORACLE_BASE}/oradata/dbconfig/${ORACLE_SID}/${LSPATCHES_FILE}" + +$ORACLE_HOME/OPatch/opatch lspatches > ${LSPATCHES_FILE_PATH}; \ No newline at end of file