-
Notifications
You must be signed in to change notification settings - Fork 56
/
cico_setup.sh
executable file
·83 lines (71 loc) · 2.1 KB
/
cico_setup.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash -ex
REGISTRY="quay.io"
load_jenkins_vars() {
if [ -e "jenkins-env.json" ]; then
eval "$(./env-toolkit load -f jenkins-env.json \
DEVSHIFT_TAG_LEN \
QUAY_USERNAME \
QUAY_PASSWORD \
JENKINS_URL \
GIT_BRANCH \
GIT_COMMIT \
BUILD_NUMBER \
ghprbSourceBranch \
ghprbActualCommit \
BUILD_URL \
ghprbPullId)"
fi
}
prep() {
yum -y update
yum -y install docker git openssl-devel gcc subscription-manager-rhsm-certificates
# fix based on https://github.com/minishift/minishift-centos-iso/pull/255
# to enable ubi builds
touch /etc/rhsm/ca/redhat-uep.pem
systemctl start docker
}
docker_login() {
if [ -n "${QUAY_USERNAME}" -a -n "${QUAY_PASSWORD}" ]; then
docker login -u "${QUAY_USERNAME}" -p "${QUAY_PASSWORD}" "${REGISTRY}"
else
echo "Could not login, missing credentials for the registry"
exit 1
fi
}
build_image() {
# build image and tests
make docker-build
}
tag_push() {
local target=$1
local source=$2
docker tag "${source}" "${target}"
docker push "${target}"
}
push_image() {
local image_name
local image_repository
local short_commit
local image_url
image_name=$(make get-image-name)
image_repository=$(make get-image-repository)
short_commit=$(git rev-parse --short=7 HEAD)
if [ "$TARGET" = "rhel" ]; then
image_url="${REGISTRY}/openshiftio/rhel-bayesian-bayesian-api"
else
image_url="${REGISTRY}/openshiftio/bayesian-bayesian-api"
fi
if [ -n "${ghprbPullId}" ]; then
# PR build
pr_id="SNAPSHOT-PR-${ghprbPullId}"
tag_push "${image_url}:${pr_id}" "${image_name}"
tag_push "${image_url}:${pr_id}-${short_commit}" "${image_name}"
else
# master branch build
tag_push "${image_url}:latest" "${image_name}"
tag_push "${image_url}:${short_commit}" "${image_name}"
fi
echo 'CICO: Image pushed, ready to update deployed app'
}
load_jenkins_vars
prep