From 4131860646e7b59ed9188eea46061297ffea0cdb Mon Sep 17 00:00:00 2001 From: "Brown, Joshua" Date: Wed, 18 Oct 2023 16:40:12 -0400 Subject: [PATCH] Add docker files for building python client --- .../Dockerfile.python-client-base.ubuntu | 15 +++++ python/docker/Dockerfile.python-client.ubuntu | 59 +++++++++++++++++++ python/docker/entrypoint.sh | 40 +++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 python/docker/Dockerfile.python-client-base.ubuntu create mode 100644 python/docker/Dockerfile.python-client.ubuntu create mode 100755 python/docker/entrypoint.sh diff --git a/python/docker/Dockerfile.python-client-base.ubuntu b/python/docker/Dockerfile.python-client-base.ubuntu new file mode 100644 index 000000000..3395b072a --- /dev/null +++ b/python/docker/Dockerfile.python-client-base.ubuntu @@ -0,0 +1,15 @@ +FROM ubuntu:focal as build + +ARG DATAFED_DIR="/datafed" +ARG BUILD_DIR="/datafed/source" + +RUN mkdir -p ${BUILD_DIR} + +WORKDIR ${BUILD_DIR} + +COPY ./scripts/dependency_install_functions.sh ${BUILD_DIR}/scripts/ +COPY ./scripts/dependency_versions.sh ${BUILD_DIR}/scripts/ +COPY ./scripts/install_python_client_dependencies.sh ${BUILD_DIR}/scripts/ + +RUN echo "#!/bin/bash\n\$@" > /usr/bin/sudo && chmod +x /usr/bin/sudo +RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC ${BUILD_DIR}/scripts/install_python_client_dependencies.sh diff --git a/python/docker/Dockerfile.python-client.ubuntu b/python/docker/Dockerfile.python-client.ubuntu new file mode 100644 index 000000000..b22eddc59 --- /dev/null +++ b/python/docker/Dockerfile.python-client.ubuntu @@ -0,0 +1,59 @@ +FROM code.ornl.gov:4567/dlsw/datafed/python-client-base:latest as build + +ARG DATAFED_DIR="/datafed" +ARG BUILD_DIR="/datafed/source" +ARG DATAFED_INSTALL_PATH="/datafed/install" + +# The above should also be available at runtime +ENV DATAFED_DIR="$DATAFED_DIR" +ENV BUILD_DIR="$BUILD_DIR" +ENV DATAFED_INSTALL_PATH="$DATAFED_INSTALL_PATH/python-client" + +RUN mkdir -p ${BUILD_DIR}/logs +RUN mkdir -p ${DATAFED_INSTALL_PATH} +RUN mkdir -p ${DATAFED_INSTALL_PATH}/keys + +# For communicating with repo server +# EXPOSE 7512 +# For listening to web server +# EXPOSE 7513 +# ArangoDB port +# EXPOSE 8529 + +# Create datafed user, prefer more secure login options than password +# Recommended to mount ssh public key on run +RUN adduser --disabled-password --gecos "" datafed + +WORKDIR ${BUILD_DIR} + +COPY ./common ${BUILD_DIR}/common +COPY ./CMakeLists.txt ${BUILD_DIR} +COPY ./scripts/dependency_versions.sh ${BUILD_DIR}/scripts/ +COPY ./scripts/generate_datafed.sh ${BUILD_DIR}/scripts/ +COPY ./cmake ${BUILD_DIR}/cmake +COPY ./python ${BUILD_DIR}/python + +# All files should be owned by the datafed user +RUN chown -R datafed:datafed ${DATAFED_DIR} + +USER datafed + +RUN ${BUILD_DIR}/scripts/generate_datafed.sh &&\ + cmake -S. -B build -DBUILD_REPO_SERVER=False -DBUILD_AUTHZ=False \ + -DBUILD_CORE_SERVER=False -DBUILD_WEB_SERVER=False \ + -DBUILD_DOCS=False -DBUILD_PYTHON_CLIENT=True \ + -DBUILD_FOXX=False -DENABLE_UNIT_TESTS=False \ + -DBUILD_TESTS=False -DBUILD_COMMON=False &&\ + cmake --build build -j 8 +RUN cmake --build build --target pydatafed + +WORKDIR ${BUILD_DIR}/python/datafed_pkg + +# Install datafed client +RUN python3 -m pip install . + +WORKDIR /home/datafed + +#ENTRYPOINT ["/bin/bash"] +ENTRYPOINT ["/datafed/source/python/docker/entrypoint.sh"] + diff --git a/python/docker/entrypoint.sh b/python/docker/entrypoint.sh new file mode 100755 index 000000000..f9573344f --- /dev/null +++ b/python/docker/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euf -o pipefail + +SCRIPT=$(realpath "$0") +SOURCE=$(dirname "$SCRIPT") + +# Entry point file expects that the directory where the DataFed source file +# is passed in as the first argument + +echo "SOURCE BUILD DIR $BUILD_DIR" + +# Here we will rerun datafed configuration script to create a new set of +# default variables that are useful for setting up the DataFed Python client +# ini file + +"${BUILD_DIR}/scripts/generate_datafed.sh" +source "${BUILD_DIR}/config/datafed.sh" + +mkdir -p "/home/datafed/.datafed" + +# At this point we will create an ini file +cat << EOF > "/home/datafed/.datafed/datafed-client.ini" +[server] +host = ${DATAFED_DOMAIN} +port = ${DATAFED_SERVER_PORT} +config_dir = /home/datafed/.datafed + +[client] +config_dir = /home/datafed/.datafed + +EOF + +if [ "$#" -eq 0 ]; then + echo "No arguments were passed, running bash" + exec "/home/datafed/.local/bin/datafed --cfg /home/datafed/.datafed/datafed-client.ini" +fi + +"$@" +