-
Notifications
You must be signed in to change notification settings - Fork 42
/
build_deploy.sh
executable file
·48 lines (36 loc) · 1.43 KB
/
build_deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -exv
export PR_CHECK="false" # Only used when doing a PR check from Github.
IMAGE="quay.io/cloudservices/edge-api"
# Determine Git commit hash (7 hex characters)
IMAGE_TAG="$(git rev-parse --short=7 HEAD)"
if [[ -z "${QUAY_USER}" || -z "${QUAY_TOKEN}" ]]; then
echo "QUAY_USER and QUAY_TOKEN must be set"
exit 1
fi
if [[ -z "${RH_REGISTRY_USER}" || -z "${RH_REGISTRY_TOKEN}" ]]; then
echo "RH_REGISTRY_USER and RH_REGISTRY_TOKEN must be set"
exit 1
fi
AUTH_CONF_DIR="$(pwd)/.podman"
mkdir -p "${AUTH_CONF_DIR}"
export REGISTRY_AUTH_FILE="${AUTH_CONF_DIR}/auth.json"
podman login -u="${QUAY_USER}" -p="${QUAY_TOKEN}" quay.io
podman login -u="${RH_REGISTRY_USER}" -p="${RH_REGISTRY_TOKEN}" registry.redhat.io
# Build image
podman build --no-cache -f Dockerfile -t "${IMAGE}:${IMAGE_TAG}" .
# Push image to remote repository
podman push "${IMAGE}:${IMAGE_TAG}"
TAGS="latest main qa"
# check if a change is under cmd/kafka directory and tag accordingly
#num_files=$(git log --raw -n 1 --no-merges | egrep "^:.*" | wc -l)
num_kafka_files=$(git log --raw -n 1 --no-merges | egrep "^:.*cmd/kafka" | wc -l)
# if all changes are under cmd/kafka then only tag kafka
if [[ $num_kafka_files -gt 0 ]]; then
#[[ num_files -eq num_kafka_files ]] && TAGS="kafka" || TAGS="$TAGS kafka"
TAGS="$TAGS kafka"
fi
for tag in $(echo $TAGS); do
podman tag "${IMAGE}:${IMAGE_TAG}" "${IMAGE}:${tag}"
podman push "${IMAGE}:${tag}"
done