This repository was archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild_deploy.sh
More file actions
executable file
·80 lines (66 loc) · 2.29 KB
/
build_deploy.sh
File metadata and controls
executable file
·80 lines (66 loc) · 2.29 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
#!/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
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
APP_NAME="application-services"
DEPLOYMENT_REPOSPITORY="https://github.com/RedHatInsights/rhosak-dashboard-build.git"
CONTAINER_ENGINE=${CONTAINER_ENGINE:-"docker"}
VERSION="$(git log --pretty=format:'%h' -n 1)"
IMAGE_REGISTRY=${IMAGE_REGISTRY:-"quay.io"}
IMAGE_REPOSITORY=${IMAGE_REPOSITORY:-"${IMAGE_REGISTRY}/rhoas/application-services-ui"}
IMAGE_TAG=${IMAGE_TAG:-${VERSION}}
IMAGE="${IMAGE_REPOSITORY}:${IMAGE_TAG}"
RHOAS_QUAY_USER=${RHOAS_QUAY_USER:-}
RHOAS_QUAY_TOKEN=${RHOAS_QUAY_TOKEN:-}
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} \
$@
}
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 .
if [[ ! -z "${RHOAS_QUAY_USER}" ]] && [[ ! -z "${RHOAS_QUAY_TOKEN}" ]]; then
step "Push ui image"
${CONTAINER_ENGINE} login --username "${RHOAS_QUAY_USER}" --password "${RHOAS_QUAY_TOKEN}" "${IMAGE_REGISTRY}"
# update the latest image too
${CONTAINER_ENGINE} tag ${IMAGE} ${IMAGE_REPOSITORY}:latest
# push both tags
${CONTAINER_ENGINE} push ${IMAGE}
${CONTAINER_ENGINE} push ${IMAGE_REPOSITORY}:latest
fi
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_REPOSPITORY}" \
--app-name "${APP_NAME}"