Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an explicit ENTRYPOINT to the Agent "all" containers #3320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agent/containers/images/Dockerfile.layered.j2
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions agent/containers/images/container_entrypoint
Original file line number Diff line number Diff line change
@@ -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 "${@}"
70 changes: 70 additions & 0 deletions contrib/containerized-pbench/pbench
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#! /bin/bash
portante marked this conversation as resolved.
Show resolved Hide resolved
#
# 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} <Pbench Agent Command> [<arg>...]" >&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} "${@}"
33 changes: 33 additions & 0 deletions contrib/containerized-pbench/pbench_demo
Original file line number Diff line number Diff line change
@@ -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)