-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
24 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |