-
Notifications
You must be signed in to change notification settings - Fork 14
/
cico_build_deploy.sh
executable file
·99 lines (77 loc) · 2.73 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
GENERATOR_DOCKER_HUB_USERNAME=openshiftioadmin
REGISTRY_URI="quay.io"
REGISTRY_NS="fabric8io"
REGISTRY_IMAGE="fabric8-online-docs"
BUILDER_IMAGE="docs-builder"
BUILDER_CONT="docs-builder-container"
DEPLOY_IMAGE="docs-deploy"
DEPLOY_CONT="docs-deploy-container"
if [ "$TARGET" = "rhel" ]; then
REGISTRY_URL=${REGISTRY_URI}/openshiftio/rhel-${REGISTRY_NS}-${REGISTRY_IMAGE}
DOCKERFILE_DEPLOY="Dockerfile.deploy.rhel"
else
REGISTRY_URL=${REGISTRY_URI}/openshiftio/${REGISTRY_NS}-${REGISTRY_IMAGE}
DOCKERFILE_DEPLOY="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 -ex
if [ -z $CICO_LOCAL ]; then
eval "$(./env-toolkit load -f jenkins-env.json \
DEVSHIFT_TAG_LEN \
QUAY_USERNAME \
QUAY_PASSWORD \
GIT_COMMIT)"
# 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 UP BUILDER CONTAINER
docker ps | grep -q ${BUILDER_CONT} && docker stop ${BUILDER_CONT}
docker ps -a | grep -q ${BUILDER_CONT} && docker rm ${BUILDER_CONT}
#REMOVE DIR WITH OLD BUILT DOCS IF IT EXISTS
if [ -d $TARGET_DIR ]; then rm -rf ${TARGET_DIR}/; fi
#CREATE A FRESH DIR FOR BUILT DOCS TO BE PUT INTO
mkdir -pm 777 ${TARGET_DIR}
#BUILD BUILDER IMAGE
docker build -t ${BUILDER_IMAGE} -f Dockerfile.build .
#RUN BUILDER CONTAINER ONCE, THUS BUILDING THE DOCS
docker run --rm --name=${BUILDER_CONT} -it --volume=$(pwd)/${TARGET_DIR}:/${TARGET_DIR}:Z ${BUILDER_IMAGE}
#LOGIN IS REQUIRED FOR BUILDING ON RHEL
if [ -z "$CICO_LOCAL" ]; then
docker_login "${QUAY_USERNAME}" "${QUAY_PASSWORD}" "${REGISTRY_URI}"
fi
#BUILD DEPLOY IMAGE
docker build -t ${DEPLOY_IMAGE} -f "${DOCKERFILE_DEPLOY}" .
#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
#SERVE DOCS WHEN ON LOCAL
if [ ! -z $CICO_LOCAL ]; then
#CLEAN UP OLD DEPLOY (CADDY) CONTAINERS
docker ps | grep -q $DEPLOY_CONT && docker stop $DEPLOY_CONT
docker ps -a | grep -q $DEPLOY_CONT && docker rm $DEPLOY_CONT
#RUN THE DEPLOY (CADDY) CONTAINER
docker run --detach=true --name $DEPLOY_CONT --publish 8080:8080 $DEPLOY_IMAGE && \
echo "Docs are now available for local preview at http://127.0.0.1:8080/" || \
echo "Local deployment of docs failed."
fi