This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
cico_build_deploy.sh
executable file
·85 lines (64 loc) · 2.22 KB
/
cico_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -x
GENERATOR_DOCKER_HUB_USERNAME=openshiftioadmin
REGISTRY_URI="quay.io"
REGISTRY_NS="fabric8"
REGISTRY_IMAGE="launcher-documentation"
BUILDER_IMAGE="launcher-documentation-builder"
BUILDER_CONT="launcher-documentation-builder-container"
DEPLOY_IMAGE="launcher-documentation-deploy"
if [ "$TARGET" = "rhel" ]; then
REGISTRY_URL=${REGISTRY_URI}/openshiftio/rhel-${REGISTRY_NS}-${REGISTRY_IMAGE}
DOCKERFILE="Dockerfile.deploy.rhel"
else
REGISTRY_URL=${REGISTRY_URI}/openshiftio/${REGISTRY_NS}-${REGISTRY_IMAGE}
DOCKERFILE="Dockerfile.deploy"
fi
TARGET_DIR="html"
function docker_login() {
local USERNAME=$1
local PASSWORD=$2
local REGISTRY=$3
if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
docker login -u ${USERNAME} -p ${PASSWORD} ${REGISTRY}
fi
}
function tag_push() {
local TARGET_IMAGE=$1
docker tag ${DEPLOY_IMAGE} ${TARGET_IMAGE}
docker push ${TARGET_IMAGE}
}
# Exit on error
set -e
if [ -z "$CICO_LOCAL" ]; then
[ -f jenkins-env ] && cat jenkins-env | grep -e PASS -e USER -e GIT -e DEVSHIFT > inherit-env
[ -f inherit-env ] && . inherit-env
# We need to disable selinux for now, XXX
/usr/sbin/setenforce 0 || :
# Get all the deps in
yum -y install docker make git
service docker start
fi
#CLEAN
docker ps | grep -q ${BUILDER_CONT} && docker stop ${BUILDER_CONT}
docker ps -a | grep -q ${BUILDER_CONT} && docker rm ${BUILDER_CONT}
rm -rf ${TARGET_DIR}/
#BUILD
docker build -t ${BUILDER_IMAGE} -f Dockerfile.build .
mkdir -pm 777 ${TARGET_DIR}/
mkdir -pm 777 ${TARGET_DIR}/docs
mkdir -pm 777 ${TARGET_DIR}/docs/images
docker run --detach=true --name ${BUILDER_CONT} -t -v $(pwd)/${TARGET_DIR}:/${TARGET_DIR}:Z ${BUILDER_IMAGE} /bin/tail -f /dev/null #FIXME
docker exec ${BUILDER_CONT} sh scripts/build_guides.sh
#Need to do this again to set permission of images and html files
chmod -R 0777 ${TARGET_DIR}/
#LOGIN
docker_login "${QUAY_USERNAME}" "${QUAY_PASSWORD}" "${REGISTRY_URI}"
#BUILD DEPLOY IMAGE
docker build -t ${DEPLOY_IMAGE} -f "${DOCKERFILE}" .
#PUSH
if [ -z "$CICO_LOCAL" ]; then
TAG=$(echo $GIT_COMMIT | cut -c1-${DEVSHIFT_TAG_LEN})
tag_push "${REGISTRY_URL}:${TAG}"
tag_push "${REGISTRY_URL}:latest"
fi