This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpackpack
executable file
·240 lines (217 loc) · 7.74 KB
/
packpack
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/sh
# PackPack version
PACKVERSION=1.0.0
# Source directory
SOURCEDIR=${SOURCEDIR:-$PWD}
# Build directory
BUILDDIR=${BUILDDIR:-${SOURCEDIR}/build}
# Docker repository to use
DOCKER_REPO=${DOCKER_REPO:-packpack/packpack}
# Extra parameters for docker run.
PACKPACK_EXTRA_DOCKER_RUN_PARAMS="${PACKPACK_EXTRA_DOCKER_RUN_PARAMS:-}"
# CMake top-level CMakeLists.txt directory
SRC_TOP_LEVEL_DIR="${SRC_TOP_LEVEL_DIR:-/source/halcs}"
BUILD_TOP_LEVEL_DIR="${BUILD_TOP_LEVEL_DIR:-/build/halcs}"
# Set CI variable to CI provider name
CI=""
if [ "${APPVEYOR:-}" = "True" -o "${APPVEYOR:-}" = "true" ]; then
# https://www.appveyor.com/docs/environment-variables/
CI="appveyor"
elif [ "${CIRCLECI:-}" = "true" ]; then
# https://circleci.com/docs/2.0/env-vars/
CI="circle"
elif [ "${GITHUB_ACTIONS:-}" = "true" ]; then
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
CI="github"
elif [ "${GITLAB_CI:-}" = "true" ]; then
# https://docs.gitlab.com/ee/ci/variables/
CI="gitlab"
elif [ "${TRAVIS:-}" = "true" ]; then
# https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
CI="travis"
fi
# Docker architecture
if [ -z "${ARCH}" ]; then
# Use uname -m instead of HOSTTYPE
case "$(uname -m)" in
i*86) ARCH="i386" ;;
arm*) ARCH="armhf" ;;
x86_64) ARCH="x86_64"; ;;
aarch64) ARCH="aarch64" ;;
*) ARCH="${HOSTTYPE}" ;;
esac
fi
# Docker image to use
if [ -z "${DOCKER_IMAGE}" ]; then
if [ -n "${OS}" ] && [ -n "${DIST}" ]; then
# Non-numeric dist, e.g. debian-sid, ubuntu-precise, etc.
DOCKER_IMAGE="${OS}-${DIST}"
else
# Use ubuntu-xenial docker image if OS or DIST is invalid
DOCKER_IMAGE=ubuntu-bionic
fi
if [ "${ARCH}" != "x86_64" ]; then
DOCKER_IMAGE="${DOCKER_IMAGE}-${ARCH}"
fi
fi
version() {
echo "PackPack version ${PACKVERSION}"
}
usage() {
echo "# PackPack version ${PACKVERSION}"
echo ""
echo "Usage: OS=ubuntu DIST=xenial $0 [CPack Generators] [CMake options]"
echo ""
echo "## Environment Variables"
echo ""
echo " * PRODUCT - the name of software product, e.g. 'tarantool'"
echo " * ARCH - architecture, e.g i386, x86_64, armhf (${ARCH})"
echo " * OS - the name of distribution, e.g. debian or fedora (${OS})"
echo " * DIST - the version of distribution, e.g. xenial or 24 (${DIST})"
echo " * BUILDDIR - directory used for out-of-source build (${BUILDDIR})"
echo " * DOCKER_REPO - Docker repository to use (${DOCKER_REPO})"
echo " * MORE_LD_LIBRARY_PATH - Additional paths to append to Docker LD_LIBRARY_PATH"
echo ""
echo "The actual list of distribution is available on Docker Hub:"
echo ""
echo " https://hub.docker.com/r/${DOCKER_REPO}/tags/"
echo ""
echo "## Documentation"
echo ""
echo " * See https://github.com/packpack/packpack"
echo ""
}
case "$1" in
-V|--version)
version
exit 0
;;
-h|--help)
usage
exit 1
;;
*) ;;
esac
#
# Create an entry point for Docker to allow builds from non-root user
#
mkdir -p ${BUILDDIR}
if [ "${OS}" = "alpine" ]; then
(
echo "#!/bin/sh";
echo "set -x";
echo "adduser -u $(id -u) -D $USER";
echo "adduser $USER adm";
echo "adduser $USER wheel";
echo "adduser $USER abuild";
echo "export HOME=/home/$USER" ;
echo "export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}\${MORE_LD_LIBRARY_PATH:+:\$MORE_LD_LIBRARY_PATH}" ;
echo "abuild-keygen -a -i -n";
echo "su-exec $USER \"\$@\"";
) > ${BUILDDIR}/userwrapper.sh
else
(
echo "#!/bin/sh";
echo "set -x";
echo "useradd -u $(id -u) $USER";
echo "usermod -a -G sudo $USER 2>/dev/null || :";
echo "usermod -a -G wheel $USER 2>/dev/null || :";
echo "usermod -a -G adm $USER 2>/dev/null || :";
echo "export HOME=/home/$USER" ;
echo "export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}\${MORE_LD_LIBRARY_PATH:+:\$MORE_LD_LIBRARY_PATH}" ;
echo "exec chroot --userspec=$USER / \"\$@\"";
) > ${BUILDDIR}/userwrapper.sh
fi
chmod a+x ${BUILDDIR}/userwrapper.sh
#
# Docker command
#
(
echo "#!/bin/sh";
echo "set -x";
echo "SRC_TOP_LEVEL_DIR=\"\$1\"";
echo "shift 1";
echo "BUILD_TOP_LEVEL_DIR=\"\$1\"";
echo "shift 1";
echo "CMAKE_OPTS=\"\$@\"";
echo "cd \${BUILD_TOP_LEVEL_DIR}";
echo "if [ -f \"/etc/debian_version\" ]; then";
echo " case \"\$(cat /etc/debian_version)\" in";
echo " *stretch* | 9.* )";
echo " sudo apt purge -y --auto-remove cmake";
echo " sudo apt install -y libssl-dev";
echo " version=3.17";
echo " build=3";
echo " mkdir -p ~/cmake-src";
echo " cd ~/cmake-src";
echo " wget https://cmake.org/files/v\$version/cmake-\$version.\$build.tar.gz";
echo " tar -xzvf cmake-\$version.\$build.tar.gz";
echo " cd cmake-\$version.\$build/";
echo " ./bootstrap";
echo " make -j\$(nproc) > /dev/null";
echo " sudo make install";
echo " cmake --version";
echo " cd \${BUILD_TOP_LEVEL_DIR}";
echo " ;;"
echo " esac";
echo "fi";
echo "sudo apt-get -y update && \\";
echo " sudo apt-get -y install pkg-config systemd uuid-dev libsodium-dev libzmq3-dev libczmq-dev";
echo "if [ \"\$?\" -ne 0 ]; then"
echo " sudo yum install -y epel-release centos-release-scl centos-release-scl-rh && \\";
echo " sudo yum-config-manager --add-repo http://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-draft/CentOS_7/network:messaging:zeromq:release-draft.repo && \\";
echo " sudo yum install -y pkgconfig uuid-devel libsodium-devel zeromq-devel czmq-devel && \\";
echo " sudo sed -i -e '/Cflags:/ s/-I\${libdir}\/pgm-5.2\/include//' /usr/lib64/pkgconfig/openpgm-5.2.pc";
echo "fi";
echo "if [ \"\$?\" -ne 0 ]; then";
echo " exit 1";
echo "fi";
echo "cmake3 \${CMAKE_OPTS} \${SRC_TOP_LEVEL_DIR}";
echo "if [ \"\$?\" -ne 0 ]; then";
echo " cmake \${CMAKE_OPTS} \${SRC_TOP_LEVEL_DIR}";
echo "fi";
echo "if [ \"\$?\" -ne 0 ]; then";
echo " exit 1";
echo "fi";
echo "make package";
) > ${BUILDDIR}/usercmd.sh
chmod a+x ${BUILDDIR}/usercmd.sh
#
# Save defined configuration variables to ./env file
#
env | grep -E "^PRODUCT=|^VERSION=|^RELEASE=|^ABBREV=|^TARBALL_|^CHANGELOG_|^CCACHE_|^PACKAGECLOUD_|^SMPFLAGS=|^OS=|^DIST=|^VAR_|^MORE_LD_LIBRARY_PATH=" \
> ${BUILDDIR}/env
#
# Setup cache directory
#
CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/packpack"
mkdir -p "${CACHE_DIR}/ccache"
#
# Fix security context for selinux
#
chcon -Rt svirt_sandbox_file_t ${SOURCEDIR} ${BUILDDIR} \
1> /dev/null 2> /dev/null || :
#
# Start Docker
#
set -ex
docker pull ${DOCKER_REPO}:${DOCKER_IMAGE}
docker run \
${PACKPACK_EXTRA_DOCKER_RUN_PARAMS} \
--volume "${SOURCEDIR}:${SRC_TOP_LEVEL_DIR}:ro" \
--volume "${BUILDDIR}:${BUILD_TOP_LEVEL_DIR}" \
--env-file ${BUILDDIR}/env \
--workdir ${BUILD_TOP_LEVEL_DIR} \
--rm=true --tty=true \
--entrypoint=${BUILD_TOP_LEVEL_DIR}/userwrapper.sh \
-e XDG_CACHE_HOME=/cache \
-e CCACHE_DIR=/cache/ccache \
-e TMPDIR=/tmp \
-e CI=${CI} \
--volume "${CACHE_DIR}:/cache" \
${DOCKER_REPO}:${DOCKER_IMAGE} \
${BUILD_TOP_LEVEL_DIR}/usercmd.sh "${SRC_TOP_LEVEL_DIR}" "${BUILD_TOP_LEVEL_DIR}" "$@"
retcode=$?
rm -f ${BUILDDIR}/userwrapper.sh ${BUILDDIR}/usercmd.sh ${BUILDDIR}/env
exit $retcode
# vim: filetype=sh tabstop=4 shiftwidth=4 softtabstop=4 expandtab