aboutsummaryrefslogtreecommitdiffstats
path: root/docker-build.sh
blob: fb4cac5bf281eb755c095f6ee98905fb30b0cc08 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#
#
# 1 build the docker image with both service manager and ves collector
# 2 tag and then push to the remote repo if not verify
#


phase=$1

case $phase in 
  verify|merge|release) 
    echo Running $phase job
    ;;
  *)
    echo Unknown phase \'$phase\'
    exit 1
esac


# DCAE Controller service manager for VES collector
DCM_AR="${WORKSPACE}/manager.zip"
if [ ! -f "${DCM_AR}" ]
then
    echo "FATAL error cannot locate ${DCM_AR}"
    exit 2
fi

# unarchive the service manager
TARGET="${WORKSPACE}/target"
STAGE="${TARGET}/stage"
DCM_DIR="${STAGE}/opt/app/manager"
[ ! -d "${DCM_DIR}" ] && mkdir -p "${DCM_DIR}"
unzip -qo -d "${DCM_DIR}" "${DCM_AR}"

# unarchive the collector
VERSION=$(xpath -e '/project/version/text()' pom.xml)
AR=${WORKSPACE}/target/OpenVESCollector-${VERSION}-bundle.tar.gz
APP_DIR=${STAGE}/opt/app/SEC

[ -d ${STAGE}/opt/app/OpenVESCollector-${VERSION} ] && rm -rf ${STAGE}/opt/app/OpenVESCollector-$VERSION

[ ! -f $APP_DIR ] && mkdir -p ${APP_DIR}

gunzip -c ${AR} | tar xvf - -C ${APP_DIR} --strip-components=1

#
# generate the manager start-up.sh
#
## [ -f "${DCM_DIR}/start-manager.sh" ] && exit 0

cat <<EOF > "${DCM_DIR}/start-manager.sh"
#!/bin/bash

MAIN=org.openecomp.dcae.controller.service.standardeventcollector.servers.manager.DcaeControllerServiceStandardeventcollectorManagerServer
ACTION=start

WORKDIR=/opt/app/manager

LOGS=\$WORKDIR/logs

mkdir -p \$LOGS

cd \$WORKDIR

echo 10.0.4.102 \$(hostname).dcae.simpledemo.openecomp.org >> /etc/hosts

if [ ! -e config ]; then
	echo no configuration directory setup: \$WORKDIR/config
	exit 1
fi

exec java -cp ./config:./lib:./lib/*:./bin \$MAIN \$ACTION > logs/manager.out 2>logs/manager.err

EOF

chmod 775 "${DCM_DIR}/start-manager.sh"


#
# generate docker file
#
cat <<EOF > "${STAGE}/Dockerfile"
FROM ubuntu:14.04

MAINTAINER dcae@lists.openecomp.org

WORKDIR /opt/app/manager

ENV HOME /opt/app/SEC
ENV JAVA_HOME /usr

RUN apt-get update && apt-get install -y \
        bc \
        curl \
        telnet \
        vim \
        netcat \
        openjdk-7-jdk

COPY opt /opt

EXPOSE 9999

CMD [ "/opt/app/manager/start-manager.sh" ]
EOF

#
# build the docker image. tag and then push to the remote repo
#
IMAGE='openecomp/dcae-collector-common-event'
#TAG='1.0.0'
VERSION=$(xpath -e "//project/version/text()" "pom.xml")
VERSION=$(echo $VERSION |sed 's/\"//')
EXT=$(echo "$VERSION" | rev | cut -s -f1 -d'-' | rev)
if [ -z "$EXT" ]; then
    VERSION=$(echo "${VERSION}-STAGING")
fi

TIMESTAMP=$(date +%C%y%m%dT%H%M%S)
TAG="$VERSION-$TIMESTAMP"
LFQI="${IMAGE}:${TAG}"
BUILD_PATH="${WORKSPACE}/target/stage"

# build a docker image
echo docker build --rm -t "${LFQI}" "${BUILD_PATH}"
docker build --rm -t "${LFQI}" "${BUILD_PATH}"

case $phase in 
  verify) 
    exit 0
  ;;
esac

#
# push the image
#
# io registry  DOCKER_REPOSITORIES="nexus3.openecomp.org:10001 \
# release registry                   nexus3.openecomp.org:10002 \
# snapshot registry                   nexus3.openecomp.org:10003"
REPO='nexus3.openecomp.org:10003'

if [ ! -z "$REPO" ]; then
    RFQI="${REPO}/${LFQI}"
    # tag
    docker tag "${LFQI}" "${RFQI}"

    # push to remote repo
    docker push "${RFQI}"


    TAG="latest"
    LFQI="${IMAGE}:${TAG}"
    RFQI2="${REPO}/${LFQI}"
    echo "$LFQI"
    echo "$RFQI2"
    docker tag "${RFQI}" "${RFQI2}"
    docker push "${RFQI2}"
fi