|
1 | 1 | #! /bin/bash |
2 | 2 | # |
3 | 3 | # This script is a wrapper to facilitate the invocation of a Pbench Agent |
4 | | -# command using a containerized deployment of the Pbench Agent. Simply prefix |
| 4 | +# command using a containerized deployment of the Pbench Agent. Simply prefix |
5 | 5 | # a Pbench Agent command line with the path to this script to run it inside a |
6 | 6 | # container, without needing to install the Agent on the host system. |
7 | 7 | # |
8 | 8 | # Invocation options are provided as environment variables: |
9 | | -# PB_AGENT_IMAGE_NAME: the full image name for the containerized Pbench Agent |
10 | | -# _PBENCH_AGENT_CONFIG: the location of the Pbench Agent configuration file |
11 | | -# PB_AGENT_RUN_DIR: the directory for use as the Pbench Agent "run directory" |
12 | | -# PB_AGENT_SERVER_LOC: the host and port for the Pbench Server |
13 | | -# PB_AGENT_PODMAN_OPTIONS: Additional options to be supplied to Podman run |
| 9 | +# PB_AGENT_IMAGE_NAME: the full image name for the containerized Pbench Agent |
| 10 | +# PB_AGENT_RUN_DIR: the directory for use as the Pbench Agent "run directory" |
| 11 | +# PB_AGENT_CA: a CA bundle to verify Pbench Server PUTs |
| 12 | +# PB_AGENT_PODMAN_OPTIONS: Additional options to be supplied to Podman run |
14 | 13 | # |
15 | 14 | # In all cases, reasonable defaults are supplied if the environment variables |
16 | 15 | # are not defined. |
17 | 16 | # |
18 | | -# This script checks for the presence of a `~/.ssh` directory, an existing |
19 | | -# Pbench Agent configuration file, and a Pbench Agent "run directory" and maps |
20 | | -# them into the container if they exist. If the configuration file is missing |
21 | | -# but the location of the Pbench Server is available, then this script will |
22 | | -# generate the configuration file, and the script creates the run directory if |
23 | | -# it does not exist. The script then invokes the Pbench Agent container with |
24 | | -# these options and any others which the user has specified and passes in the |
25 | | -# command to be executed. |
| 17 | +# This script manages a persistent host Pbench Agent "run directory", which |
| 18 | +# defaults to /var/tmp/{USER}/pbench-agent/run, and maps that directory into |
| 19 | +# the container so that multiple runs can be generated and uploaded at once. |
| 20 | +# |
| 21 | +# To upload results to a Pbench Server, use this script to execute the |
| 22 | +# pbench-results-move command within the container, specifying either --relay |
| 23 | +# with the address of a Pbench Relay Server, or --server with the address of a |
| 24 | +# Pbench Server and --token to specify a Pbench Server API key for user |
| 25 | +# authentication. |
| 26 | +# |
| 27 | +# To use a server with a certificate signed by the Pbench development CA bundle |
| 28 | +# define the environment variable PB_AGENT_CA to cause the CA to be mapped into |
| 29 | +# the container and defined using REQUESTS_CA_BUNDLE: |
| 30 | +# |
| 31 | +# PB_AGENT_CA=server/pbenchinacan/etc/pki/tls/certs/pbench_CA.crt \ |
| 32 | +# contrib/containerized-pbench/pbench pbench-results-move \ |
| 33 | +# --server https://<server>:8443 --token <api-token> |
26 | 34 |
|
27 | 35 | image_name=${PB_AGENT_IMAGE_NAME:-quay.io/pbench/pbench-agent-all-centos-8:main} |
28 | | -config_file=${_PBENCH_AGENT_CONFIG:-${HOME}/.config/pbench/pbench-agent.cfg} |
29 | 36 | pbench_run_dir=${PB_AGENT_RUN_DIR:-/var/tmp/${USER}/pbench-agent/run} |
30 | | -pbench_server=${PB_AGENT_SERVER_LOC} |
| 37 | +ca=${PB_AGENT_CA:-${REQUESTS_CA_BUNDLE}} |
| 38 | +if [[ ${ca} ]]; then |
| 39 | + pbench_ca=$(realpath ${ca}) # expand path outside container |
| 40 | +fi |
| 41 | +container_ca=/etc/pki/tls/certs/pbench_CA.crt # path inside container |
31 | 42 | other_options=${PB_AGENT_PODMAN_OPTIONS} |
32 | 43 |
|
33 | 44 | if [[ $# == 0 || $1 == "help" || $1 == "-h" || $1 == "--help" ]]; then |
34 | 45 | echo "Usage: ${0} <Pbench Agent Command> [<arg>...]" >&2 |
35 | 46 | exit 2 |
36 | 47 | fi |
37 | 48 |
|
38 | | -if [[ -d "${HOME}/.ssh" && -r "${HOME}/.ssh" ]]; then |
39 | | - other_options="--security-opt=label=disable -v ${HOME}/.ssh:/root/.ssh ${other_options}" |
40 | | -fi |
41 | | - |
42 | | -if [[ -f "${config_file}" && -r "${config_file}" ]]; then |
43 | | - other_options="-v ${config_file}:/opt/pbench-agent/config/pbench-agent.cfg:z ${other_options}" |
44 | | -elif [[ -n "${pbench_server}" ]]; then |
45 | | - echo "Warning: the Pbench Agent config file is missing; attempting to generate one in ${config_file}" >&2 |
46 | | - # TODO: this should be handled by a separate Pbench Agent "configuration wizard". |
47 | | - mkdir -p $(dirname ${config_file}) |
48 | | - cat > ${config_file} <<- EOF |
49 | | - [DEFAULT] |
50 | | - pbench_install_dir = /opt/pbench-agent |
51 | | - pbench_web_server = ${pbench_server} |
52 | | - [config] |
53 | | - path = %(pbench_install_dir)s/config |
54 | | - files = pbench-agent-default.cfg |
55 | | - EOF |
56 | | -else |
57 | | - echo "Warning: the Pbench Agent config file (e.g., ${config_file}) is missing or inaccessible -- using default configuration." >&2 |
58 | | -fi |
59 | | - |
60 | 49 | mkdir -p ${pbench_run_dir} |
61 | | -other_options="-v ${pbench_run_dir}:/var/lib/pbench-agent:z ${other_options}" |
| 50 | +if [[ -f "${pbench_ca}" ]]; then |
| 51 | + other_options="-v ${pbench_ca}:${container_ca}:Z ${other_options}" |
| 52 | + other_options="-e REQUESTS_CA_BUNDLE=${container_ca} ${other_options}" |
| 53 | +fi |
62 | 54 |
|
63 | 55 | podman run \ |
64 | 56 | -it \ |
65 | 57 | --rm \ |
66 | 58 | --network host \ |
67 | 59 | --name pbench-agent \ |
| 60 | + -v ${pbench_run_dir}:/var/lib/pbench-agent:Z \ |
68 | 61 | ${other_options} \ |
69 | 62 | ${image_name} "${@}" |
0 commit comments