Skip to content

Commit

Permalink
Merge branch 'main' into tcps_cert_order
Browse files Browse the repository at this point in the history
  • Loading branch information
gvenzl authored Aug 18, 2023
2 parents 77a97a3 + 8e59a92 commit 338a8bd
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 71 deletions.
12 changes: 10 additions & 2 deletions OracleDatabase/SingleInstance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Before you build the image make sure that you have provided the installation bin

[oracle@localhost dockerfiles]$ ./buildContainerImage.sh -h

Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x] [-i] [-o] [container build option]
Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x | -f] [-i] [-p] [-b] [-o] [container build option]
Builds a container image for Oracle Database.

Parameters:
Expand All @@ -44,6 +44,8 @@ Before you build the image make sure that you have provided the installation bin
-x: creates image based on 'Express Edition'
-f: creates image based on Database 'Free'
-i: ignores the MD5 checksums
-p: creates and extends image using the patching extension
-b: build base stage only (Used by extensions)
-o: passes on container build option

* select one edition only: -e, -s, -x, or -f
Expand All @@ -63,11 +65,17 @@ 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.

#### Building patched container images

**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:

./buildContainerImage.sh -e -v 21.3.0 -o '--build-arg SLIMMING=false'

Patched container images can now be built by specifying the parameter -p. Download the database version specific release update and one-offs and place them into the `extensions/patching/patches/release_update` and `extensions/patching/patches/one_offs` folder respectively. In this case, SLIMMING is internally set to **false**. Example command for building the patched container image is as follows:

./buildContainerImage.sh -e -v 21.3.0 -p

#### Building the container images using Podman

Building Oracle Database container images using Podman is similar to Docker. Some additional environment variables are required to be set for proper functioning. The description is as follows:
Expand Down Expand Up @@ -499,4 +507,4 @@ All scripts and files hosted in this project and GitHub [docker-images/OracleDat

## Copyright

Copyright (c) 2014,2021 Oracle and/or its affiliates.
Copyright (c) 2014,2023 Oracle and/or its affiliates.
56 changes: 49 additions & 7 deletions OracleDatabase/SingleInstance/dockerfiles/buildContainerImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2014,2021 Oracle and/or its affiliates.
# Copyright (c) 2014,2023 Oracle and/or its affiliates.
#

usage() {
cat << EOF
Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x | -f] [-i] [-o] [container build option]
Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x | -f] [-i] [-p] [-b] [-o] [container build option]
Builds a container image for Oracle Database.
Parameters:
Expand All @@ -24,6 +24,8 @@ Parameters:
-x: creates image based on 'Express Edition'
-f: creates images based on Database 'Free'
-i: ignores the MD5 checksums
-p: creates and extends image using the patching extension
-b: build base stage only (Used by extensions)
-o: passes on container build option
* select one edition only: -e, -s, -x, or -f
Expand Down Expand Up @@ -111,6 +113,8 @@ ENTERPRISE=0
STANDARD=0
EXPRESS=0
FREE=0
PATCHING=0
BASE_ONLY=0
# Obtaining the latest version to build
VERSION="$(find -- *.*.* -type d | tail -n 1)"
SKIPMD5=0
Expand All @@ -125,7 +129,7 @@ if [ "$#" -eq 0 ]; then
exit 1;
fi

while getopts "hesxfiv:t:o:" optname; do
while getopts "hesxfiv:t:o:pb" optname; do
case "${optname}" in
"h")
usage
Expand All @@ -146,6 +150,12 @@ while getopts "hesxfiv:t:o:" optname; do
"f")
FREE=1
;;
"p")
PATCHING=1
;;
"b")
BASE_ONLY=1
;;
"v")
VERSION="${OPTARG}"
;;
Expand Down Expand Up @@ -229,9 +239,12 @@ echo "$DOCKERFILE"
# If provided using -t build option then use it; Otherwise, create with version and edition
if [ -z "${IMAGE_NAME}" ]; then
IMAGE_NAME="oracle/database:${VERSION}-${EDITION}"
if [ ${BASE_ONLY} -eq 1 ]; then
IMAGE_NAME="oracle/database:${VERSION}-base"
fi
fi;

if [ ! "${SKIPMD5}" -eq 1 ]; then
if [ ${BASE_ONLY} -eq 0 ] && [ ! "${SKIPMD5}" -eq 1 ]; then
checksumPackages
else
echo "Ignored MD5 checksum."
Expand Down Expand Up @@ -267,6 +280,30 @@ if [ ${#PROXY_SETTINGS[@]} -gt 0 ]; then
echo "Proxy settings were found and will be used during the build."
fi

if [ ${PATCHING} -eq 1 ]; then
# Setting SLIMMING to false to support patching
BUILD_OPTS=("${BUILD_OPTS[@]}" "--build-arg" "SLIMMING=false" )
fi

# ############################# #
# BUILDING THE BASE STAGE IMAGE #
# ############################# #

if [ ${BASE_ONLY} -eq 1 ]; then
echo "Building base stage image '${IMAGE_NAME}' ..."
# BUILD THE BASE STAGE IMAGE (replace all environment variables)
"${CONTAINER_RUNTIME}" build --force-rm=true \
"${BUILD_OPTS[@]}" "${PROXY_SETTINGS[@]}" --target base \
-t "${IMAGE_NAME}" -f "${DOCKERFILE}" . || {
echo ""
echo "ERROR: Base stage image was NOT successfully created."
exit 1
}
# Remove dangling images (intermitten images with tag <none>)
yes | "${CONTAINER_RUNTIME}" image prune > /dev/null || true
exit
fi

# ################## #
# BUILDING THE IMAGE #
# ################## #
Expand All @@ -275,8 +312,8 @@ echo "Building image '${IMAGE_NAME}' ..."
# BUILD THE IMAGE (replace all environment variables)
BUILD_START=$(date '+%s')
"${CONTAINER_RUNTIME}" build --force-rm=true --no-cache=true \
"${BUILD_OPTS[@]}" "${PROXY_SETTINGS[@]}" --build-arg DB_EDITION="${EDITION}" \
-t "${IMAGE_NAME}" -f "${DOCKERFILE}" . || {
"${BUILD_OPTS[@]}" "${PROXY_SETTINGS[@]}" --build-arg DB_EDITION="${EDITION}" \
-t "${IMAGE_NAME}" -f "${DOCKERFILE}" . || {
echo ""
echo "ERROR: Oracle Database container image was NOT successfully created."
echo "ERROR: Check the output and correct any reported problems with the build operation."
Expand All @@ -299,4 +336,9 @@ cat << EOF
Build completed in ${BUILD_ELAPSED} seconds.
EOF
EOF

# EXTEND THE BUILT IMAGE BY APPLYING PATCHING EXTENSION
if [ ${PATCHING} -eq 1 ]; then
../../extensions/buildExtensions.sh -b "${IMAGE_NAME}" -t "${IMAGE_NAME}"-ext -v "${VERSION}" -x 'patching'
fi
5 changes: 3 additions & 2 deletions OracleDatabase/SingleInstance/extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ Once you have created the base image, go into the **extensions** folder and run

[oracle@localhost dockerfiles]$ ./buildExtensions.sh -h

Usage: buildExtensions.sh -a -x [extensions] -b [base image] -t [image name] [-o] [Docker build option]
Usage: buildExtensions.sh -a -x [extensions] -b [base image] -t [image name] -v [version] [-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
-v: Base version to extend (example 21.3.0)
-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.
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.

The resulting image can be used in the same fashion as the base image.
84 changes: 60 additions & 24 deletions OracleDatabase/SingleInstance/extensions/buildExtensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,69 @@
#
# Since: Mar, 2020
# Author: [email protected]
# Description: Build script for building Docker Image Extensions
# Description: Build script for building Container Image Extensions
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
#

SCRIPT_DIR=$(dirname $0)
SCRIPT_NAME=$(basename $0)
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.
Usage: $SCRIPT_NAME -a -x [extensions] -b [base image] -t [image name] -v [version] [-o] [container build option]
Builds one of more Container 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)
Choose from : $(for i in $(cd "$SCRIPT_DIR" && ls -d -- */); do echo -n "${i%%/} "; done)
-b: Base image to use
-v: Base version to extend (example 21.3.0)
-t: name:tag for the extended image
-o: passes on Docker build option
-o: passes on Container build option
LICENSE UPL 1.0
Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
EOF

}

# Check container runtime
checkContainerRuntime() {
CONTAINER_RUNTIME=$(which docker 2>/dev/null) ||
CONTAINER_RUNTIME=$(which podman 2>/dev/null) ||
{
echo "No docker or podman executable found in your PATH"
exit 1
}
}

##############
#### MAIN ####
##############

# Parameters
DOCKEROPS=""
DOCKERFILE="Dockerfile"
BASE_IMAGE="oracle/database:19.3.0-ee"
BASE_IMAGE="oracle/database:21.3.0-ee"
IMAGE_NAME="oracle/database:ext"
VERSION="21.3.0"

if [ "$#" -eq 0 ]; then
usage;
exit 1;
fi

while getopts "ax:b:t:o:h" optname; do
while getopts "ax:b:t:v:o:h" optname; do
case "$optname" in
a)
EXTENSIONS=$(for i in $(cd "$SCRIPT_DIR" && ls -d */); do echo -n "${i%%/} "; done)
EXTENSIONS=$(for i in $(cd "$SCRIPT_DIR" && ls -d -- */); do echo -n "${i%%/} "; done)
;;
x)
EXTENSIONS="$OPTARG"
Expand All @@ -63,6 +75,9 @@ while getopts "ax:b:t:o:h" optname; do
t)
IMAGE_NAME="$OPTARG"
;;
v)
VERSION="$OPTARG"
;;
o)
DOCKEROPS="$OPTARG"
;;
Expand All @@ -72,34 +87,35 @@ while getopts "ax:b:t:o:h" optname; do
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
echo "Unknown error while processing options inside buildContainerImage.sh"
;;
esac
done

echo "=========================="
echo "DOCKER info:"
docker info
echo "=========================="
# Check that we have a container runtime installed
checkContainerRuntime

# Proxy settings
PROXY_SETTINGS=""
# shellcheck disable=SC2154
if [ "${http_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg http_proxy=${http_proxy}"
fi

# shellcheck disable=SC2154
if [ "${https_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg https_proxy=${https_proxy}"
fi

# shellcheck disable=SC2154
if [ "${ftp_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg ftp_proxy=${ftp_proxy}"
fi

# shellcheck disable=SC2154
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
Expand All @@ -111,35 +127,55 @@ fi
BUILD_START=$(date '+%s')

cd "$SCRIPT_DIR"

# BUILD THE LINUX BASE FOR REUSE
../dockerfiles/buildContainerImage.sh -b -v "${VERSION}" -t "$BASE_IMAGE"-base

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" \

if [ "$x" == "patching" ]; then
if [ "$( (ls patches/one_offs && ls patches/release_update) | wc -l)" -eq 0 ]; then
echo "Patches Missing. Skipping Patching Extension"
if [ "$EXTENSIONS" == "patching" ]; then
exit
fi
cd ..
continue
fi
fi

# shellcheck disable=SC2086
"${CONTAINER_RUNTIME}" 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."
echo "ERROR: Oracle Database Container Image was NOT successfully created."
echo "ERROR: Check the output and correct any reported problems with the container build operation."
exit 1
}
"${CONTAINER_RUNTIME}" tag "$BASE_IMAGE"-base "$IMAGE_NAME"-base
BASE_IMAGE="$IMAGE_NAME"
cd ..
done

"${CONTAINER_RUNTIME}" rmi -f "$BASE_IMAGE"-base

# Remove dangling images (intermitten images with tag <none>)
docker image prune -f > /dev/null
"${CONTAINER_RUNTIME}" image prune -f > /dev/null

BUILD_END=$(date '+%s')
BUILD_ELAPSED=`expr $BUILD_END - $BUILD_START`
BUILD_ELAPSED=$(( BUILD_END - BUILD_START ))

echo ""
echo ""

cat<<EOF
Oracle Database Docker Image extended:
Oracle Database Container Image extended:
--> $IMAGE_NAME
Expand Down
Loading

0 comments on commit 338a8bd

Please sign in to comment.