2024年12月22日日曜日

Oracle Graph Serverのコンテナ・イメージを作成する

Oracle Graph Serverのコンテナ・イメージを作成してみました。

@ryotayamanakaさんのQiitaの記事「Graph Serverコンテナ作成(23.4)」の記事に多くを依っています。公式のドキュメントは以下です。

Oracle Graph ServerはARM版のバージョン24.4のRPMを使用します。Dockerfileは、Oracleが配布しているOracleJavaのOracle Linux 8のJava21向けのものを元に、Graph Serverもインストールするように記述を追加します。


イメージの作成には、macOSのpodmanを使用します。

OSのパッケージとしてnumactl, libgcc, libgfortranを追加していますが、これはEnterprise Schedulerの要件を満たすためだと思います。Enterprise SchedulerはARMでは動かないようで(OS要件はLinux (x86_64)となっている)、ARMでは不要かもしれません。

# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
#
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This is the Dockerfile for Oracle JDK 21 on Oracle Linux 8
#
# REQUIRED FILES TO BUILD THIS IMAGE
# ----------------------------------
# This dockerfile will download a copy of JDK 21 from
# https://download.oracle.com/java/21/latest/jdk-21_linux-<ARCH>_bin.tar.gz
#
# It will use either x64 or aarch64 depending on the target platform
#
# HOW TO BUILD THIS IMAGE
# -----------------------
# Run:
# $ docker build -t oracle/jdk:21 .
#
# This command is already scripted in build.sh so you can alternatively run
# $ bash build.sh
#
# The builder image will be used to uncompress the tar.gz file with the Java Runtime.
FROM oraclelinux:8 as builder
#LABEL maintainer="Aurelio Garcia-Ribeyro <aurelio.garciaribeyro@oracle.com>"
# Since the files are compressed as tar.gz first dnf install tar. gzip is already in oraclelinux:8
RUN set -eux; \
dnf install -y tar;
# Default to UTF-8 file.encoding
ENV LANG en_US.UTF-8
# Environment variables for the builder image.
# Required to validate that you are using the correct file
ENV JAVA_URL=https://download.oracle.com/java/21/latest \
JAVA_HOME=/usr/java/jdk-21
##
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -eux; \
ARCH="$(uname -m)" && \
# Java uses just x64 in the name of the tarball
if [ "$ARCH" = "x86_64" ]; \
then ARCH="x64"; \
fi && \
JAVA_PKG="$JAVA_URL"/jdk-21_linux-"${ARCH}"_bin.tar.gz ; \
JAVA_SHA256=$(curl "$JAVA_PKG".sha256) ; \
curl --output /tmp/jdk.tgz "$JAVA_PKG" && \
echo "$JAVA_SHA256" */tmp/jdk.tgz | sha256sum -c; \
mkdir -p "$JAVA_HOME"; \
tar --extract --file /tmp/jdk.tgz --directory "$JAVA_HOME" --strip-components 1
## Get a fresh version of Oracle Linux 8 for the final image
FROM oraclelinux:8
# Default to UTF-8 file.encoding
ENV LANG en_US.UTF-8
ENV JAVA_HOME=/usr/java/jdk-21
ENV PATH $JAVA_HOME/bin:$PATH
# If you need the Java Version you can read it from the release file with
# JAVA_VERSION=$(sed -n '/^JAVA_VERSION="/{s///;s/"//;p;}' "$JAVA_HOME"/release);
# Copy the uncompressed Java Runtime from the builder image
COPY --from=builder $JAVA_HOME $JAVA_HOME
# For Oracle Graph
COPY ./oracle-graph-*.rpm /tmp/
RUN set -eux; \
# Ensure we get the latest OL 8 updates available at build time
dnf -y update; \
# JDK assumes freetype is available
dnf install -y \
# freetype fontconfig \
freetype fontconfig unzip numactl gcc libgfortran python3.8 \
; \
# For Oracle Graph
dnf install -y \
/tmp/oracle-graph-*.rpm ; \
rm -f /tmp/oracle-graph-*.rpm ; \
rm -f /usr/bin/python3 /usr/bin/pip3 ; \
ln /usr/bin/python3.8 /usr/bin/python3 ; \
ln /usr/bin/pip3.8 /usr/bin/pip3 ; \
pip3 install oracle-graph-client ; \
# End
rm -rf /var/cache/dnf; \
ln -sfT "$JAVA_HOME" /usr/java/default; \
ln -sfT "$JAVA_HOME" /usr/java/latest; \
for bin in "$JAVA_HOME/bin/"*; do \
base="$(basename "$bin")"; \
[ ! -e "/usr/bin/$base" ]; \
alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \
done;
# For Oracle Graph
COPY ./server.conf /etc/oracle/graph/server.conf
COPY ./pgx.conf /etc/oracle/graph/pgx.conf
EXPOSE 7007
WORKDIR /opt/oracle/graph/bin
CMD ["sh", "/opt/oracle/graph/pgx/bin/start-server"]
view raw Dockerfile hosted with ❤ by GitHub

コンテナ・イメージに含める設定ファイルとしてserver.confを作成します。enable_tlsfalseにして、HTTPで接続するようにします。

{
"port": 7007,
"enable_tls": false,
"enable_client_authentication": false,
"server_keystore": "/etc/oracle/graph/server_keystore.jks",
"server_keystore_alias": "pgx",
"server_keystore_type": "JKS",
"server_keystore_provider": "SUN",
"ca_certs": [],
"working_dir": "/opt/oracle/graph/pgx/tmp_data"
}
view raw server.conf hosted with ❤ by GitHub

もう一つの設定ファイルとしてpgx.confを作成します。schedulerとしてbasic_schedulerを選択し(x86_64であればenterprise_schedulerが動くので不要です)、pgx_realmoptionsに含まれるjdbc_urlbase_urlを変更しています。

{
"scheduler": "basic_scheduler",
"allow_idle_timeout_overwrite": true,
"allow_task_timeout_overwrite": true,
"authorization": [{
"pgx_role": "GRAPH_ADMINISTRATOR",
"pgx_permissions": []
}, {
"pgx_role": "GRAPH_DEVELOPER",
"pgx_permissions": [
]
}],
"enable_gm_compiler": true,
"enterprise_scheduler_config": {
"analysis_task_config": {
"priority": "MEDIUM",
"weight": "<no-of-CPUs>",
"max_threads": "<no-of-CPUs>"
},
"fast_analysis_task_config": {
"priority": "HIGH",
"weight": 1,
"max_threads": "<no-of-CPUs>"
},
"num_io_threads_per_task": "<no-of-CPUs>"
},
"graph_algorithm_language": "JAVA",
"in_place_update_consistency_model": "ALLOW_INCONSISTENCIES",
"java_home_dir": "<system-java-home-dir>",
"max_active_sessions": 1024,
"max_queue_size_per_session": -1,
"max_snapshot_count": 0,
"memory_cleanup_interval": 5,
"preload_graphs": [],
"pgx_realm": {
"implementation": "oracle.pg.identity.DatabaseRealm",
"options": {
"jdbc_url": "jdbc:oracle:thin:@host.containers.internal:1521/freepdb1",
"token_expiration_seconds": 3600,
"refresh_time_before_token_expiry_seconds": 1800,
"connect_timeout_milliseconds": 10000,
"connection_pool_cleanup_interval_secs": 10,
"max_pool_size": 64,
"max_threads_size": 16,
"max_num_users": 512,
"max_num_token_refresh": 24,
"max_num_results_per_user": 10,
"visualization_results_duration_seconds": 1800,
"table_maximum_rows": 1000,
"krb5_conf_file": "<REPLACE-WITH-KRB5-CONF-FILE-PATH-TO-ENABLE-KERBEROS-AUTHENTICATION>",
"krb5_ticket_cache_dir": "/dev/shm/graph_cache",
"krb5_max_cache_size": 1024,
"base_url": "http://localhost:7007",
"get_latest_snapshot_for_visualization": true
}
},
"release_memory_threshold": 0.0,
"session_idle_timeout_secs": 14400,
"session_task_timeout_secs": 0,
"strict_mode": true,
"tmp_dir": "/tmp"
}
view raw pgx.conf hosted with ❤ by GitHub

適当なディクレトリを作成し、以下の5つのファイルを配置します。JavaについてはAMD64かARMでファイルが異なります。また、Javaは21限定です。Oracle Graph Serverは新しいバージョンでも、Dockerfileは変更せずにイメージが作れるはずです。
  • 上記のDockerfile
  • Oracle Graph Serverのrpmファイル - oracle-graph-24.4.0.aarch64.rpm
  • Oracle Javaのtar.gzファイル - jdk-21_linux-aarch64_bin.tar.gz
  • 上記のserver.conf
  • 上記のpgx.conf
以下のコマンドを実行して、oracle/graph:24.4のコンテナ・イメージを作成します。

podman build --file Dockerfile --tag oracle/graph:24.4 .

% podman build --file Dockerfile --tag oracle/graph:24.4

[1/2] STEP 1/6: FROM oraclelinux:8 AS builder

[1/2] STEP 2/6: RUN set -eux;     dnf install -y tar;

--> Using cache 5cea888c79479824d285a73c852893348e9919feaa7aa317afd4e9f705f5816e

--> 5cea888c7947

[1/2] STEP 3/6: ENV LANG en_US.UTF-8

--> Using cache a585a03081cdb5f3e15bc7bd9f62de91944cc7b0aed6b2af89d5178333c33894

--> a585a03081cd

[1/2] STEP 4/6: ENV JAVA_URL=https://download.oracle.com/java/21/latest     JAVA_HOME=/usr/java/jdk-21

--> Using cache b87a297f14d3221491715591d8e6d38a2f5dbd884697e005c528ca302a9a7f50

--> b87a297f14d3

[1/2] STEP 5/6: SHELL ["/bin/bash", "-o", "pipefail", "-c"]

--> Using cache b8af6dccd544cbf370c3b4167fcab08fc6341c4bece94c60a4608cb1905c5dd9

--> b8af6dccd544

[1/2] STEP 6/6: RUN set -eux;     ARCH="$(uname -m)" &&     if [ "$ARCH" = "x86_64" ];         then ARCH="x64";     fi &&     JAVA_PKG="$JAVA_URL"/jdk-21_linux-"${ARCH}"_bin.tar.gz ;     JAVA_SHA256=$(curl "$JAVA_PKG".sha256) ;     curl --output /tmp/jdk.tgz "$JAVA_PKG" &&     echo "$JAVA_SHA256" */tmp/jdk.tgz | sha256sum -c;     mkdir -p "$JAVA_HOME";     tar --extract --file /tmp/jdk.tgz --directory "$JAVA_HOME" --strip-components 1

--> Using cache 3763a78c62bff34d2d3788e0cb0cc85e5054bc6e8b35b5d40689c3fe0076677a

--> 3763a78c62bf

[2/2] STEP 1/12: FROM oraclelinux:8

[2/2] STEP 2/12: ENV LANG en_US.UTF-8

--> Using cache 8964bc11495eb33b855f9d79cee5244aadc444312f6eefa71dd19a2b6d5f4fbc

--> 8964bc11495e

[2/2] STEP 3/12: ENV JAVA_HOME=/usr/java/jdk-21

--> Using cache ec94d6313a982b2a88d2e4e48d4cedd8bb14a811fb14c40e0ac10f4524e1791c

--> ec94d6313a98

[2/2] STEP 4/12: ENV PATH $JAVA_HOME/bin:$PATH

--> Using cache 99c2bf65de1858cef3a87631ccf719c0c5cf52d0be9703b1ab2774af607364bf

--> 99c2bf65de18

[2/2] STEP 5/12: COPY --from=builder $JAVA_HOME $JAVA_HOME

--> Using cache 597e7f14bdedcee4454d83f8d155697b414320f81045565be040b837a74143b6

--> 597e7f14bded

[2/2] STEP 6/12: COPY ./oracle-graph-*.rpm /tmp/

--> Using cache 0b8932f89eaae03516ae420ed1cf167f1096a7be384e5de65340df414fbfc44b

--> 0b8932f89eaa

[2/2] STEP 7/12: RUN set -eux;     dnf -y update;     dnf install -y         freetype fontconfig unzip numactl gcc libgfortran python3.8     ;     dnf install -y         /tmp/oracle-graph-*.rpm ;     rm -f /tmp/oracle-graph-*.rpm ;     rm -f /usr/bin/python3 /usr/bin/pip3 ;     ln /usr/bin/python3.8 /usr/bin/python3 ;     ln /usr/bin/pip3.8 /usr/bin/pip3 ;     pip3 install oracle-graph-client ;     rm -rf /var/cache/dnf;     ln -sfT "$JAVA_HOME" /usr/java/default;     ln -sfT "$JAVA_HOME" /usr/java/latest;     for bin in "$JAVA_HOME/bin/"*; do         base="$(basename "$bin")";         [ ! -e "/usr/bin/$base" ];         alternatives --install "/usr/bin/$base" "$base" "$bin" 20000;     done;

--> Using cache d953adfd9cf4887de943053c54b79a23c9f19bf9ffb58780b1cd2e1e23064081

--> d953adfd9cf4

[2/2] STEP 8/12: COPY ./server.conf /etc/oracle/graph/server.conf

--> Using cache 76edffe6cb7f4c0b7885ae67bc392c21d75d622ea0f7d788f40b48c20330df13

--> 76edffe6cb7f

[2/2] STEP 9/12: COPY ./pgx.conf /etc/oracle/graph/pgx.conf

--> Using cache deb693223ad9e447a34e53d8bd7ef65275fdc08042ad53a627c9d638318288d7

--> deb693223ad9

[2/2] STEP 10/12: EXPOSE 7007

--> Using cache 6e784a42e60b49316b15d01be7942b38ba1d34af7dc6d885362b8bd1efe98c5c

--> 6e784a42e60b

[2/2] STEP 11/12: WORKDIR /opt/oracle/graph/bin

--> Using cache 5c1d618b728003e7b98f94a050db8b6b340a30e7e7d78ed450779f22eee7a288

--> 5c1d618b7280

[2/2] STEP 12/12: CMD ["sh", "/opt/oracle/graph/pgx/bin/start-server"]

--> Using cache 8002048f2543ceea3fb75f0151fc983a2a34042c40e79c38408033a97a412a7d

[2/2] COMMIT oracle/graph:24.4

--> 8002048f2543

Successfully tagged localhost/oracle/graph:24.4

8002048f2543ceea3fb75f0151fc983a2a34042c40e79c38408033a97a412a7d

% 


作成されたコンテナ・イメージからコンテナを作成して、Oracle Graph ServerのWeb UIにアクセスします。

podman run -d --name oraclegraph -p 7007:7007 -e JAVA_TOOL_OPTIONS="-Xms1G -Xmx2G" localhost/oracle/graph:24.4

% podman run -d --name oraclegraph -p 7007:7007 -e JAVA_TOOL_OPTIONS="-Xms1G -Xmx2G" localhost/oracle/graph:24.4

b92ae0fadd4ecc3e7f6f276a5734b3054cfaa308238687cc4676442e8801277a

% 


ブラウザより以下のURLにアクセスします。



今回の構成は、ローカルのコンテナとしてOracle Graph Serverを実行し、同じくローカルで実行しているOracle Database 23ai Freeにアクセスすることを想定しています。また、APEXのワークスペース・スキーマを接続ユーザーとします。

公式のドキュメントのUser Authentication and Authorizationのセクションにユーザーの設定方法が記載されていますが、Oracle Autonomous Databaseおよび23aiではGRAPH_DEVELOPERとGRAPH_ADMINISTRATORのロールは作成済みなので、ロールを割り当てるとOracle Graph Serverからアクセスできるようになります。以下では、APEXのワークスペース・スキーマをWKSP_APEXDEVとしています。

grant graph_developer to wksp_apexdev;
grant graph_administrator to wksp_apexdev;

ワークスペース・スキーマをUsername、スキーマのパスワードをPasswordに与えてSUBMITをクリックするとGraph Visualizationの画面が開きます。


今回の記事は以上になります。