-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-in-container.sh
executable file
·157 lines (138 loc) · 5.14 KB
/
build-in-container.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
#!/bin/bash
set -x
hopsan_git_url=https://github.com/Hopsan/hopsan.git
dockerfile="$1"
git_ref="$2"
base_version="$3"
do_build=true
do_test=true
do_clean=true
if [[ ! -f ${dockerfile} ]]; then
echo "Error: Arg1 must be an existing dockerfile"
exit 1
fi
if [[ -z "$git_ref" ]]; then
echo "Error: Arg2 must be a git ref (branch, tag or commit hash)"
exit 1
fi
if [[ -z "$base_version" ]]; then
echo "Error: Arg3 must be the release version number for Hopsan"
exit 1
fi
name=$(echo ${dockerfile} | cut -d. -f1 | cut -d- -f2)
tag=$(echo ${dockerfile} | cut -d. -f1 | cut -d- -f3)
image_name=hopsan-build-${name}${tag}
sudo docker build --file ${dockerfile} --tag ${image_name}:latest .
sudo docker images
host_deps_cache=$(pwd -P)/hopsan-dependencies-cache
host_code_dir=$(pwd -P)/${image_name}-code
host_build_dir=$(pwd -P)/${image_name}-build
host_install_dir=$(pwd -P)/${image_name}-install
host_package_output_dir=$(pwd -P)/hopsan-packages
mkdir -p "${host_deps_cache}"
mkdir -p "${host_code_dir}"
mkdir -p "${host_build_dir}"
mkdir -p "${host_install_dir}"
mkdir -p "${host_package_output_dir}"
echo
echo ==============================
echo Downloading source code
echo ==============================
echo
pushd "${host_code_dir}"
if [[ ! -d ".git" ]]; then
git clone ${hopsan_git_url} .
git submodule update --init
fi
git fetch --all --prune
git config advice.detachedHead false
git checkout ${git_ref}
if git tag --list v* | grep ${git_ref}; then
git reset --hard ${git_ref}
else
git reset --hard origin/${git_ref}
fi
if [[ "${do_clean}" == "true" ]]; then
git clean -ffdx
fi
pushd dependencies
# Switch to python3 in case of older version being checked out
sed 's|#!/usr/bin/env python$|#!/usr/bin/env python3|' -i download-dependencies.py
# Figure out if cache option is available in the version being built
if ./download-dependencies.py --help | grep cache; then
./download-dependencies.py --cache "${host_deps_cache}" --all
else
# if not, ugly copy any/all files from the cache (may have been manually placed there)
cp -v "${host_deps_cache}"/* .
./download-dependencies.py --all
fi
popd
release_revision=$(./getGitInfo.sh date.time .)
full_version_name=${base_version}.${release_revision}
echo Release revision number: $release_revision
echo Release version name: $full_version_name
sleep 2
popd
echo
echo ==============================
echo Building inside container
echo ==============================
echo
if [[ "${do_build}" == "true" ]]; then
if [[ "${do_clean}" == "true" ]]; then
rm -rf ${host_build_dir}
rm -rf ${host_install_dir}
fi
mkdir -p ${host_build_dir}
mkdir -p ${host_install_dir}
sudo docker run --user $(id -u):$(id -g) \
--mount type=bind,src=${host_deps_cache},dst=/hopsan/deps \
--mount type=bind,src=${host_code_dir},dst=/hopsan/code \
--mount type=bind,src=${host_build_dir},dst=/hopsan/build \
--mount type=bind,src=${host_install_dir},dst=/hopsan/install \
--tty --name ${image_name}-builder --rm ${image_name} bash -c \
"set -e; \
pushd /hopsan/code; \
./packaging/fixPythonShebang.sh ./ 3
pushd /hopsan/code/dependencies; \
./setupAll.sh; \
popd; \
./packaging/prepareSourceCode.sh /hopsan/code /hopsan/code \
${base_version} ${release_revision} ${full_version_name} \
true false; \
popd; \
pushd /hopsan/build; \
source /hopsan/code/dependencies/setHopsanBuildPaths.sh; \
echo HOPSAN_BUILD_QT_QMAKE \${HOPSAN_BUILD_QT_QMAKE}; \
\${HOPSAN_BUILD_QT_QMAKE} /hopsan/code/HopsanNG.pro -r -spec linux-g++ -config release; \
make -j8; \
popd; \
pushd /hopsan/code; \
packaging/copyInstallHopsan.sh ./ /hopsan/install; \
if [[ \"$do_test\" == \"true\" ]]; then \
export QT_QPA_PLATFORM=offscreen; \
# Using TRAVIS_OS_NAME to prevent gui test from running, it does not work inside container for unknown reason
export TRAVIS_OS_NAME=osx; \
./runUnitTests.sh; \
./runValidationTests.sh; \
fi; \
popd; \
echo Build Done"
pushd "${host_package_output_dir}"
package_dir_name=hopsan-${name}${tag}-${full_version_name}
package_file_name=${package_dir_name}.tar.gz
rm -rf "${package_dir_name}"
rm -rf "${package_file_name}"
cp -rv "${host_install_dir}" "${package_dir_name}"
tar -czf "${package_file_name}" --owner=0 --group=0 "${package_dir_name}"
rm -rf "${package_dir_name}"
popd
echo "Done packaging: ${host_package_output_dir}/${package_file_name}"
else
sudo docker run --user $(id -u):$(id -g) \
--mount type=bind,src=${host_deps_cache},dst=/hopsan/deps \
--mount type=bind,src=${host_code_dir},dst=/hopsan/code \
--mount type=bind,src=${host_build_dir},dst=/hopsan/build \
--mount type=bind,src=${host_install_dir},dst=/hopsan/install \
--tty --interactive --name ${image_name}-runner --entrypoint /bin/bash --rm ${image_name}
fi