This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp-build.sh
executable file
·193 lines (176 loc) · 7.34 KB
/
app-build.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# Copyright 2020-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Build the apps
# General purposes vars
CURRENT_UID=$(id -u)
CURRENT_GID=$(id -g)
CURRENT_DIR=$(pwd)
MVN=1
PROJECT_VERSION=0
# Docker related vars
DOCKER_MVN_TAG=3.6.3-openjdk-11-slim
DOCKER_MVN_IMAGE=maven:${DOCKER_MVN_TAG}
# Do not attach stdin if running in an environment without it (e.g., Jenkins)
IT=$(test -t 0 && echo "-it" || echo "-t")
# Trellis-control related vars
TRELLIS_CONTROL_GROUPID=org.onosproject
TRELLIS_CONTROL_ARTIFACTID=segmentrouting-app
TRELLIS_CONTROL_ARTIFACT=${TRELLIS_CONTROL_GROUPID}:${TRELLIS_CONTROL_ARTIFACTID}
TRELLIS_CONTROL_OAR=${TRELLIS_CONTROL_ROOT}/app/target/${TRELLIS_CONTROL_ARTIFACTID}-${TRELLIS_CONTROL_VERSION}.oar
# Trellis-t3 related vars
TRELLIS_T3_GROUPID=org.onosproject
TRELLIS_T3_ARTIFACTID=t3-app
TRELLIS_T3_ARTIFACT=${TRELLIS_T3_GROUPID}:${TRELLIS_T3_ARTIFACTID}
TRELLIS_T3_OAR=${TRELLIS_T3_ROOT}/app/target/${TRELLIS_T3_ARTIFACTID}-${TRELLIS_T3_VERSION}.oar
# UP4 related vars
UP4_GROUPID=org.omecproject
UP4_ARTIFACTID=up4-app
UP4_ARTIFACT=${UP4_GROUPID}:${UP4_ARTIFACTID}
UP4_TARGETS=_prepare_app_build
UP4_OAR=${UP4_ROOT}/app/app/target/${UP4_ARTIFACTID}-${UP4_VERSION}.oar
# Fabric-tna related vars
FABRIC_TNA_GROUPID=org.stratumproject
FABRIC_TNA_ARTIFACTID=fabric-tna
FABRIC_TNA_ARTIFACT=${FABRIC_TNA_GROUPID}:${FABRIC_TNA_ARTIFACTID}
FABRIC_TNA_TARGETS=all
FABRIC_TNA_OAR=${FABRIC_TNA_ROOT}/target/${FABRIC_TNA_ARTIFACTID}-${FABRIC_TNA_VERSION}.oar
set -eu -o pipefail
function extract_version {
# Enter in the project folder
cd "$1" || exit 1
# Verify if the VERSION file exists
if [ -f "VERSION" ]; then
NEW_VERSION=$(head -n1 "VERSION")
# If this is a golang project, use funky v-prefixed versions
if [ -f "Gopkg.toml" ] || [ -f "go.mod" ]; then
PROJECT_VERSION=v${NEW_VERSION}
else
PROJECT_VERSION=${NEW_VERSION}
fi
# If this is a node.js project
elif [ -f "package.json" ]; then
NEW_VERSION=$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
PROJECT_VERSION=${NEW_VERSION}
# If this is a mvn project
elif [ -f "pom.xml" ]; then
NEW_VERSION=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)
PROJECT_VERSION=${NEW_VERSION}
else
echo "ERROR: No versioning file found!"
exit 1
fi
cd ../
}
# Generic function to build an app
function build_app {
# First step is to remove the oar dir
rm -rf "$1"
# Settings are needed by both build processes - contains proxy settings and extra
cp mvn_settings.xml "$2"
# Dependencies are needed only by the mvn copy - contains repo settings
cp dependencies.xml "$2"
# Mounting the current dir allows to cache the .m2 folder that is persisted and leveraged by subsequent builds
docker run "${IT}" --rm -v "${CURRENT_DIR}":/root -w /root/"$3" "${DOCKER_MVN_IMAGE}" \
bash -c "mvn dependency:copy -Dartifact=$4:$5:oar \
-DoutputDirectory=$6 -Dmdep.useBaseVersion=true \
-Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
-s mvn_settings.xml; \
chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
# If the oar is not found - try to build using the source code
if [ ! -f "$7" ]; then
cd "$2" || exit 1
# Verify for the last time if the VERSION is a checkout object or a review
if ! (git checkout "origin/$5" || git checkout "$5"); then
if ! (git fetch "$8" "$5" && git checkout FETCH_HEAD); then
exit 1
fi
fi
cd ../
# Having the same mount file allows to reduce build time
docker run "${IT}" --rm -v "${CURRENT_DIR}":/root -w /root/"$3" "${DOCKER_MVN_IMAGE}" \
bash -c "mvn clean install -s mvn_settings.xml; \
chown -R ${CURRENT_UID}:${CURRENT_GID} /root"
# We need to override the version variable because it is not valid at this point
MVN=0
fi
}
function trellis-control-build {
# Build function
build_app "${TRELLIS_CONTROL_ROOT}"/app/target \
"${TRELLIS_CONTROL_ROOT}"/ "trellis-control" \
"${TRELLIS_CONTROL_ARTIFACT}" "${TRELLIS_CONTROL_VERSION}" \
"app/target" "${TRELLIS_CONTROL_OAR}" "${TRELLIS_CONTROL_REPO}"
# If MVN was not successful - built from sources
if [ "$MVN" -eq "0" ]; then
# When building from source api and app jars are automatically put into the local .m2 folder.
# Update VERSION
extract_version "${TRELLIS_CONTROL_ROOT}"
# Update OAR
TRELLIS_CONTROL_OAR="${TRELLIS_CONTROL_ROOT}"/app/target/"${TRELLIS_CONTROL_ARTIFACTID}"-"${PROJECT_VERSION}".oar
else
# Fetch trellis-control api and app JARs that may be needed to build other apps when using local maven cache (i.e., T3 and fabric-tna).
# Fetched jars will be places in the local .m2 folder.
docker run "${IT}" --rm -v "${CURRENT_DIR}":/root -w /root/"trellis-control" "${DOCKER_MVN_IMAGE}" \
bash -c "mvn dependency:copy -Dartifact=${TRELLIS_CONTROL_GROUPID}:segmentrouting-api:${TRELLIS_CONTROL_VERSION} \
-Dmdep.useBaseVersion=true -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
-s mvn_settings.xml; \
mvn dependency:copy -Dartifact=${TRELLIS_CONTROL_GROUPID}:segmentrouting-app:${TRELLIS_CONTROL_VERSION} \
-Dmdep.useBaseVersion=true -Dmdep.overWriteReleases=true -Dmdep.overWriteSnapshots=true -f dependencies.xml \
-s mvn_settings.xml"
fi
# Final step requires to move the oar to the folder used by Dockerfile. Moreover, it will help catch up errors
cp "${TRELLIS_CONTROL_OAR}" "${LOCAL_APPS}"/
}
function trellis-t3-build {
build_app "${TRELLIS_T3_ROOT}"/app/target \
"${TRELLIS_T3_ROOT}"/ "trellis-t3" \
"${TRELLIS_T3_ARTIFACT}" "${TRELLIS_T3_VERSION}" \
"app/target" "${TRELLIS_T3_OAR}" "${TRELLIS_T3_REPO}"
if [ "$MVN" -eq "0" ]; then
extract_version "${TRELLIS_T3_ROOT}"
TRELLIS_T3_OAR="${TRELLIS_T3_ROOT}"/app/target/"${TRELLIS_T3_ARTIFACTID}"-"${PROJECT_VERSION}".oar
fi
cp "${TRELLIS_T3_OAR}" "${LOCAL_APPS}"/
}
function up4-build {
# Prepares app folder
cd "${UP4_ROOT}" || exit 1 && make "${UP4_TARGETS}"
cd ../
build_app "${UP4_ROOT}"/app/app/target \
"${UP4_ROOT}"/app "up4/app" \
"${UP4_ARTIFACT}" "${UP4_VERSION}" \
"app/app/target" "${UP4_OAR}" "${UP4_REPO}"
if [ "$MVN" -eq "0" ]; then
extract_version "${UP4_ROOT}"/app
cd ../
UP4_OAR="${UP4_ROOT}"/app/app/target/"${UP4_ARTIFACTID}"-"${PROJECT_VERSION}".oar
fi
cp "${UP4_OAR}" "${LOCAL_APPS}"/
}
function fabric-tna-build {
# This workaround is temporary - typically we need to build only the pipeconf
cd "${FABRIC_TNA_ROOT}" || exit 1 && make "${FABRIC_TNA_TARGETS[@]}" SHOW_SENSITIVE_OUTPUT="${SHOW_SENSITIVE_OUTPUT:-false}"
cd ../
build_app "${FABRIC_TNA_ROOT}"/target \
"${FABRIC_TNA_ROOT}"/ "fabric-tna" \
"${FABRIC_TNA_ARTIFACT}" "${FABRIC_TNA_VERSION}" \
"target" "${FABRIC_TNA_OAR}" "${FABRIC_TNA_REPO}"
if [ "$MVN" -eq "0" ]; then
extract_version "${FABRIC_TNA_ROOT}"
FABRIC_TNA_OAR="${FABRIC_TNA_ROOT}"/target/"${FABRIC_TNA_ARTIFACTID}"-"${PROJECT_VERSION}".oar
fi
cp "${FABRIC_TNA_OAR}" "${LOCAL_APPS}"/
}
"$1"