This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_deploy.sh
executable file
·68 lines (53 loc) · 1.76 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
#
# Copyright RedHat.
# License: MIT License see the file LICENSE
# Inspired by https://disconnected.systems/blog/another-bash-strict-mode/
set -eEu -o pipefail
trap 's=$?; echo "[ERROR] [$(date +"%T")] on $0:$LINENO"; exit $s' ERR
APP_NAME="ads-editors-build"
DEPLOYMENT_REPOSITORY="https://github.com/RedHatInsights/${APP_NAME}.git"
CONTAINER_ENGINE=${CONTAINER_ENGINE:-"docker"}
VERSION="$(git log --pretty=format:'%h' -n 1)"
IMAGE_REPOSITORY=${IMAGE_REPOSITORY:-"${APP_NAME//-build}"} # strip '-build' from ${APP_NAME}
IMAGE_TAG=${IMAGE_TAG:-${VERSION}}
IMAGE="${IMAGE_REPOSITORY}:${IMAGE_TAG}"
function log() {
echo "[$1] [$(date +"%T")] - ${2}"
}
function step() {
log "STEP" "$1"
}
if [[ ! -d ./.git ]]; then
echo "error: the build_deploy.sh script must be executed from the project root"
exit 1
fi
TOOLS_IMAGE=${TOOLS_IMAGE:-"quay.io/app-sre/mk-ci-tools:latest"}
TOOLS_HOME=$(mktemp -d)
function run() {
${CONTAINER_ENGINE} run \
-u ${UID} \
-v ${TOOLS_HOME}:/thome:z \
-e HOME=/thome \
-v ${PWD}:/workspace:z \
-w /workspace \
${TOOLS_IMAGE} \
$@
}
# Log in to the image registry:
if [ -z "${NACHOBOT_TOKEN}" ]; then
echo "The nachobot token hasn't been provided."
echo "Make sure to set the NACHOBOT_TOKEN environment variable."
exit 1
fi
step "Build the image"
${CONTAINER_ENGINE} build -t ${IMAGE} -f ./build/Dockerfile .
step "Push the client files"
CID=$(${CONTAINER_ENGINE} create ${IMAGE})
${CONTAINER_ENGINE} cp ${CID}:/opt/app-root/src/dist .
${CONTAINER_ENGINE} rm ${CID}
run /opt/tools/scripts/push_to_insights.sh \
--nachobot-token "${NACHOBOT_TOKEN}" \
--version "${VERSION}" \
--repository "${DEPLOYMENT_REPOSITORY}" \
--app-name "${APP_NAME}"