diff --git a/agent/containers/images/Dockerfile.layered.j2 b/agent/containers/images/Dockerfile.layered.j2 index 1eb337488d..f44c290b59 100644 --- a/agent/containers/images/Dockerfile.layered.j2 +++ b/agent/containers/images/Dockerfile.layered.j2 @@ -1,6 +1,11 @@ # {{ distro }} pbench-agent {{ kind }} image FROM pbench-agent-base-{{ distro }}:{{ tag }} +{% if kind == 'all' %} +COPY ./container_entrypoint /container_entrypoint +ENTRYPOINT ["/container_entrypoint"] +{% endif %} + {% if kind in ('tools', 'all') %} {% if distro.startswith('fedora') or distro == 'centos-7' or distro == 'centos-8' %} COPY ./{{ distro }}-pcp.repo /etc/yum.repos.d/pcp.repo diff --git a/agent/containers/images/container_entrypoint b/agent/containers/images/container_entrypoint new file mode 100755 index 0000000000..404bada1ce --- /dev/null +++ b/agent/containers/images/container_entrypoint @@ -0,0 +1,11 @@ +#!/bin/bash + +# This script is the entrypoint for the Agent containers. +# +# Since execution in these environments does not follow the normal login path, +# we first execute the `agent/profile` script to set up the environment for +# Agent commands. Then we exec the requested command. + +source /opt/pbench-agent/profile + +exec "${@}" diff --git a/contrib/containerized-pbench/pbench b/contrib/containerized-pbench/pbench new file mode 100755 index 0000000000..e6671a35a7 --- /dev/null +++ b/contrib/containerized-pbench/pbench @@ -0,0 +1,70 @@ +#! /bin/bash +# +# This script is a wrapper to facilitate the invocation of a Pbench Agent +# command using a containerized deployment of the Pbench Agent. Simply prefix +# a Pbench Agent command line with the path to this script to run it inside a +# container, without needing to install the Agent on the host system. +# +# Invocation options are provided as environment variables: +# PB_AGENT_IMAGE_NAME: the full image name for the containerized Pbench Agent +# _PBENCH_AGENT_CONFIG: the location of the Pbench Agent configuration file +# PB_AGENT_RUN_DIR: the directory for use as the Pbench Agent "run directory" +# PB_AGENT_SERVER_LOC: the host and port for the Pbench Server +# PB_AGENT_PODMAN_OPTIONS: Additional options to be supplied to Podman run +# +# In all cases, reasonable defaults are supplied if the environment variables +# are not defined. +# +# This script checks for the presence of a `~/.ssh` directory, an existing +# Pbench Agent configuration file, and a Pbench Agent "run directory" and maps +# them into the container if they exist. If the configuration file is missing +# but the location of the Pbench Server is available, then this script will +# generate the configuration file, and the script creates the run directory if +# it does not exist. The script then invokes the Pbench Agent container with +# these options and any others which the user has specified and passes in the +# command to be executed. + +image_name=${PB_AGENT_IMAGE_NAME:-quay.io/pbench/pbench-agent-all-centos-8:latest} +config_file=${_PBENCH_AGENT_CONFIG:-${HOME}/.config/pbench/pbench-agent.cfg} +pbench_run_dir=${PB_AGENT_RUN_DIR:-/var/tmp/${USER}/pbench-agent/run} +pbench_server=${PB_AGENT_SERVER_LOC} +other_options=${PB_AGENT_PODMAN_OPTIONS} + +if [[ $# == 0 || $1 == "help" || $1 == "-h" || $1 == "--help" ]]; then + echo "Usage: ${0} [...]" >&2 + exit 2 +fi + +if [[ -d "${HOME}/.ssh" && -r "${HOME}/.ssh" ]]; then + other_options="-v ${HOME}/.ssh:/root/.ssh:z ${other_options}" +fi + +if [[ -f "${config_file}" && -r "${config_file}" ]]; then + other_options="-v ${config_file}:/opt/pbench-agent/config/pbench-agent.cfg:z ${other_options}" +elif [[ -n "${pbench_server}" ]]; then + echo "Warning: the Pbench Agent config file is missing; attempting to generate one in ${config_file}" >&2 + # TODO: this should be handled by a separate Pbench Agent command which + # provides a "configuration wizard". + mkdir -p $(dirname ${config_file}) + cat > ${config_file} <<- EOF + [DEFAULT] + pbench_install_dir = /opt/pbench-agent + pbench_web_server = ${pbench_server} + [config] + path = %(pbench_install_dir)s/config + files = pbench-agent-default.cfg + EOF +else + echo "Warning: the Pbench Agent config file (e.g., ${config_file}) is missing or inaccessible -- using default configuration." >&2 +fi + +mkdir -p ${pbench_run_dir} +other_options="-v ${pbench_run_dir}:/var/lib/pbench-agent:z ${other_options}" + +podman run \ + -it \ + --rm \ + --network host \ + --name pbench-agent \ + ${other_options} \ + ${image_name} "${@}" diff --git a/contrib/containerized-pbench/pbench_demo b/contrib/containerized-pbench/pbench_demo new file mode 100755 index 0000000000..f78be72721 --- /dev/null +++ b/contrib/containerized-pbench/pbench_demo @@ -0,0 +1,33 @@ +#! /bin/bash -xe +# +# This script provides a demonstration of the contrib/containerized-pbench/pbench +# wrapper script. +# + +#+ +# Set up a few things to make life simpler. Typically, these would already be +# set in the users environment (e.g., the `pbench` command alias would be done +# by the user's login script; we wouldn't need the `shopt` command if these +# commands were being run interactively; and, we only need `PB_AGENT_IMAGE_NAME` +# here because we're not using the default image). +#- +shopt -s expand_aliases +alias pbench=$(git rev-parse --show-toplevel)/contrib/containerized-pbench/pbench + +FIOTEST=${PWD}/fiotest +export PB_AGENT_PODMAN_OPTIONS="--pull newer -v ${FIOTEST}:/fiotest:z" +export PB_AGENT_IMAGE_NAME=quay.io/pbench/pbench-agent-all-fedora-36:main + +mkdir -p ${FIOTEST} + +#+ +# Run the demo! +#- +pbench pbench-register-tool-set light +pbench pbench-list-tools +pbench pbench-user-benchmark --config example-workload -- \ + fio --directory=/fiotest --name fio_test_file --direct=1 --rw=randread \ + --bs=16k --size=100M --numjobs=16 --time_based --runtime=20s \ + --group_reporting --norandommap +pbench pbench-generate-token --output=/var/lib/pbench-agent/.token +pbench pbench-results-move --token=$(< /var/tmp/pbench/pbench-agent/run/.token)