From c45c1579d410ceef50781f0f42c6397ed2f2e279 Mon Sep 17 00:00:00 2001 From: Yu Qi Zhang Date: Tue, 22 Jan 2019 12:22:30 -0500 Subject: [PATCH] rhcos-toolbox: fix default and add runlabel Change default image to redhat registry support-tools image for debugging, as well as add the ability to runlabel directly if the RUN label exists in the image. Signed-off-by: Yu Qi Zhang --- rhcos-toolbox | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/rhcos-toolbox b/rhcos-toolbox index ae0f2e1..9360927 100755 --- a/rhcos-toolbox +++ b/rhcos-toolbox @@ -4,8 +4,8 @@ set -eo pipefail trap cleanup EXIT setup() { - REGISTRY=registry.fedoraproject.org - IMAGE=fedora:latest + REGISTRY=registry.redhat.io + IMAGE=rhel7/support-tools TOOLBOX_NAME=toolbox-"${USER}" # Allow user overrides @@ -23,23 +23,30 @@ run() { image_pull fi + local runlabel=$(image_runlabel) if ! container_exists; then echo "Spawning a container '$TOOLBOX_NAME' with image '$TOOLBOX_IMAGE'" - container_create + if [[ -z "$runlabel" ]]; then + container_create + else + echo "Detected RUN label in the container image. Using that as the default..." + container_runlabel + return + fi else - echo "Container '$TOOLBOX_NAME' already exists. Starting..." + echo "Container '$TOOLBOX_NAME' already exists. Trying to start..." echo "(To remove the container and start with a fresh toolbox, run: sudo podman rm '$TOOLBOX_NAME')" fi local state=$(container_state) - if [[ "$state" == configured ]] || [[ "$state" == exited ]]; then + if [[ "$state" == configured ]] || [[ "$state" == exited ]] || [[ "$state" == stopped ]]; then container_start elif [[ "$state" != running ]]; then echo "Container '$TOOLBOX_NAME' in unknown state: '$state'" return 1 fi - echo "Container started successfully." + echo "Container started successfully. To exit, type 'exit'." container_exec "$@" } @@ -59,6 +66,10 @@ image_exists() { sudo podman inspect "$TOOLBOX_IMAGE" &>/dev/null } +image_runlabel() { + sudo podman container runlabel --display RUN "$TOOLBOX_IMAGE" +} + image_pull() { if ! sudo podman pull "$TOOLBOX_IMAGE"; then read -r -p "Would you like to authenticate to registry: '${REGISTRY}' and try again? [y/N] " @@ -95,6 +106,13 @@ container_start() { fi } +container_runlabel() { + if ! sudo podman container runlabel --name "$TOOLBOX_NAME" RUN "$TOOLBOX_IMAGE" 2>&1; then + echo "$0: failed to runlabel on image '$TOOLBOX_IMAGE'" + exit 1 + fi +} + container_exec() { sudo podman exec \ --env LANG="$LANG" \