From d4f29cf1108b6e467d3ade76022bdfe365f50926 Mon Sep 17 00:00:00 2001 From: oraclesean Date: Mon, 3 Jul 2023 15:59:52 -0600 Subject: [PATCH] First commit --- Dockerfile.11-19 | 56 ------ Dockerfile.11-19.dockerignore | 10 - Dockerfile.12-19 | 54 ------ Dockerfile.12-19.dockerignore | 10 - Dockerfile.19-21 | 57 ------ Dockerfile.19-21.dockerignore | 10 - README.md | 320 ++++++++++++++++++++++++++++--- buildDBImage.sh | 23 +-- config/manifest | 1 + config/manifest.11.2.0.2 | 1 - config/manifest.11.2.0.4 | 4 - config/manifest.12.1 | 6 - config/manifest.12.2 | 2 - config/manifest.18.3 | 3 - config/manifest.19 | 40 ---- config/manifest.21 | 11 -- functions.sh | 2 +- manageOracle.sh | 117 ++++------- templates/oraclelinux.dockerfile | 2 +- 19 files changed, 344 insertions(+), 385 deletions(-) delete mode 100644 Dockerfile.11-19 delete mode 100644 Dockerfile.11-19.dockerignore delete mode 100644 Dockerfile.12-19 delete mode 100644 Dockerfile.12-19.dockerignore delete mode 100644 Dockerfile.19-21 delete mode 100644 Dockerfile.19-21.dockerignore delete mode 100644 config/manifest.11.2.0.2 delete mode 100644 config/manifest.11.2.0.4 delete mode 100644 config/manifest.12.1 delete mode 100644 config/manifest.12.2 delete mode 100644 config/manifest.18.3 delete mode 100644 config/manifest.19 delete mode 100644 config/manifest.21 diff --git a/Dockerfile.11-19 b/Dockerfile.11-19 deleted file mode 100644 index 003382f..0000000 --- a/Dockerfile.11-19 +++ /dev/null @@ -1,56 +0,0 @@ -FROM oraclelinux:7-slim-19c - -# Database defaults -ARG ORACLE_VERSION=11.2.0.4 -ARG ORACLE_INV=/u01/app/oraInventory -ARG ORACLE_BASE=/u01/app/oracle -ARG ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1 -ARG ORADATA=/opt/oracle/oradata -ARG ORACLE_EDITION=EE -ARG ORACLE_SID=LAB - -ARG ORACLE_19C_HOME=$ORACLE_BASE/product/19c/dbhome_1 - -# Pass --build-arg DEBUG="bash -x" to run scripts in debug mode. -ARG DEBUG= - -# Environment settings -ENV ORACLE_BASE=$ORACLE_BASE \ - ORACLE_HOME=$ORACLE_HOME \ - ORACLE_19C_HOME=$ORACLE_19C_HOME \ - ORACLE_INV=$ORACLE_INV \ - ORADATA=$ORADATA \ - ORACLE_VERSION=$ORACLE_VERSION \ - ORACLE_EDITION=$ORACLE_EDITION \ - ORACLE_SID=$ORACLE_SID \ - DEBUG=$DEBUG \ - PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \ - CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib \ - LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib \ - TNS_ADMIN=$ORACLE_HOME/network/admin - -#COPY ./manageOracle.sh /opt/scripts/ - -USER oracle -COPY ./manageOracle.sh /opt/scripts/ -COPY --chown=oracle:oinstall --from=oraclesean/db:11.2.0.4-EE $ORACLE_INV $ORACLE_INV -COPY --chown=oracle:oinstall --from=oraclesean/db:11.2.0.4-EE $ORACLE_BASE $ORACLE_BASE -COPY --chown=oracle:oinstall --from=oraclesean/db:11.2.0.4-EE $ORADATA $ORADATA -COPY --chown=oracle:oinstall --from=oraclesean/db:19.13.1-EE $ORACLE_BASE $ORACLE_BASE -COPY ./bashrc19 /home/oracle/.bashrc -COPY ./config/login.sql.tmpl /home/oracle/login.sql - -USER root -RUN chmod 755 /opt/scripts/manageOracle.sh && \ - yum install -y gcc && yum clean all && \ - $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE -R && \ - $ORACLE_19C_HOME/root.sh - -USER oracle -RUN $ORACLE_19C_HOME/oui/bin/attachHome.sh -WORKDIR /home/oracle - -VOLUME ["$ORADATA"] -EXPOSE 1521 5500 8080 -HEALTHCHECK --interval=1m --start-period=5m CMD $SCRIPTS_DIR/$MANAGE_ORACLE -h >/dev/null || exit 1 -CMD exec $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE diff --git a/Dockerfile.11-19.dockerignore b/Dockerfile.11-19.dockerignore deleted file mode 100644 index 79a474f..0000000 --- a/Dockerfile.11-19.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -# Ignore files -Dockerfile* -.docker* -.git* -README.md -# Ignore all directories -** -!manageOracle.sh -!bashrc19 -!config/login.sql.tmpl diff --git a/Dockerfile.12-19 b/Dockerfile.12-19 deleted file mode 100644 index 16abc51..0000000 --- a/Dockerfile.12-19 +++ /dev/null @@ -1,54 +0,0 @@ -FROM oraclelinux:7-slim-19c - -# Database defaults -ARG ORACLE_VERSION=12.1 -ARG ORACLE_INV=/u01/app/oraInventory -ARG ORACLE_BASE=/u01/app/oracle -ARG ORACLE_HOME=$ORACLE_BASE/product/12.1/dbhome_1 -ARG ORADATA=/opt/oracle/oradata -ARG ORACLE_EDITION=EE -ARG ORACLE_SID=LAB - -ARG ORACLE_19C_HOME=$ORACLE_BASE/product/19c/dbhome_1 - -# Pass --build-arg DEBUG="bash -x" to run scripts in debug mode. -ARG DEBUG= - -# Environment settings -ENV ORACLE_BASE=$ORACLE_BASE \ - ORACLE_HOME=$ORACLE_HOME \ - ORACLE_19C_HOME=$ORACLE_19C_HOME \ - ORACLE_INV=$ORACLE_INV \ - ORADATA=$ORADATA \ - ORACLE_VERSION=$ORACLE_VERSION \ - ORACLE_EDITION=$ORACLE_EDITION \ - ORACLE_SID=$ORACLE_SID \ - DEBUG=$DEBUG \ - PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \ - CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib \ - LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib \ - TNS_ADMIN=$ORACLE_HOME/network/admin - -USER oracle -COPY ./manageOracle.sh /opt/scripts/ -COPY --chown=oracle:oinstall --from=oraclesean/db:12.1-EE $ORACLE_INV $ORACLE_INV -COPY --chown=oracle:oinstall --from=oraclesean/db:12.1-EE $ORACLE_BASE $ORACLE_BASE -COPY --chown=oracle:oinstall --from=oraclesean/db:12.1-EE $ORADATA $ORADATA -COPY --chown=oracle:oinstall --from=oraclesean/db:19.13.1-EE $ORACLE_BASE $ORACLE_BASE -COPY ./bashrc19 /home/oracle/.bashrc -COPY ./config/login.sql.tmpl /home/oracle/login.sql - -USER root -RUN chmod 755 /opt/scripts/manageOracle.sh && \ - yum install -y gcc && yum clean all && \ - $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE -R && \ - $ORACLE_19C_HOME/root.sh - -USER oracle -RUN $ORACLE_19C_HOME/oui/bin/attachHome.sh -WORKDIR /home/oracle - -VOLUME ["$ORADATA"] -EXPOSE 1521 5500 8080 -HEALTHCHECK --interval=1m --start-period=5m CMD $SCRIPTS_DIR/$MANAGE_ORACLE -h >/dev/null || exit 1 -CMD exec $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE diff --git a/Dockerfile.12-19.dockerignore b/Dockerfile.12-19.dockerignore deleted file mode 100644 index 79a474f..0000000 --- a/Dockerfile.12-19.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -# Ignore files -Dockerfile* -.docker* -.git* -README.md -# Ignore all directories -** -!manageOracle.sh -!bashrc19 -!config/login.sql.tmpl diff --git a/Dockerfile.19-21 b/Dockerfile.19-21 deleted file mode 100644 index f8e1b7e..0000000 --- a/Dockerfile.19-21 +++ /dev/null @@ -1,57 +0,0 @@ -FROM oraclelinux:7-slim-21c - -# Database defaults -ARG ORACLE_VERSION=19.13.1 -ARG ORACLE_INV=/u01/app/oraInventory -ARG ORACLE_BASE=/u01/app/oracle -ARG ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1 -ARG ORADATA=/opt/oracle/oradata -ARG ORACLE_EDITION=EE -ARG ORACLE_SID=LAB - -ARG ORACLE_21C_HOME=$ORACLE_BASE/product/21c/dbhome_1 - -# Pass --build-arg DEBUG="bash -x" to run scripts in debug mode. -ARG DEBUG= - -# Environment settings -ENV ORACLE_BASE=$ORACLE_BASE \ - ORACLE_HOME=$ORACLE_HOME \ - ORACLE_21C_HOME=$ORACLE_21C_HOME \ - ORACLE_INV=$ORACLE_INV \ - ORADATA=$ORADATA \ - ORACLE_VERSION=$ORACLE_VERSION \ - ORACLE_EDITION=$ORACLE_EDITION \ - ORACLE_SID=$ORACLE_SID \ - DEBUG=$DEBUG \ - PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \ - CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib \ - LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib \ - TNS_ADMIN=$ORACLE_HOME/network/admin - -USER oracle -COPY ./manageOracle.sh /opt/scripts/ -COPY --chown=oracle:oinstall --from=oraclesean/db:19.13.1-EE $ORACLE_INV $ORACLE_INV -COPY --chown=oracle:oinstall --from=oraclesean/db:19.13.1-EE $ORACLE_BASE $ORACLE_BASE -COPY --chown=oracle:oinstall --from=oraclesean/db:19.13.1-EE $ORADATA $ORADATA -COPY --chown=oracle:oinstall --from=oraclesean/db:21.5-EE $ORACLE_BASE $ORACLE_BASE -COPY ./bashrc21 /home/oracle/.bashrc -COPY ./config/login.sql.tmpl /home/oracle/login.sql - -USER root -RUN chmod 755 /opt/scripts/manageOracle.sh -RUN $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE -R - -USER root -RUN chmod 755 /opt/scripts/manageOracle.sh && \ - $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE -R && \ - $ORACLE_21C_HOME/root.sh - -USER oracle -RUN $ORACLE_21C_HOME/oui/bin/attachHome.sh -WORKDIR /home/oracle - -VOLUME ["$ORADATA"] -EXPOSE 1521 5500 8080 -HEALTHCHECK --interval=1m --start-period=5m CMD $SCRIPTS_DIR/$MANAGE_ORACLE -h >/dev/null || exit 1 -CMD exec $DEBUG $SCRIPTS_DIR/$MANAGE_ORACLE diff --git a/Dockerfile.19-21.dockerignore b/Dockerfile.19-21.dockerignore deleted file mode 100644 index 4ebd523..0000000 --- a/Dockerfile.19-21.dockerignore +++ /dev/null @@ -1,10 +0,0 @@ -# Ignore files -Dockerfile* -.docker* -.git* -README.md -# Ignore all directories -** -!manageOracle.sh -!bashrc21 -!config/login.sql.tmpl diff --git a/README.md b/README.md index 7d496ef..174abc4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ -# Update -May 5 2022: I'm in the process of updating the documentation to reflect changes to operation/architecture in this repo. Please bear with me as I make these changes! - -# docker-oracle -A repository of Docker image builds for creating Oracle databases. This repo replaces the other Docker repos I maintain. +# cloud-native-oracle +A repository of container image builds for Oracle databases, with support for Intel, Apple Silicon, and ARM processors. Jump to a section: - [Build an image](#build-an-image) @@ -18,7 +15,7 @@ Jump to a section: # Build an image One [reason behind this repo](#why-this-repo) was reducing duplication. I wanted one set of scripts (not one-per-version) and less maintenance. That created a need for more than one Dockerfile (one per version) because building 11g and 21c images is *mostly* boilerplate, but not entirely, and Dockerfiles don't take variables. This repo solves that by taking boilerplate Dockerfile templates, processing them to substitute variables, and using them for the build. Named Dockerfiles enable matching .dockerignore files to limit context. But, every version still needs a unique Dockerfile. Rather than polluting the directory with versioned Dockerfiles run directly with `docker build` I'm hiding the complexity with temporary files and a shell script. Version and edition information passed to the script generates temporary Dockerfile and .dockerignore files, runs `docker build`, then deletes the temporary file. -This is a temporary workaround. Dockerfile 1.4 and Buildx v0.8+, introduced in May 2022, add control over build context. I'm working on integrating the new capability. Until then, `buildDBImage.sh` manages Dockerfiles and builds. +This is a temporary workaround. I'm working on integrating new capabilities but until then, `buildDBImage.sh` manages Dockerfiles and builds. ## Build options and examples To build a database image, run `buildDBImage.sh` and pass optional values for version, edition, tag, source, and repository name: @@ -26,18 +23,60 @@ To build a database image, run `buildDBImage.sh` and pass optional values for ve ./buildDBImage.sh [version] [edition] [tag] [source] [repository] ``` -- `version`: The database version to build. The value must match a version in a manifest file. (Default: `19.14`) +- `version`: The database version to build. The value must match a version in a manifest file. (Default: `19.19`) - `edition`: The edition to build. Acceptable values: - `EE`: Enterprise Edition - 'SE`: Standard Edition, Standard Edition 2 - `XE`: Express Edition (Only for versions 11.2.0.2, 18.4) -- `tag`: The base OEL version. Options are `7-slim` or `8-slim`. (Default: `7-slim`) +- `tag`: The base OEL version. Options are `7-slim` or `8-slim`. (Default: `8-slim`) - `source`: The OEL source. (Default: `oraclelinux`) - `repository`: The image repository name assignment. (Default: `oraclesean/db`) Images created by the script are named as: `[repository]:[version]-[edition]` It additionally creates a version-specific Linux image: `[source]-[tag]-[base_version]` where the base version is 11g, 12.1, 12.2, 18c, 19c, or 21c. This Linux image includes the database prerequisites for the given version and makes building multiple database images for the same database version faster. The majority of the build time is spent applying prerequisite RPMs. The build understands if a version-ready image is present and uses it. +### Build example: Macs with Apple Silicon/ARM Systems +The only database currently supported for ARM architectures is Oracle 19.19. +- [Download the Oracle Database 19c for LINUX ARM (aarch64)](https://www.oracle.com/database/technologies/oracle-database-software-downloads.html#db_ee) zip file and place it in the `database` subdirectory. Do not unzip the file. +- From the base directory, run the `buildDBImage.sh` script: +``` +./buildDBImage.sh +# or: +./buildDBImage.sh 19.19 EE +``` +This will create two images +- A "database-ready" Oracle Enterprise Linux image, with `git`, `less`, `strace`, `tree`, `vi`, `which`, `bash-completion`, and `rlwrap` installed. + - Change these by editing the `RPM_LIST` in `templates/oraclelinux.dockerfile`, or pass a build argument. Note that you *must* include `hostname` and `file` on `oraclelinux:8-slim` builds. +- A database image with a default `ORACLE_BASE` under `/u01/app/oracle` and an `ORACLE_HOME` under `$ORACLE_BASE/product/19c/dbhome_1`. + - Change these by editing the entries in `templates/db.dockerfile`, or pass build arguments for each parameter. + +### Build example: Intel-based systems (Linux, Mac, Windows) +All database versions are supported. +- Download the appropriate installation file and place it in the `database` subdirectory. +- Download any patches to be installed and place them in the `database/patches` subdirectory. +- Update the `config/manifest` file if necessary. See the `README` file under `database` for details on formatting. +- From the base directory, run the `buildDBImage.sh` script, passing the appropriate database version, edition, and OS version: +``` +# Oracle 11g: +./buildDBImage.sh 11.2.0.4 EE 7-slim +# Oracle 12.1: +./buildDBImage.sh 12.1.0.1 EE 7-slim +# Oracle 12.2: +./buildDBImage.sh 12.2 EE 7-slim +# Oracle 18c: +./buildDBImage.sh 18.3 EE 7-slim +# Oracle 19c: +./buildDBImage.sh 19 EE +# or, to build a specific version: +./buildDBImage.sh EE +# ... where is the RU to apply atop the base 19.3 +# Oracle 21c: +./buildDBImage.sh 21 EE +# or, to build a specific version: +./buildDBImage.sh EE +# ... where is the RU to apply atop the base 21.3 +``` + ## FORCE_PATCH and `.netrc` When a `'.netrc` file is present, the `FORCE_PATCH` build argument enables patch downloads from My Oracle Support. Patches are downloaded when: - patches listed in the manifest aren't present in the build context (not added to the `./database/patches` directory) @@ -55,16 +94,6 @@ Pass the FORCE_PATCH value to `docker build` as `--build-arg FORCE_PATCH= [internal] load .dockerignore 0.0s + => => transferring context: 2B 0.0s + => [internal] load build definition from Dockerfile.oraclelinux.202307031409.jTxd 0.0s + => => transferring dockerfile: 1.55kB 0.0s + => [internal] load metadata for docker.io/library/oraclelinux:8-slim 1.3s + => [internal] load build context 0.0s + => => transferring context: 45.06kB 0.0s + => CACHED [1/3] FROM docker.io/library/oraclelinux:8-slim@sha256:0226d80b442e93f977753e1d 0.0s + => => resolve docker.io/library/oraclelinux:8-slim@sha256:0226d80b442e93f977753e1d269c8ec 0.0s + => [2/3] COPY manageOracle.sh /opt/scripts/ 0.0s + => [3/3] RUN chmod ug+x /opt/scripts/manageOracle.sh && /opt/scripts/manageOracle.sh 48.7s + => exporting to image 1.5s + => => exporting layers 1.5s + => => writing image sha256:6cdb5ddeb9d8ffbfcaeba0cb1fad0c003dbffc3cd77b204a8ddc60292e184b 0.0s + => => naming to docker.io/library/oraclelinux:8-slim-19c 0.0s +oraclelinux:8-slim-19c +[+] Building 193.8s (21/21) FINISHED docker:desktop-linux + => [internal] load .dockerignore 0.0s + => => transferring context: 2B 0.0s + => [internal] load build definition from Dockerfile.db.202307031410.NUni 0.0s + => => transferring dockerfile: 5.11kB 0.0s + => resolve image config for docker.io/docker/dockerfile:1.4 0.9s + => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727c 0.0s + => [internal] load metadata for docker.io/library/oraclelinux:8-slim-19c 0.0s + => [db 1/6] FROM docker.io/library/oraclelinux:8-slim-19c 0.0s + => [internal] load build context 38.5s + => => transferring context: 2.42GB 38.5s + => [db 2/6] COPY --chown=oracle:oinstall manageOracle.sh /opt/scripts/ 0.6s + => [stage-1 2/9] COPY --chown=oracle:oinstall ./config/dbca.* /opt/install/ 0.6s + => [stage-1 3/9] COPY --chown=oracle:oinstall ./config/*.tmpl /opt/install/ 0.0s + => [db 3/6] COPY --chown=oracle:oinstall ./config/inst.* /opt/install/ 0.0s + => [db 4/6] COPY --chown=oracle:oinstall ./config/manifest.* /opt/install/ 0.0s + => [stage-1 4/9] COPY --chown=oracle:oinstall manageOracle.sh /opt/scripts/ 0.0s + => [db 5/6] COPY --chown=oracle:oinstall ./database/ /opt/install/ 6.3s + => [db 6/6] RUN chmod ug+x /opt/scripts/manageOracle.sh && /opt/scripts/manageOracl 98.9s + => [stage-1 5/9] COPY --chown=oracle:oinstall --from=db /u01/app/oraInventory /u01/app/o 0.0s + => [stage-1 6/9] COPY --chown=oracle:oinstall --from=db /u01/app/oracle /u01/app/oracle 18.6s + => [stage-1 7/9] COPY --chown=oracle:oinstall --from=db /opt/oracle/oradata /opt/orac 0.0s + => [stage-1 8/9] RUN /opt/scripts/manageOracle.sh -R 0.5s + => [stage-1 9/9] WORKDIR /home/oracle 0.0s + => exporting to image 17.6s + => => exporting layers 17.6s + => => writing image sha256:4874efbbfe1cfb271e314ed8d6d0773e5a270d1a0b789861af76e59d4b6f82 0.0s + => => naming to docker.io/oraclesean/db:19.19-EE 0.0s +``` + +Total build time was 245.4 seconds. After building the image: +``` +# docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +oraclesean/db 19.19-EE 4874efbbfe1c About an hour ago 5.87GB +oraclelinux 8-slim-19c 6cdb5ddeb9d8 About an hour ago 690MB +``` + +The ARM image size is about 2GB smaller than its corresponding Intel-based image. + +Here's an example of running a network and container, with volumes defined for data, database logs, the audit directory, and a scripts directory. + +## Create a network (optional) +This creates a network called `oracle-db`. This step is optional; if you elect to not create a network here, be sure to remove the network assignment from the `docker run` command. +``` +docker network create oracle-db --attachable --driver bridge +``` + +## Set the container name and data path +Set a name for the container and a path to mount bind volumes. +``` +CONTAINER_NAME=ARM +ORADATA=~/oradata +``` + +## Create volumes +I cannot overemphasize the value of volumes for Oracle databases. They persist data outside the container and make data independent of the container itself. Putting volatile directories outside the container's filesystem improves performance. And, volumes don't "hide" data in the `/var/lib/docker` directory of the virtual machine. You have better visibility into space use, and you're far less likely to fill the VM's disk. + +## Create a script directory (optional) +This creates a shared directory in the container for saving/sharing files between container and host. If you bypass this step, be sure to remove the corresponding definition from the `docker run` command later. +``` +mkdir -p $ORADATA/scripts +``` + +## Create the audit, data, and diagnostic directories +This creates separate subdirectories for each file type and bind mounts them to Docker volumes. Assigning them to Docker volumes means they're visible in the Docker Desktop tool, as well as through the CLI via `docker volume ls` and other commands. +``` + for dir in audit data diag + do mkdir -p $ORADATA/${CONTAINER_NAME}/${dir} + rm -fr $ORADATA/${CONTAINER_NAME}/${dir}/* + docker volume rm ${CONTAINER_NAME}_${dir} 2>/dev/null + docker volume create --opt type=none --opt o=bind \ + --opt device=$ORADATA/${CONTAINER_NAME}/${dir} \ + ${CONTAINER_NAME}_${dir} +done +``` + +## Remove the container (if it already exists) +If you created a container by the same name, remove it before recreating it. +``` +docker rm -f $CONTAINER_NAME 2>/dev/null +``` + +## Create the container +In the following command, I'm creating a container named `$CONTAINER_NAME`, then: +- Mapping volumes for data (`/opt/oracle/oradata`), log data (`/u01/app/oracle/diag`), audit files (`/u01/app/oracle/admin`), and a shared directory for scripts (`/scripts`) +- Assigning the container to a network called `oracle-db` +- Setting the database SID +- Setting the name of the PDB to ${CONTAINER_NAME}PDB1 +- Mapping port 8080 in the container to port 8080 on the host +- Mapping port 1521 in the container to port 51521 on the host +``` +docker run -d \ + --name ${CONTAINER_NAME} \ + --volume ${CONTAINER_NAME}_data:/opt/oracle/oradata \ + --volume ${CONTAINER_NAME}_diag:/u01/app/oracle/diag \ + --volume ${CONTAINER_NAME}_audit:/u01/app/oracle/admin \ + --volume $ORADATA/scripts:/scripts \ + --network oracle-db \ + -e ORACLE_SID=${CONTAINER_NAME} \ + -e ORACLE_PDB=${CONTAINER_NAME}PDB1 \ + -p 8080:8080 \ + -p 51521:1521 \ + oraclesean/db:19.19-EE +``` + +Add or remove options as you see fit. + +## Monitor the database creation and logs +View the database activity: +``` +docker logs -f $CONTAINER_NAME +``` + +Sample output from a database: +``` +# docker logs -f $CONTAINER_NAME + +# ----------------------------------------------------------------------------------------------- # + Oracle password for SYS, SYSTEM and PDBADMIN: HB#K_xhkwM_O10 +# ----------------------------------------------------------------------------------------------- # + +# ----------------------------------------------------------------------------------------------- # + runDBCA: Running DBCA for database ARM at 2023-07-03 20:16:05 +# ----------------------------------------------------------------------------------------------- # + +LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 03-JUL-2023 20:16:05 + +Copyright (c) 1991, 2023, Oracle. All rights reserved. + +Starting /u01/app/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait... + +TNSLSNR for Linux: Version 19.0.0.0.0 - Production +System parameter file is /u01/app/oracle/product/19c/dbhome_1/network/admin/listener.ora +Log messages written to /u01/app/oracle/diag/tnslsnr/96bb65f2a1b7/listener/alert/log.xml +Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) +Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521))) + +Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) +STATUS of the LISTENER +------------------------ +Alias LISTENER +Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production +Start Date 03-JUL-2023 20:16:06 +Uptime 0 days 0 hr. 0 min. 0 sec +Trace Level off +Security ON: Local OS Authentication +SNMP OFF +Listener Parameter File /u01/app/oracle/product/19c/dbhome_1/network/admin/listener.ora +Listener Log File /u01/app/oracle/diag/tnslsnr/96bb65f2a1b7/listener/alert/log.xml +Listening Endpoints Summary... + (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) + (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521))) +Services Summary... +Service "ARM" has 1 instance(s). + Instance "ARM", status UNKNOWN, has 1 handler(s) for this service... +The command completed successfully +# ----------------------------------------------------------------------------------------------- # + runDBCA: Creating container database ARM and 3 pluggable database(s) with name ARMPDB at 2023-07-03 20:16:06 +# ----------------------------------------------------------------------------------------------- # +Prepare for db operation +8% complete +Copying database files +31% complete +Creating and starting Oracle instance +32% complete +36% complete +40% complete +43% complete +46% complete +Completing Database Creation +51% complete +54% complete +Creating Pluggable Databases +58% complete +63% complete +68% complete +77% complete +Executing Post Configuration Actions +100% complete +Database creation complete. For details check the logfiles at: + /u01/app/oracle/cfgtoollogs/dbca/ARM. +Database Information: +Global Database Name:ARM +System Identifier(SID):ARM +Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ARM/ARM.log" for further details. + +Pluggable database altered. + +Pluggable database altered. + +# ----------------------------------------------------------------------------------------------- # + runDBCA: DBCA complete at 2023-07-03 20:26:37 +# ----------------------------------------------------------------------------------------------- # + +# ----------------------------------------------------------------------------------------------- # + Database ARM with unique name ARM is open and available. +# ----------------------------------------------------------------------------------------------- # + +# ----------------------------------------------------------------------------------------------- # + Tailing alert_ARM.log: +2023-07-03T20:26:36.493063+00:00 +ARMPDB3(5):CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ARM/ARMPDB3/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO +ARMPDB3(5):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ARM/ARMPDB3/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO +ARMPDB3(5):ALTER DATABASE DEFAULT TABLESPACE "USERS" +ARMPDB3(5):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS" +2023-07-03T20:26:37.882084+00:00 +alter pluggable database all open +Completed: alter pluggable database all open +alter pluggable database all save state +Completed: alter pluggable database all save state +``` + +Database creation took about 10 minutes; note that this output is for a CDB with three Pluggable Databases (PDB). + # Directory Structure Three subdirectories contain the majority of assets and configuration needed by images. @@ -98,7 +366,7 @@ Three subdirectories contain the majority of assets and configuration needed by Here you'll find version-specific files and configuration, including: - `dbca..rsp`: Every version of Oracle seems to introduce new options and features for Database Configuration Assistant (DBCA). Each version-specific file includes options with default and placeholder values. During database creation, the script replaces placeholders with values passed to the container at runtime via the `-e` option. - `inst..rsp`: The database install response files, like the DBCA response files, include default and placeholder values for customizing database installation for any version of Oracle. The script updates the placeholder values with those present in the Dockerfile or given to the build operation through a `--build-arg` option. -- `manifest.`: The manifest file includes information for all database and/or patch versions: +- `manifest`: The manifest file includes information for all database and/or patch versions: ``` # md5sum File name Type Version Other 1858bd0d281c60f4ddabd87b1c214a4f LINUX.X64_193000_db_home.zip database 19 SE,EE @@ -201,7 +469,6 @@ I build and run many Oracle databases in containers. There were things I didn't - For CDB databases, control the number/naming of PDBs - Data Guard, Sharding, RAC, GoldenGate, upgrades, etc. -# Legacy README: There is one script to handle all operations, for all editions and versions. This adds some complexity to the script (it has to accommodate peculiarities of every version and edition) but: - _For the most part_ these operations are identical across the board - One script in the root directory does everything and only one script needs maintenance @@ -297,9 +564,6 @@ I recommend handling this as follows: - Set ORACLE_PDB explicitly in `docker run` even when using PDB_LIST. PDB_LIST is evaluated first so setting ORACLE_PDB sets the environment and PDB_LIST creates multiple pluggable databases. The default PDB should be first in the list and match ORACLE_PDB. - If you need multiple PDBs, use PDB_LIST instead of PDB_COUNT, and set ORACLE_PDB to the "default" PDB. Otherwise, the ORACLE_PDB value in non-interactive shells is the prefix and not a full/valid PDB name. -# TODO -- Remove sudo option for building containers. It's only used during software installation and isn't required in final images. - # Glossary - APEX: Oracle Application Express, a low-code web development tool. - CDB: Container Database - Introduced in 12c, container databases introduce capacity and security enhancements. Each CDB consists of a root container plus one or more Pluggable Databases, or PDBs. @@ -313,3 +577,13 @@ I recommend handling this as follows: - runInstall: Performs Oracle database software installation. - SE, SE2: Oracle Standard Edition/Oracle Standard Edition 2 - A licensed version of Oracle with limited features. Not all features are available, licensed, or extensive in SE/SE2. For example, partitioning is not available in SE/SE2, and RAC is limited to specific node/core counts. - XE: Oracle Express Edition - A limited version of the Oracle database that is free to use. + +## TODO: +- Replace positional options with flags +- Expand customizations +- Add flexibility to pass `--build-arg`s to the script/image +- Add a "Create Dockerfile" option (don't run the build) +- Add Dockerfile naming capability +- Add a help menu and error dialogs +- Integrate secrets +- More... diff --git a/buildDBImage.sh b/buildDBImage.sh index 0e3d9b7..5901fa7 100755 --- a/buildDBImage.sh +++ b/buildDBImage.sh @@ -1,9 +1,9 @@ # Automate dynamic image builds # Set defaults for version, edition, tag and source: -ORACLE_VERSION=${1:-19.14} +ORACLE_VERSION=${1:-19.19} ORACLE_EDITION=${2:-EE} -TAG=${3:-7-slim} +TAG=${3:-8-slim} SOURCE=${4:-oraclelinux} DB_REPO=${5:-oraclesean/db} MOS_SECRET=${6:-$PWD/config/.netrc} @@ -150,26 +150,27 @@ addException() { } processManifest() { -# if [ -f ./config/manifest."$ORACLE_BASE_VERSION" ] if [ -f ./config/manifest ] then -# grep -ve "^#" ./config/manifest."$ORACLE_BASE_VERSION" | awk '{print $1,$2,$3,$4,$5}' | while IFS=" " read -r checksum filename filetype version extra - grep -ve "^#" ./config/manifest | awk '{print $1,$2,$3,$4,$5}' | while IFS=" " read -r checksum filename filetype version extra + # Get the correct architecture. + # Use `uname -m | sed -e 's/_/\./g' -e 's/-/\./g'` replaces underscores (_) and dashes (-) + # with the wildcard and matches both "x86_64" and "x86-64". + grep -i $(uname -m | sed -e 's/_/\./g' -e 's/-/\./g') ./config/manifest | grep -ve "^#" | awk '{print $1,$2,$3,$4,$5}' | while IFS=" " read -r checksum filename filetype version extra do if [ "$filetype" == "database" ] && [ "$version" == "$ORACLE_BASE_VERSION" ] && [ -f ./database/"$filename" ] && [ -z "$edition" ] then case $1 in ignore) addException $filename database ;; - label) sed -i -e "/^###SOFTWARE_LABEL###/i LABEL database.software.${version}=\"Edition=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n" $dockerfile ;; + label) sed -i '' -e "s/^###SOFTWARE_LABEL###/&\nLABEL database.software.${version}=\"Edition=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n/" $dockerfile ;; esac elif [ "$filetype" == "database" ] && [ "$version" == "$ORACLE_BASE_VERSION" ] && [ -f ./database/"$filename" ] && [[ $edition =~ $ORACLE_EDITION ]] then case $1 in ignore) addException $filename database ;; - label) sed -i -e "/^###SOFTWARE_LABEL###/i LABEL database.software.${version}=\"Edition=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n" $dockerfile ;; + label) sed -i '' -e "s/^###SOFTWARE_LABEL###/&\nLABEL database.software.${version}=\"Edition=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n/" $dockerfile ;; esac elif [ "$filetype" == "opatch" -o "$filetype" == "patch" ] && [ "$version" == "$ORACLE_BASE_VERSION" -o "$version" == "$ORACLE_VERSION" ] && [ -f ./database/patches/"$filename" ] then case $1 in ignore) addException $filename patch ;; - label) sed -i -e "/^###SOFTWARE_LABEL###/i LABEL database.patch.${extra}=\"Patch ID=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n" $dockerfile ;; + label) sed -i '' -e "s/^###SOFTWARE_LABEL###/&\nLABEL database.patch.${extra}=\"Patch ID=${extra}, Version=${version}, File=${filename}, md5sum=${checksum}\"\n/" $dockerfile ;; esac fi done @@ -213,7 +214,7 @@ processDockerfile() { processManifest label # Remove unset lines - sed -i -e '/###$/d' $1 + sed -i '' -e '/###$/d' $1 } getVersion @@ -221,8 +222,8 @@ getEdition setBuildKit # Set build options -#options="--force-rm=true --no-cache=true" # --progress=plain -options="--force-rm=true --no-cache=true --progress=plain" +options="--force-rm=true --no-cache=true" +#options="--force-rm=true --no-cache=true --progress=plain" # Set build arguments arguments="" diff --git a/config/manifest b/config/manifest index ae2df1d..9ffcd2c 100644 --- a/config/manifest +++ b/config/manifest @@ -33,6 +33,7 @@ bc427a4d8c31929da523cae7fd6e659c p34006614_121020_Linux-x86-64.zip patch 12.1 # 19c 1858bd0d281c60f4ddabd87b1c214a4f LINUX.X64_193000_db_home.zip database 19 SE,EE #1f86171d22137e31cc2086bf7af36e91 oracle-database-ee-19c-1.0-1.x86_64.rpm database 19 SE,EE +6c39043ad12e11bcdc505184631e11a2 LINUX.ARM64_1919000_db_home.zip database 19 SE,EE 5a8aedbd343732b5f69967b1379b21b9 p6880880_190000_Linux-x86-64.zip opatch 19 6880880 2a06e8c7409b21de9be6d404d39febda p30557433_190000_Linux-x86-64.zip patch 19.6 30557433 0e0831a46cc3f8312a761212505ba5d1 p30565805_196000DBRU_Linux-x86-64.zip patch 19.6 30565805 diff --git a/config/manifest.11.2.0.2 b/config/manifest.11.2.0.2 deleted file mode 100644 index ccfb42a..0000000 --- a/config/manifest.11.2.0.2 +++ /dev/null @@ -1 +0,0 @@ -dd7881a55569d890241f11cd0eeb7d48 oracle-xe-11.2.0-1.0.x86_64.rpm.zip database 11.2.0.2 XE diff --git a/config/manifest.11.2.0.4 b/config/manifest.11.2.0.4 deleted file mode 100644 index 6a5b44f..0000000 --- a/config/manifest.11.2.0.4 +++ /dev/null @@ -1,4 +0,0 @@ -1616f61789891a56eafd40de79f58f28 p13390677_112040_Linux-x86-64_1of7.zip database 11.2.0.4 SE,EE -67ba1e68a4f581b305885114768443d3 p13390677_112040_Linux-x86-64_2of7.zip database 11.2.0.4 SE,EE -171045894bf20a80ed45fea27207b839 p6880880_112000_Linux-x86-64.zip opatch 11.2.0.4 6880880 -eb970c5843f3a69ad6476f7fba1f9a7f p31537677_112040_Linux-x86-64.zip patch 11.2.0.4 31537677 diff --git a/config/manifest.12.1 b/config/manifest.12.1 deleted file mode 100644 index 0ea96ec..0000000 --- a/config/manifest.12.1 +++ /dev/null @@ -1,6 +0,0 @@ -080435a40bd4c8dff6399b231a808e9a linuxamd64_12102_database_1of2.zip database 12.1 EE -30f20ef9437442b8282ce3984546c982 linuxamd64_12102_database_2of2.zip database 12.1 EE -dadbf2cfbc9b53f92d0b07f6677af966 linuxamd64_12102_database_se2_1of2.zip database 12.1 SE -2bda8cd4883bbd3f892dc152e568fc9e linuxamd64_12102_database_se2_2of2.zip database 12.1 SE -9a66f9ff5ccedf1a253820d2984a540b p6880880_121010_Linux-x86-64.zip opatch 12.1 6880880 -19cdb4322035099328e2a90737918767 p32768233_121020_Linux-x86-64.zip patch 12.1 32768233 diff --git a/config/manifest.12.2 b/config/manifest.12.2 deleted file mode 100644 index 8e22974..0000000 --- a/config/manifest.12.2 +++ /dev/null @@ -1,2 +0,0 @@ -1841f2ce7709cf909db4c064d80aae79 linuxx64_12201_database.zip database 12.2 SE,EE -9a66f9ff5ccedf1a253820d2984a540b p6880880_122010_Linux-x86-64.zip opatch 12.2 6880880 diff --git a/config/manifest.18.3 b/config/manifest.18.3 deleted file mode 100644 index 73f941e..0000000 --- a/config/manifest.18.3 +++ /dev/null @@ -1,3 +0,0 @@ -99a7c4a088a8a502c261e741a8339ae8 LINUX.X64_180000_db_home.zip database 18.3 SE,EE -#2ef79c73660191b1b6d68a5380892b60 oracle-database-ee-18c-1.0-1.x86_64.rpm database 18.3 SE,EE -9a66f9ff5ccedf1a253820d2984a540b p6880880_180000_Linux-x86-64.zip opatch 18.3 6880880 diff --git a/config/manifest.19 b/config/manifest.19 deleted file mode 100644 index 18bffb0..0000000 --- a/config/manifest.19 +++ /dev/null @@ -1,40 +0,0 @@ -1858bd0d281c60f4ddabd87b1c214a4f LINUX.X64_193000_db_home.zip database 19 SE,EE -#1f86171d22137e31cc2086bf7af36e91 oracle-database-ee-19c-1.0-1.x86_64.rpm database 19 SE,EE -#f65d3ce87cec3a09c3f2bc480c58ea4b p6880880_190000_Linux-x86-64.zip opatch 19 6880880 -9a66f9ff5ccedf1a253820d2984a540b p6880880_190000_Linux-x86-64.zip opatch 19 6880880 -2a06e8c7409b21de9be6d404d39febda p30557433_190000_Linux-x86-64.zip patch 19.6 30557433 -0e0831a46cc3f8312a761212505ba5d1 p30565805_196000DBRU_Linux-x86-64.zip patch 19.6 30565805 -f949a2bc8c5b1e01fd24ebee8c7feebe p30869156_190000_Linux-x86-64.zip patch 19.7 30869156 -fef4c7b7f7c313847de69667258eb3cd p30565805_197000DBRU_Linux-x86-64.zip patch 19.7 30565805 -2003566250018b0b5c53e6f98d5d6d80 p31281355_190000_Linux-x86-64.zip patch 19.8 31281355 -bd8060c43c60bd4337bb2a89471b1fba p30565805_198000DBRU_Linux-x86-64.zip patch 19.8 30565805 -65c2d78b70ebba4ee66d9454af9bbbb8 p31771877_190000_Linux-x86-64.zip patch 19.9 31771877 -add92eb9abca0f67593ae08e128bc3d4 p32218454_190000_Linux-x86-64.zip patch 19.10 32218454 -d2b136a8eb13e2446b62752b4d55db2f p32545013_190000_Linux-x86-64.zip patch 19.11 32545013 -f61d7cee9f16b70069cabe9617abc3d1 p33457235_1911000DBRU_Linux-x86-64.zip patch 19.11 33457235 -726b68f86c2060a63808836a6831cb3d p33153989_190000_Linux-x86-64.zip patch 19.11.2 33153989 -317e43c72d6c60dc4105b0be19acc84e p33457235_1911200DBRUR_Linux-x86-64.zip patch 19.11.2 33457235 -a3cc49832e94a6abd0490ab22732b39f p32904851_190000_Linux-x86-64.zip patch 19.12 32904851 -1a86167e157ede01b3f266ce6b0994df p33457235_1912000DBRU_Linux-x86-64.zip patch 19.12 33457235 -73133e0259a6fc39326001bc43976881 p33210889_190000_Linux-x86-64.zip patch 19.12.1 33210889 -9d868fb8f273ef10338ee5ee15a7c336 p33457235_1912100DBRUR_Linux-x86-64.zip patch 19.12.1 33457235 -de60e587df931a96deac13c5119e4264 p33494256_190000_Linux-x86-64.zip patch 19.12.2 33494256 -5b2f369f6c1f0397c656a5554bc864e6 p33192793_190000_Linux-x86-64.zip patch 19.13 33192793 -680af566ae1ed41a9916dfb0a122565c p33457235_1913000DBRU_Linux-x86-64.zip patch 19.13 33457235 -30eb702fe0c1bee393bb80ff8f10afe9 p33516456_190000_Linux-x86-64.zip patch 19.13.1 33516456 -de8c41d94676479b9aa35d66ca11c96a p33457235_1913100DBRUR_Linux-x86-64.zip patch 19.13.1 33457235 -b0f065b8cb6e6b45ccb3558042a7edc5 p33783771_190000_Linux-x86-64.zip patch 19.13.2 33783771 -7bcfdcd0f3086531e232fd0237b7438f p33515361_190000_Linux-x86-64.zip patch 19.14 33515361 -9af8fefc1cd25cfbef611922091a81bc p33806138_190000_Linux-x86-64.zip patch 19.14.1 33806138 -665b940107da7f51f611fcbbf27f0df3 p34110559_190000_Linux-x86-64.zip patch 19.14.2 34110559 -4b1ce8b287073994ddf72282a7d1e2e9 p33806152_190000_Linux-x86-64.zip patch 19.15 33806152 -ec7cc001b66271c6475b7dca7f6d0163 p33195096_1915000DBRU_Linux-x86-64.zip patch 19.15 33195096 -5f7d0f8d72d425167a7f43dde54377de p34119532_190000_Linux-x86-64.zip patch 19.15.1 34119532 -ebc61b15e15aa0d84131b61ae776ba41 p34429835_190000_Linux-x86-64.zip patch 19.15.2 34429835 -12d5aadb52df3269ad0d995657660bb0 p34133642_190000_Linux-x86-64.zip patch 19.16 34133642 -b82e96e953f3da29987b8914c64b3c4e p33195096_1916000DBRU_Linux-x86-64.zip patch 19.16 33195096 -42a6c3484a1bd7f6aa3ca3434d762fb7 p34444812_190000_Linux-x86-64.zip patch 19.16.1 34444812 -5866e2e148a1cecc267b3b43e68b62c3 p34419443_190000_Linux-x86-64.zip patch 19.17 34419443 -# DATABASE PERL UPDATE IN 19C TO V5.32-1 (CVE-2022-23990 - LIBEXPAT UPDATE) -# General for any version, must be applied after RU -fd96f9db3c1873dfee00efe8088186a4 p33912872_190000_Linux-x86-64.zip patch 19 33912872 diff --git a/config/manifest.21 b/config/manifest.21 deleted file mode 100644 index da4590d..0000000 --- a/config/manifest.21 +++ /dev/null @@ -1,11 +0,0 @@ -8ac915a800800ddf16a382506d3953db LINUX.X64_213000_db_home.zip database 21 SE,EE -#be49680760d60089815cc0b4ae2e1805 oracle-database-ee-21c-1.0-1.ol7.x86_64.rpm database 21 SE,EE OEL7 -#db3d15b21e17a455a1c28861d5ce0a4f oracle-database-ee-21c-1.0-1.ol8.x86_64.rpm database 21 SE,EE OEL8 -9a66f9ff5ccedf1a253820d2984a540b p6880880_210000_Linux-x86-64.zip opatch 21 6880880 -e52c22cdc2f6cb18f571569c9412b693 p33516412_210000_Linux-x86-64.zip patch 21.5 33516412 -a4f3339727becb27a4033b84615ac214 p33843745_210000_Linux-x86-64.zip patch 21.6 33843745 -70cb6d33ea30aff9302a5bf0ac1e5348 p34160444_210000_Linux-x86-64.zip patch 21.7 34160444 -f9fd56bcb1f4faab2ebde54f193b7a63 p34527084_210000_Linux-x86-64.zip patch 21.8 34527084 -# DATABASE PERL UPDATE FOR 21C TO V5.32-1 (CVE-2022-23990 - LIBEXPAT UPDATE) -# General for any version, must be applied after RU -1e3fdfd8dfea43b9d9f34d1202348b89 p33928944_210000_Linux-x86-64.zip patch 21 33928944 diff --git a/functions.sh b/functions.sh index 5fcc58b..88111b1 100755 --- a/functions.sh +++ b/functions.sh @@ -54,7 +54,7 @@ replaceVars() { then local __val="$(eval echo "\$$(echo "$__var")")" else local __val="$3" fi - sed -i -e "s|###${__var}###|"${__val}"|g" "$__file" + sed -i '' -e "s|###${__var}###|"${__val}"|g" "$__file" } checkSum() { diff --git a/manageOracle.sh b/manageOracle.sh index a038d71..86792a6 100755 --- a/manageOracle.sh +++ b/manageOracle.sh @@ -107,7 +107,7 @@ checkDirectory() { } getPreinstall() { - # Set the default RPM by version: + # Set the default RPM by version: case $1 in 11*) pre="oracle-rdbms-server-11gR2-preinstall unzip" ;; 12.1*) pre="oracle-rdbms-server-12cR1-preinstall tar" ;; @@ -115,12 +115,20 @@ getPreinstall() { 18*) pre="oracle-database-preinstall-18c" ;; 19*) pre="oracle-database-preinstall-19c" ;; 21*) pre="oracle-database-preinstall-21c" ;; - 23*) pre="oracle-database-preinstall-21c" ;; -# 23*) pre="oracle-database-preinstall-23c-1.0-1.el8.x86_64.rpm" ;; + 23*) curl -L -o oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/developer/x86_64/getPackage/oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm + dnf -y localinstall oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm ;; *) pre="oracle-database-preinstall-19c" ;; esac - export RPM_LIST="openssl $pre $RPM_LIST" + # Set the EPEL release: + release=$(cat /etc/os-release | grep -e "^PLATFORM_ID" | sed -e 's/^.*://g' -e 's/"//g') + + export RPM_LIST="openssl oracle-epel-release-$release $pre $RPM_LIST" +} + +getYum() { + # Get the correct package installer: yum, dnf, or microdnf: + YUM=$(command -v yum || command -v dnf || command -v microdnf) } configENV() { @@ -134,18 +142,19 @@ configENV() { fi getPreinstall "$ORACLE_VERSION" + getYum - yum -y update - yum -y install $RPM_LIST + $YUM -y update + $YUM -y install $RPM_LIST sync if [ -n "$RPM_SUPPLEMENT" ] - then yum -y install $RPM_SUPPLEMENT + then $YUM -y install $RPM_SUPPLEMENT fi # Add option to add systemd support to the image (for AHF/TFA) if [ -n "$SYSTEMD" ] - then yum -y install systemd + then $YUM -y install systemd cd /lib/systemd/system/sysinit.target.wants for i in * do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i @@ -158,7 +167,7 @@ configENV() { systemctl set-default multi-user.target fi - yum clean all + $YUM clean all mkdir -p {"$INSTALL_DIR","$SCRIPTS_DIR"} || error "Failure creating directories." } @@ -198,7 +207,8 @@ setBase() { mkPass() { # Generate a random 16-character password; first character always alphanum, including one guaranteed special character: - echo "$(tr -dc '[:alnum:]' /dev/null 2>&1 || yum install -y curl + command -v curl >/dev/null 2>&1 || getYum; $YUM install -y curl # Log in to MOS if there isn't already a cookie file. if [ ! -f "$__cookie" ] @@ -283,7 +293,9 @@ installPatch() { if [ -f "$manifest" ] then manifest="$(find $INSTALL_DIR -maxdepth 1 -name "manifest*" 2>/dev/null)" # Allow manifest to hold version-specific (version = xx.yy) and generic patches (version = xx) and apply them in order. - grep -e "^[[:alnum:]].*\b.*\.zip[[:blank:]]*\b${1}\b[[:blank:]]*\(${__major_version}[[:blank:]]\|${__minor_version}[[:blank:]]\)" $manifest | awk '{print $5,$2,$1}' | while read patchid install_file checksum + grep -e "^[[:alnum:]].*\b.*\.zip[[:blank:]]*\b${1}\b[[:blank:]]*\(${__major_version}[[:blank:]]\|${__minor_version}[[:blank:]]\)" $manifest \ + | grep -i $(uname -m | sed -e 's/_/\./g' -e 's/-/\./g' -e 's/aarch64/arm64/g') \ + | awk '{print $5,$2,$1}' | while read patchid install_file checksum do # If there's a credential file and either: # ...the patch file isn't present @@ -371,7 +383,7 @@ installOracle() { fi fi - yum -y localinstall $ORACLE_RPM + getYum; $YUM -y localinstall $ORACLE_RPM # Determine the name of the init file used for RPM installation # if [ "$__version" == "11.2.0.2" ] && [ "$ORACLE_EDITION" != "XE" ] @@ -426,7 +438,9 @@ installOracle() { # Some versions have multiple files that must be unzipped to the correct location prior to installation. # Loop over the manifest, retrieve the file and checksum values, unzip the installation files. set +e - grep -e "^[[:alnum:]].*\b.*\.zip[[:blank:]]*\bdatabase\b.*${ORACLE_EDITION::2}" $manifest | awk '{print $1,$2}' | while read checksum install_file + grep -e "^[[:alnum:]].*\b.*\.zip[[:blank:]]*\bdatabase\b.*${ORACLE_EDITION::2}" $manifest \ + | grep -i $(uname -m | sed -e 's/_/\./g' -e 's/-/\./g' -e 's/aarch64/arm64/g') \ + | awk '{print $1,$2}' | while read checksum install_file do checkSum "$INSTALL_DIR/$install_file" "$checksum" case $ORACLE_VERSION in 18.*|19.*|2*) sudo su - oracle -c "unzip -oq -d $ORACLE_HOME $INSTALL_DIR/$install_file" ;; @@ -587,65 +601,6 @@ stopDB() { stopListener } -checkMode() { - target_status=$(echo "$1" | sed "s/ /./g") - check= - while [[ ! $check =~ $target_status ]] - do check=$(echo "select open_mode from v\$database;" | "$ORACLE_HOME"/bin/sqlplus -S / as sysdba) 2>/dev/null - if ! [[ $check =~ $target_status ]] - then echo "Database $DB_UNQNAME is not online; sleeping." - sleep 180 - else echo "Database $DB_UNQNAME is online." - fi - done -} - -setupDG() { - dbrole=$1 - local __version=$(echo "$ORACLE_VERSION" | cut -d. -f1) - setBase - if [ "$dbrole" = "PRIMARY" ] - then "$ORACLE_HOME"/bin/sqlplus / as sysdba @"$SETUP_DIR"/"$SETUP_PRIMARY".sql - for duplicate in $(find "$SETUP_DIR"/"$RMAN_DUPLICATE".*.rman) - do cs="$(head -1 "$duplicate" | awk '{print $NF}')" - "$ORACLE_HOME"/bin/rman target sys/"$ORACLE_PWD"@"$DB_UNQNAME" cmdfile "$duplicate" log /tmp/duplicate.out - # Open standby database read only - if [ "$(grep -c farsync "$duplicate")" -eq 0 ] - then echo "alter database open read only;" | "$ORACLE_HOME"/bin/sqlplus "$cs" as sysdba - fi - done - cat "$SETUP_DIR"/"$BROKER_SCRIPT" | "$ORACLE_HOME"/bin/dgmgrl / - sleep 60 - cat "$SETUP_DIR"/"$BROKER_CHECKS" | "$ORACLE_HOME"/bin/dgmgrl / - else mkdir -p "$ORADATA"/"$ORACLE_SID" - mkdir -p "$ORACLE_BASE"/fast_recovery_area/"$ORACLE_SID" - createAudit "$DB_UNQNAME" - mkdir -p "$ORACLE_BASE"/diag/rdbms/"${DB_UNQNAME,,}"/"$ORACLE_SID"/trace - touch "$ORACLE_BASE"/diag/rdbms/"${DB_UNQNAME,,}"/"$ORACLE_SID"/trace/alert_"$ORACLE_SID".log - printf "%s:%s:N\n" "$ORACLE_SID" "$ORACLE_HOME" > /etc/oratab - # Create a pfile for startup of the DG replica - copyTemplate "$INSTALL_DIR"/init.ora.tmpl "$ORACLE_BASE_CONFIG"/init"$ORACLE_SID".ora replace - # Create a password file - case "$__version" in - 11) __option="force=y" ;; - *) __option="force=yes format=12" ;; - esac - "$ORACLE_HOME"/bin/orapwd file="$ORACLE_BASE_CONFIG"/orapw"$ORACLE_SID" "$__option" <<< $(echo "$ORACLE_PWD") - echo "startup nomount pfile='${ORACLE_BASE_CONFIG}/init${ORACLE_SID}.ora';" | "$ORACLE_HOME"/bin/sqlplus / as sysdba - # Start listener - startListener - # Wait for the database to come online - if [ "$OPEN_MODE" = "MOUNT" ] - then checkMode "MOUNT" - else checkMode "READ ONLY" - # Open managed for managed apply - if [ "$OPEN_MODE" = "APPLY" ] - then runsql "alter database recover managed standby database disconnect from session;" - fi - fi - fi -} - runDBCA() { local __version=$(echo "$ORACLE_VERSION" | cut -d. -f1) # Default init parameters @@ -1041,13 +996,13 @@ fi # Check whether container has enough memory if [ -f /sys/fs/cgroup/cgroup.controllers ] -then __mem=$(cat /sys/fs/cgroup/memory.high) +then __mem=$(cat /sys/fs/cgroup/memory.max) else __mem=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) fi if [ -z "$__mem" ] then error "There was a problem getting the cgroups memory limit on the system" -elif [ "${#__mem}" -lt 11 ] && [ "$__mem" -lt 2147483648 ] +elif [ "${__mem}" != "max" ] && [ "${#__mem}" -lt 11 ] && [ "$__mem" -lt 2147483648 ] then error "The database container requires at least 2GB of memory; only $__mem is available" fi @@ -1133,7 +1088,6 @@ else # Create the TNS configuration # Create a database password if none exists if [ -z "$ORACLE_PWD" ] then export ORACLE_PWD="$(mkPass)" - # ORACLE_PWD=$(openssl rand -base64 8)1; export ORACLE_PWD logger BA "Oracle password for SYS, SYSTEM and PDBADMIN: $ORACLE_PWD" fi @@ -1149,15 +1103,8 @@ else # Create the TNS configuration then copyTemplate "$INSTALL_DIR"/login.sql.tmpl "$ORACLE_PATH"/login.sql replace fi - # Run DBCA if this is a standalone database or primary in a Data Guard configuration - if [ -z "$ROLE" ] - then runDBCA - elif [ "$ROLE" = "PRIMARY" ] - then runDBCA - setupDG "$ROLE" - else setupDG "$ROLE" - fi - + # Run DBCA + runDBCA moveFiles runUserScripts "$ORACLE_BASE"/scripts/setup fi diff --git a/templates/oraclelinux.dockerfile b/templates/oraclelinux.dockerfile index f4c261e..9176b03 100644 --- a/templates/oraclelinux.dockerfile +++ b/templates/oraclelinux.dockerfile @@ -9,7 +9,7 @@ ARG ORACLE_PATH=/home/oracle ARG ORACLE_VERSION=###ORACLE_BASE_VERSION### # Build defaults -ARG RPM_LIST="oracle-epel-release-el7 file-5.11 git less strace sudo tree vi which bash-completion" +ARG RPM_LIST="file git hostname less strace sudo tree vi which bash-completion" ARG RPM_SUPPLEMENT="rlwrap" ARG MIN_SPACE_GB=###MIN_SPACE_GB_ARG### ARG BUILD_DATE=