Skip to content

Commit

Permalink
openshift: add "dry run" flag
Browse files Browse the repository at this point in the history
This adds a "dry run" flag (`n`) and a "debug" flag (`x`) instead of
having shell debugging on unconditionally.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Jul 16, 2024
1 parent 1a5f342 commit 3d3c03c
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions contrib/openshift/build_and_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#!/bin/bash
set -exuo pipefail
#!/usr/bin/bash
set -euo pipefail

while getopts nx name; do
case "$name" in
x) set -x ;;
n) dryrun=1 ;;
?)
printf "Usage: %s: [-nx]\n" "$0"
exit 2
;;
esac
done

: "${QUAY_USER:?Missing QUAY_USER variable.}"
: "${QUAY_TOKEN:?Missing QUAY_TOKEN variable.}"
: "${REGISTRY:=quay.io}"
: "${REPOSITORY:=${REGISTRY}/app-sre}"
: "${IMAGE:=${REPOSITORY}/clair}"
GIT_HASH="$(git rev-parse --short=7 HEAD)"
CONTAINER_ENGINE=$(command -v podman 2>/dev/null || command -v docker 2>/dev/null)
tags=("${IMAGE}:latest" "${IMAGE}:${GIT_HASH}")

git archive HEAD |
${CONTAINER_ENGINE} build -t clair-service:latest -
for t in "${tags[@]}"; do
${CONTAINER_ENGINE} tag clair-service:latest "$t"
done

${CONTAINER_ENGINE} login -u="${QUAY_USER}" -p="${QUAY_TOKEN}" "${REGISTRY}"

${CONTAINER_ENGINE} tag clair-service:latest ${IMAGE}:latest
${CONTAINER_ENGINE} push ${IMAGE}:latest
[[ -n "$dryrun" ]] && exit 0

${CONTAINER_ENGINE} tag clair-service:latest ${IMAGE}:${GIT_HASH}
${CONTAINER_ENGINE} push ${IMAGE}:${GIT_HASH}
: "${QUAY_USER:?Missing QUAY_USER variable.}"
: "${QUAY_TOKEN:?Missing QUAY_TOKEN variable.}"
${CONTAINER_ENGINE} login -u="${QUAY_USER}" -p="${QUAY_TOKEN}" "${REGISTRY}"
for t in "${tags[@]}"; do
${CONTAINER_ENGINE} push "$t"
done

0 comments on commit 3d3c03c

Please sign in to comment.