-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.sh
executable file
·258 lines (232 loc) · 7.48 KB
/
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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
usage() {
echo "Usage: $0 [--push TAG] [--target TARGET] [--version VERSION] [--userbin USERBIN] [--parallel] [--rebuildbuilder]" 1>&2
}
PARALLEL=""
REBUILD_BUILDER="false"
TAG=""
TARGET="local"
VERSION="1.0"
USERBIN="all"
while [[ "$#" -gt 0 ]]; do
case "$1" in
--parallel)
shift
PARALLEL="--parallel"
;;
--rebuildbuilder)
shift
REBUILD_BUILDER="true"
;;
--push)
shift
TAG="$1"
shift
;;
--target)
shift
TARGET="$1"
shift
;;
--version)
shift
VERSION="$1"
shift
;;
--userbin)
shift
USERBIN="$1"
shift
;;
-help)
usage
exit 0
;;
*)
echo "unexpected argument $1"
usage
exit 1
esac
done
if [ $# -gt 0 ]; then
usage
exit 1
fi
if [[ "$TAG" != "" && "$TARGET" == "local" ]] || [[ "$TAG" == "" && "$TARGET" != "local" ]] ; then
echo "Must run with either --push set and --target=remote, or --target=local and without --push"
exit 1
fi
TMP=/tmp/sigmaos
BUILD_LOG=/tmp/sigmaos-build
PROCD_BIN=/tmp/sigmaos-procd-bin
# tests uses hosts /tmp, which mounted in kernel container.
mkdir -p $TMP
mkdir -p $BUILD_LOG
# Make a dir to hold user proc build output
ROOT=$(pwd)
BIN=${ROOT}/bin
KERNELBIN=${BIN}/kernel
USRBIN=${BIN}/user
mkdir -p $USRBIN
# Clear the procd bin directory
rm -rf $PROCD_BIN
mkdir -p $PROCD_BIN
# build and start db container
if [ "${TARGET}" != "remote" ]; then
./start-network.sh
fi
# Check if a builder is running already
buildercid=$(docker ps -a | grep -w "sig-builder" | cut -d " " -f1)
rsbuildercid=$(docker ps -a | grep -w "sig-rs-builder" | cut -d " " -f1)
# Optionally stop any existing builder container, so it will be rebuilt and
# restarted.
if [[ $REBUILD_BUILDER == "true" ]]; then
if ! [ -z "$buildercid" ]; then
echo "========== Stopping old builder container $buildercid =========="
docker stop $buildercid
# Reset builder container ID
buildercid=""
fi
if ! [ -z "$rsbuildercid" ]; then
echo "========== Stopping old Rust builder container $rsbuildercid =========="
docker stop $rsbuildercid
# Reset builder container ID
rsbuildercid=""
fi
fi
if [ -z "$buildercid" ]; then
# Build builder
echo "========== Build builder image =========="
DOCKER_BUILDKIT=1 docker build --progress=plain -f builder.Dockerfile -t sig-builder . 2>&1 | tee $BUILD_LOG/sig-builder.out
echo "========== Done building builder =========="
# Start builder
echo "========== Starting builder container =========="
docker run --rm -d -it \
--name sig-builder \
--mount type=bind,src=$ROOT,dst=/home/sigmaos/ \
sig-builder
buildercid=$(docker ps -a | grep -w "sig-builder" | cut -d " " -f1)
until [ "`docker inspect -f {{.State.Running}} $buildercid`"=="true" ]; do
echo -n "." 1>&2
sleep 0.1;
done
echo "========== Done starting builder ========== "
fi
if [ -z "$rsbuildercid" ]; then
# Build builder
echo "========== Build Rust builder image =========="
DOCKER_BUILDKIT=1 docker build --progress=plain -f rs-builder.Dockerfile -t sig-rs-builder . 2>&1 | tee $BUILD_LOG/sig-rs-builder.out
echo "========== Done building Rust builder =========="
# Start builder
echo "========== Starting Rust builder container =========="
docker run --rm -d -it \
--name sig-rs-builder \
--mount type=bind,src=$ROOT,dst=/home/sigmaos/ \
sig-rs-builder
rsbuildercid=$(docker ps -a | grep -w "sig-rs-builder" | cut -d " " -f1)
until [ "`docker inspect -f {{.State.Running}} $rsbuildercid`"=="true" ]; do
echo -n "." 1>&2
sleep 0.1;
done
echo "========== Done starting Rust builder ========== "
fi
BUILD_ARGS="--norace \
--gopath /go-custom/bin/go \
--target $TARGET \
$PARALLEL"
echo "========== Building kernel bins =========="
BUILD_OUT_FILE=$BUILD_LOG/make-kernel.out
docker exec -it $buildercid \
/usr/bin/time -f "Build time: %e sec" \
./make.sh $BUILD_ARGS kernel \
2>&1 | tee $BUILD_OUT_FILE && \
if [ ${PIPESTATUS[0]} -ne 0 ]; then
printf "\n!!!!!!!!!! BUILD ERROR !!!!!!!!!!\nLogs in: $BUILD_OUT_FILE\n" \
| tee -a $BUILD_OUT_FILE;
fi;
if [ $(grep -q "BUILD ERROR" $BUILD_OUT_FILE; echo $?) -eq 0 ]; then
echo "!!!!!!!!!! ABORTING BUILD !!!!!!!!!!"
exit 1
fi
# Copy named, which is also a user bin
cp $KERNELBIN/named $USRBIN/named
echo "========== Done building kernel bins =========="
echo "========== Building user bins =========="
BUILD_OUT_FILE=$BUILD_LOG/make-user.out
docker exec -it $buildercid \
/usr/bin/time -f "Build time: %e sec" \
./make.sh $BUILD_ARGS --userbin $USERBIN user --version $VERSION \
2>&1 | tee $BUILD_OUT_FILE && \
if [ ${PIPESTATUS[0]} -ne 0 ]; then
printf "\n!!!!!!!!!! BUILD ERROR !!!!!!!!!!\nLogs in: $BUILD_OUT_FILE\n" \
| tee -a $BUILD_OUT_FILE;
fi;
if [ $(grep -q "BUILD ERROR" $BUILD_OUT_FILE; echo $?) -eq 0 ]; then
echo "!!!!!!!!!! ABORTING BUILD !!!!!!!!!!"
exit 1
fi
echo "========== Done building user bins =========="
RS_BUILD_ARGS="--rustpath \$HOME/.cargo/bin/cargo \
$PARALLEL"
echo "========== Building Rust bins =========="
BUILD_OUT_FILE=$BUILD_LOG/make-user-rs.out
docker exec -it $rsbuildercid \
/usr/bin/time -f "Build time: %e sec" \
./make-rs.sh $RS_BUILD_ARGS --version $VERSION \
2>&1 | tee $BUILD_OUT_FILE && \
if [ ${PIPESTATUS[0]} -ne 0 ]; then
printf "\n!!!!!!!!!! BUILD ERROR !!!!!!!!!!\nLogs in: $BUILD_OUT_FILE\n" \
| tee -a $BUILD_OUT_FILE;
fi;
if [ $(grep -q "BUILD ERROR" $BUILD_OUT_FILE; echo $?) -eq 0 ]; then
echo "!!!!!!!!!! ABORTING BUILD !!!!!!!!!!"
exit 1
fi
echo "========== Done building Rust bins =========="
echo "========== Copying kernel bins for procd =========="
if [ "${TARGET}" == "local" ]; then
sudo cp $ROOT/create-net.sh $KERNELBIN/
cp $KERNELBIN/procd $PROCD_BIN/
cp $KERNELBIN/spproxyd $PROCD_BIN/
cp $KERNELBIN/uproc-trampoline $PROCD_BIN/
fi
echo "========== Done copying kernel bins for uproc =========="
# Now, prepare to build final containers which will actually run.
targets="sigmauser-remote sigmaos-remote"
if [ "${TARGET}" == "local" ]; then
targets="sigmauser-local sigmaos-local"
fi
njobs=1
if ! [ -z "$PARALLEL" ]; then
# Optionally build the docker images in parallel.
njobs=$(echo $targets | wc -w)
fi
build_targets="parallel -j$njobs \"DOCKER_BUILDKIT=1 docker build --progress=plain -f target.Dockerfile --target {} -t {} . 2>&1 | tee $BUILD_LOG/{}.out\" ::: $targets"
printf "\nBuilding Docker image targets\n$build_targets\n\n"
echo "========== Start Docker targets build =========="
eval $build_targets
echo "========== Done building Docker targets =========="
if [ "${TARGET}" == "local" ]; then
# If developing locally, rename the sigmaos image which includes binaries to
# be the default sigmaos image.
docker tag sigmaos-local sigmaos
docker tag sigmauser-local sigmauser
else
docker tag sigmaos-remote sigmaos
docker tag sigmauser-remote sigmauser
# Upload the user bins to S3
echo "========== Pushing user bins to S3 =========="
./upload.sh --tag $TAG --profile sigmaos
echo "========== Done pushing user bins to S3 =========="
fi
# Build npproxy for host
echo "========== Building proxy =========="
/usr/bin/time -f "Build time: %e sec" ./make.sh --norace $PARALLEL npproxy
echo "========== Done building proxy =========="
if ! [ -z "$TAG" ]; then
echo "========== Pushing container images to DockerHub =========="
docker tag sigmaos arielszekely/sigmaos:$TAG
docker push arielszekely/sigmaos:$TAG
docker tag sigmauser arielszekely/sigmauser:$TAG
docker push arielszekely/sigmauser:$TAG
fi